Pages:
Author

Topic: [DONE] Patch bitcoin v0.5.1rc2 to send a HTTP POST when a new block is accepted - page 2. (Read 4244 times)

legendary
Activity: 1386
Merit: 1097
AND == && in php lol

You probably missed that I fixed the '=' mistake. I replaced 'and' for '&&' just because it's my personal favourite.
full member
Activity: 209
Merit: 100
Very nice Smiley

Not sure how to decode the scriptsig, but I dont use sender for now anyway.

The scriptSigs seem to be split up into 2 parts by a space
I'm not 100% sure but i think the first part is the actual sig and the 2nd part is the senders pubkey

anyway this should be done soon im just adding the block posting part now for my needs and adding in the code to make this usable by the
config file im gna make it like this
monitortx(true|false)
monitortxurl=http://example.com/foo.php
monitorblock(true|false)
monitorblockurl=http://example.com/foo.php

How are you going to handle when some blocks are rejected later, ie. a rollback of 2 blocks that didnt make it into the main chain after all ?

From what I understand the reading of block file is only a small part of what Abe does to make sure the database is maintained to keep track of the main chain.

I didn't really think about it but i think it could be done fairly easily
I'm going to add the code to post in the SetBestChain void in main.cpp
once the blocks get posted to the server just do checks on the blockchain structure and if it does need to get some different blocks send rpc commands to get them...

I'm not exactly sure how that would work out though =P I would need to do some testing
full member
Activity: 127
Merit: 100
Very nice Smiley

Not sure how to decode the scriptsig, but I dont use sender for now anyway.

The scriptSigs seem to be split up into 2 parts by a space
I'm not 100% sure but i think the first part is the actual sig and the 2nd part is the senders pubkey

anyway this should be done soon im just adding the block posting part now for my needs and adding in the code to make this usable by the
config file im gna make it like this
monitortx(true|false)
monitortxurl=http://example.com/foo.php
monitorblock(true|false)
monitorblockurl=http://example.com/foo.php

How are you going to handle when some blocks are rejected later, ie. a rollback of 2 blocks that didnt make it into the main chain after all ?

From what I understand the reading of block file is only a small part of what Abe does to make sure the database is maintained to keep track of the main chain.
full member
Activity: 209
Merit: 100
Code:
            $_SERVER['REQUEST_METHOD'] = 'POST' AND 
            !empty(
$_SERVER['CONTENT_TYPE']) AND
            
$_SERVER['CONTENT_TYPE'] = 'application/json'
?>

This is, of course, wrong. Corrected condition:

Code:
            $_SERVER['REQUEST_METHOD'] == 'POST' &&  isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json'

AND == && in php lol

its even the first example on the logical operators page in the php manual

http://www.php.net/manual/en/language.operators.logical.php
legendary
Activity: 1386
Merit: 1097
Code:
            $_SERVER['REQUEST_METHOD'] = 'POST' AND 
            !empty(
$_SERVER['CONTENT_TYPE']) AND
            
$_SERVER['CONTENT_TYPE'] = 'application/json'
?>

This is, of course, wrong. Corrected condition:

Code:
            $_SERVER['REQUEST_METHOD'] == 'POST' &&  isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json'
full member
Activity: 209
Merit: 100
Very nice Smiley

Not sure how to decode the scriptsig, but I dont use sender for now anyway.

The scriptSigs seem to be split up into 2 parts by a space
I'm not 100% sure but i think the first part is the actual sig and the 2nd part is the senders pubkey

anyway this should be done soon im just adding the block posting part now for my needs and adding in the code to make this usable by the
config file im gna make it like this
monitortx(true|false)
monitortxurl=http://example.com/foo.php
monitorblock(true|false)
monitorblockurl=http://example.com/foo.php
full member
Activity: 127
Merit: 100
Very nice Smiley

Not sure how to decode the scriptsig, but I dont use sender for now anyway.



full member
Activity: 209
Merit: 100
sorry it took so long i had some bugs to work out....

How does this look?
Code:
{
"method":"monitortx",
"params":[
{
"hash":"e0065cfb99b2479cbd7479fbe7c70864b5de5ba67c8f3bf58eb460ea2ef094b3",
"ver":1,
"vin_sz":4,
"vout_sz":2,
"lock_time":0,
"in":[
{
"prev_out":"12e1a620f7e90c3f877c8f6369aaf71100ab15be17de0d3c2802c26790f5a3c9",
"n":1,
"scriptSig":"30450221009572ef611ba5940e3842bcbf255a4b1e79c32c39549cc412655c39f0ad727413022022c07128a0cf3b111ce7faf7a7283fa48dd8563adaadd26a477d7e41e09dfbaf01 047fac59c7a28fd6069a00307ab853d0915cb6fec4df84df422b79e0ad3049be0e87cfaf9ca823a06ebee5fb04bc267b3bd0f782579a501397a35d49ada02075dc"
},
{
"prev_out":"d037bfa871865f5020e3a9edb0ad8e3bfeee25bbc6115476c3fb1cd105361c8f",
"n":0,
"scriptSig":"30460221008945b51f2616e4197f60bdec7c2b79cf9cb597faa631accf4b0d00081c525e26022100820c3e1cd2c9d0aec02fccc73dd22baef1a5746b78d3bc4c8df92f21abcf606601 047f094b909687bb621d9ecb02a3f5f7938a0dc71917beec1d21055a69094f030bf210d059b2ad6f872d717826e9dee0348aef7716c8c93911e911a067103c0b69"
},
{
"prev_out":"c8356c7f33245c77a31f75c4534b31993a5d4f47985208d7bf4e708b6e6cb9ad",
"n":0,
"scriptSig":"304502202c30da244b961e570d964cb9d6998e17b0a0349131d8cf0cfa36d214534ecf0b022100b65775ff34b27ed5b0688f5dd4f2b2a1d0c623dd0340891f7845b72757e8ed4701 04ce18444917f2dd3c8f5a4f262556ab9dd04ad482799ee8e92c92735c66957bd42a9e55f894a408ca3ce42d96f6efa221f81e914b49422ff8cfc1b8a950fc91f0"
},
{
"prev_out":"8302ab4b9b5fb426bc8a41e343d2006bafbab95883622cd954e068f2787a3e97",
"n":0,
"scriptSig":"3046022100e2b880f9cfbfeecbd8bb76629ecbff654ed915f8ff8557937f376cffedd8b98f022100ef63e5cd8af0531e2e53d4be8ee73690eb4537ac19663ed054c1c05235eaa12701 04c78a58082241cb3c8c09ef57f9104fc4c28d4ff13252f8bbce0c0eedbbafd92b66639bd48c850016b2442db22474e333cdf2ae3ef6f237eb4be22e582fcf0563"
}
],

"out":[
{
"value":505.96647463,
"scriptPubKey":"OP_DUP OP_HASH160 609c3e000d66225caf5ad27245978d33ed761ee6 OP_EQUALVERIFY OP_CHECKSIG"
},
{
"value":173.16000000,
"scriptPubKey":"OP_DUP OP_HASH160 c56d7f3e011ce6f40d7399667fb2bc116e643b38 OP_EQUALVERIFY OP_CHECKSIG"
}
]

],
"id":null
}

I just used a simple php script to catch the data

Code:

      
if (
            
$_SERVER['REQUEST_METHOD'] = 'POST' AND 
            !empty(
$_SERVER['CONTENT_TYPE']) AND
            
$_SERVER['CONTENT_TYPE'] = 'application/json'
            
) {
$stringData file_get_contents('php://input');
$myFile "test.txt";
$fh fopen($myFile'w') or die("can't open file");
          
fwrite($fh$stringData);
fclose($fh);
        }
                

?>
full member
Activity: 209
Merit: 100
I've had a little bit of time to work on this today.
I made a new thread just to handle posts like Gavins blockmonitor does.
When a new transaction is received and gets accepted to the memory pool it will put a new post in the query to be sent out.
Very nice, that is exactly what I wanted, a post per tx, and since its localhost it should be fast enough to keep.

You can use it like getmemorypool("transactions") and it will dump out all unconfirmed transactions
Also useable, but then you would need to poll it every so often and check if theres new transactions.

Did you get a POST system working in your test?
If so could you show what data the post script would receive ?

Havn't tested it yet... I should be ready to test in about 15 mins I'll let you now what happens
full member
Activity: 127
Merit: 100
I've had a little bit of time to work on this today.
I made a new thread just to handle posts like Gavins blockmonitor does.
When a new transaction is received and gets accepted to the memory pool it will put a new post in the query to be sent out.
Very nice, that is exactly what I wanted, a post per tx, and since its localhost it should be fast enough to keep.

You can use it like getmemorypool("transactions") and it will dump out all unconfirmed transactions
Also useable, but then you would need to poll it every so often and check if theres new transactions.

Did you get a POST system working in your test?
If so could you show what data the post script would receive ?
full member
Activity: 209
Merit: 100
I've had a little bit of time to work on this today.
I made a new thread just to handle posts like Gavins blockmonitor does.
When a new transaction is received and gets accepted to the memory pool it will put a new post in the query to be sent out.

Is this what you wanted? or do you want a whole dump of the transactions in the memory pool?
I just ran across some code in the new source it's a new RPC command: getmemorypool

You can use it like getmemorypool("transactions") and it will dump out all unconfirmed transactions

anyway lemme know what you think
full member
Activity: 209
Merit: 100
if your already getting the blocks why not just pull the transaction data from the blocks?

edit: err nevermind just thought about what i said lol if its in a block then it has atleast 1 confirm

full member
Activity: 127
Merit: 100
For now I am using Abe for the regular block monitoring, but yes that could be useful also, just need to check for orfans etc.

I didnt see any bids on my project, so I adjusted it and reposted, but maybe bitcoin is too unknown for someone to risk their rating on vworker to take on such a project.

I could post as pay-for-time, but then I risk paying for a few hours work with no solution.
Wish I was better as C myself, I have only done some non-object based micro processor code.
full member
Activity: 209
Merit: 100
im actually working on something like this for myself just haven't had the time to work on it hopefully today i will have the time to get and compile all the dependencies and start coding... i have another project i need to finish up first though

check this patch out:
https://bitcointalksearch.org/topic/m.15065

monitorblocks [monitor=true] [startblockcount=0]
POST block information to as blocks are added to the block chain.
[monitor] true will start monitoring, false will stop.
Pass [startblockcount] to start monitoring at/after block with given blockcount.

full member
Activity: 127
Merit: 100
Add to bitcoin.conf (with pull 727 and 743):
Code:
blocknotify=curl -d "$(bitcoind getblock %s)" http://youruri

1843ETPAWNriBA2mtDCBMQasaDHnWETP82 if this does what you need
I think thats for an actual block, I see I used "block" in the description, but as the other thread and quote shows, its the new transactions that are interesting.

ie. when bitcoind gets a new tx, which will then be unconfirmed, it calls a http post/system with the details.

I guess the reason I need both pulls was the getBlock rpc ?
I will look into 743 anyway, the code to call system() could probaly be reused.




[EDIT] I have now posted this to vworker.com, so if you are interested, please bid using vworker.
I will update this thread when the project is done.
legendary
Activity: 2576
Merit: 1186
Add to bitcoin.conf (with pull 727 and 743):
Code:
blocknotify=curl -d "$(bitcoind getblock %s)" http://youruri

1843ETPAWNriBA2mtDCBMQasaDHnWETP82 if this does what you need
hero member
Activity: 755
Merit: 515
full member
Activity: 127
Merit: 100
Src : https://github.com/bitcoin/bitcoin/commits/v0.5.1rc2

For original thread where the idea was mentioned : https://bitcointalksearch.org/topic/m.676281

The idea is to add a HTTP POST call to a local webserver, after bitcoind has accepted a new transaction into memory.

I will not put too much requirements on the contents of the call, its easyier to convert in PHP that C++ anyway.
But I need at least inputs and outputs with amounts.
The HTTP url can be hardcoded in the patch.
Patch license should be same as bitcoin or public domain.

[EDIT] What I am looking for is a call with http/system, when bitcoind gets a new transaction, ie. unconfirmed, I am not interested in the actual blocks, since I already have a setup to handle that.

Here's my suggestion for the easiest way to get unconfirmed transactions out of bitcoind

At the end of the AcceptToMemoryPool() function in main.ccp use WalletTxToJSON() in bitcoinrpc.cpp to make a json string and the HTTPPost method in to post it to your callback url which you can process.

I have posted this to vworker.com also, feel free to post a bid there.
If you are interested before bids are posted on vworker, you can also bid here.
Pages:
Jump to: