Pages:
Author

Topic: How to use Walletnotify? - page 2. (Read 19054 times)

jlp
sr. member
Activity: 266
Merit: 264
January 31, 2014, 03:55:42 PM
#21

How do I use argc/argv?

See above.  Basically, argc is the number of arguments on the command line, including the name of the script.  argv is an array of the command line elements, starting with argv[0] set to the name of the script.


I got it to work with argc and argv.  I put the following into bitcoin.conf:

walletnotify=/usr/bin/php /path/to/walletnotify.php %s

I have the following in walletnotify.php:

Code:
if(2==$argc){
require_once 'jsonRPCClient.php';
$bitcoin = new jsonRPCClient('http://username:[email protected]:8332/');

$walletinfo $bitcoin->getinfo();
$trxinfo $bitcoin->gettransaction($argv[1]);

// Append data to the file
$new "\n\nTransaction hash: ".$argv[1]."\nGetinfo balance: ".$walletinfo["balance"]
."\n Gettransaction amount: ".$trxinfo["amount"]
."\n Gettransaction confirmations: ".$trxinfo["confirmations"]
."\n Gettransaction blockhash: ".$trxinfo["blockhash"]
."\n Gettransaction blockindex: ".$trxinfo["blockindex"]
."\n Gettransaction blocktime: ".$trxinfo["blocktime"]
."\n Gettransaction txid: ".$trxinfo["txid"]
."\n Gettransaction time: ".$trxinfo["time"]
."\n Gettransaction timereceived: ".$trxinfo["timereceived"]
."\n Gettransaction account: ".$trxinfo["details"][0]["account"]
."\n Gettransaction address: ".$trxinfo["details"][0]["address"]
."\n Gettransaction category: ".$trxinfo["details"][0]["category"]
."\n Gettransaction amount: ".$trxinfo["details"][0]["amount"]
//."\n Gettransaction fee: ".$trxinfo["details"][0]["fee"]  // According to https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list, fee is returned, but it doesn't seem that way here
;

$fp=fopen("/tmp/notify_wallet.txt","a");
fwrite($fp,$new);
}
?>

When I send testnet coins from my eWallet to my Bitcoin-QT, the above walletnotify.php fetches the transaction's data from the wallet and writes it to the text file.  It works well.

I didn't need the following code:

Code:
!/bin/php

Thanks for your help!
kjj
legendary
Activity: 1302
Merit: 1026
January 31, 2014, 01:08:41 PM
#20
I'm not on a mac, but try these anyway.

This is a minimal, but functional, PHP script that can be called from walletnotify:

Code: (walletnotify.php)
!/bin/php

if(2==$argc){
 
$fp=fopen("/tmp/notify_wallet","a");
 
$out=date("Ymd His")." - ".$argv[1]."\n";
 
fwrite($fp,$out);
}
?>


And two tested and working walletnotify lines:

Code:
walletnotify=/usr/local/bin/walletnotify.php %s
Code:
walletnotify=/bin/php /usr/local/bin/walletnotify.php %s

Note that there are no quotes in either line.

For the first option, the php file must be executable, and the path to your php binary must be set in the first line.  In the second option, you need to set your php path correctly in the walletnotify line.

Try these two first.  If you can get one of them working, you have a working baseline for making your own changes.  If you can't get it working, let me know and we'll figure it out.

Is ? a valid means of passing arguments to PHP on the command line?  I've never tried it.  I always use argc/argv, but my quick google search suggests that you can also use CGI style arguments:

/path/to/php /path/to/script.php trxhash=%s

and trxhash will be populated in $_GET, etc.

The following works with ? as a means of passing arguments to PHP:

walletnotify=curl http://localhost:8888/script.php/?trxhash=%s

curl is talking to your webserver, so HTTP syntax rules applies there (but not here, unless you want to run it that way).

How do I use argc/argv?

See above.  Basically, argc is the number of arguments on the command line, including the name of the script.  argv is an array of the command line elements, starting with argv[0] set to the name of the script.

I tried the following by entering it in my Mac terminal and it works:

/usr/bin/php /path/to/script.php

I tried the following by entering them in my Mac terminal, but they do not work:

/usr/bin/php /path/to/script.php/?wallethash=testing

You have no file named "/path/to/script.php/?wallethash=testing" on your system.  ?, = and even / are perfectly valid characters to have in a filename.  (really!)

The above returns this error:

Could not open input file: /usr/bin/php /path/to/script.php/?wallethash=testing

/usr/bin/php /path/to/script.php?wallethash=testing

The above returns this error:

Could not open input file: /usr/bin/php /path/to/script.php?wallethash=testing

Ditto.

I put in the following into my PHP program:

print_r($_GET['blockhash']);
print_r($_SERVER['QUERY_STRING']);


I tried the following in my Mac terminal:

/usr/bin/php /path/to/script.php wallethash=testing

The above returns this error:

PHP Notice:  Undefined index:  wallethash in /path/to/script.php on line 17
PHP Notice:  Undefined index:  QUERY_STRING in /path/to/script.php on line 18

I welcome any other suggestions.

Double check your names.  You seem to be switching between wallethash and blockhash.  Also, try print_r($_GET);
jlp
sr. member
Activity: 266
Merit: 264
January 31, 2014, 10:34:27 AM
#19
Is ? a valid means of passing arguments to PHP on the command line?  I've never tried it.  I always use argc/argv, but my quick google search suggests that you can also use CGI style arguments:

/path/to/php /path/to/script.php trxhash=%s

and trxhash will be populated in $_GET, etc.

The following works with ? as a means of passing arguments to PHP:

walletnotify=curl http://localhost:8888/script.php/?trxhash=%s

How do I use argc/argv?

I tried the following by entering it in my Mac terminal and it works:

/usr/bin/php /path/to/script.php

I tried the following by entering them in my Mac terminal, but they do not work:

/usr/bin/php /path/to/script.php/?wallethash=testing

The above returns this error:

Could not open input file: /usr/bin/php /path/to/script.php/?wallethash=testing

/usr/bin/php /path/to/script.php?wallethash=testing

The above returns this error:

Could not open input file: /usr/bin/php /path/to/script.php?wallethash=testing

I put in the following into my PHP program:

print_r($_GET['blockhash']);
print_r($_SERVER['QUERY_STRING']);


I tried the following in my Mac terminal:

/usr/bin/php /path/to/script.php wallethash=testing

The above returns this error:

PHP Notice:  Undefined index:  wallethash in /path/to/script.php on line 17
PHP Notice:  Undefined index:  QUERY_STRING in /path/to/script.php on line 18

I welcome any other suggestions.
kjj
legendary
Activity: 1302
Merit: 1026
January 31, 2014, 08:19:16 AM
#18
Is ? a valid means of passing arguments to PHP on the command line?  I've never tried it.  I always use argc/argv, but my quick google search suggests that you can also use CGI style arguments:

/path/to/php /path/to/script.php trxhash=%s

and trxhash will be populated in $_GET, etc.
jlp
sr. member
Activity: 266
Merit: 264
January 30, 2014, 11:02:20 PM
#17
KJJ is saying the path to the PHP executable NOT the script, you have that.

Depending on your system it will most likely be something like

/usr/bin/php /Users/JLP/git_source/src/bin/walletnotify.php %s

if your on a linux-ish system (Mac, linux) you can run `whereis php` and that should tell you

Thanks for clarifying it.

I ran `whereis php` and terminal replied with:

/usr/bin/php

I changed bitcoin.conf so that it has the following:

walletnotify=/usr/bin/php /Users/JLP/git_source/src/bin/walletnotify.php/?trxhash=%s

...but it still does not work.  I changed it to the following:

walletnotify="/usr/bin/php /Users/JLP/git_source/src/bin/walletnotify.php/?trxhash=%s"

...but it still does not work.  Does anyone have any suggestions on how to get this to work?
newbie
Activity: 4
Merit: 0
January 30, 2014, 03:41:01 PM
#16
KJJ is saying the path to the PHP executable NOT the script, you have that.

Depending on your system it will most likely be something like

/usr/bin/php /Users/JLP/git_source/src/bin/walletnotify.php %s

if your on a linux-ish system (Mac, linux) you can run `whereis php` and that should tell you
jlp
sr. member
Activity: 266
Merit: 264
January 30, 2014, 02:08:09 PM
#15
Specify the path to php.

I'm not sure if your posting is in reply to my question about invoking my PHP program.  If so, I'm not sure what you mean.  I had specified the path to the php file.  It is /Users/JLP/git_source/src/bin/walletnotify.php in the following string:

walletnotify=php /Users/JLP/git_source/src/bin/walletnotify.php %s

If I can get this to work, isn't this the preferred method than to use curl, which seems like a roundabout way?
kjj
legendary
Activity: 1302
Merit: 1026
January 30, 2014, 01:59:42 PM
#14
jlp
sr. member
Activity: 266
Merit: 264
January 30, 2014, 12:14:51 PM
#13
Hi,

I am trying to use the -walletnotify option to run a php script which updates a log file/sql db with transaction id of new transaction affecting wallet.

For some reason I cannot get it working. I am using bitcoin version 80100.

I have tried this in my bitcoin.conf:

walletnotify=php /home/blahblah/Downloads/btcdev/walletnotify.php %s

and..

walletnotify="php /home/blahblah/Downloads/btcdev/walletnotify.php %s"


and also run bitcoind with and without the walletnotify commandline options: bitcoind -datadir=/home/blahblah/Downloads/testnet -testnet -debug -printtoconsole -walletnotify=php /home/blahblah/Downloads/btcdev/walletnotify.php %s

I can see the new transactions coming in but neither bitcoin-qt or bitcoind seem to try to run my script or error.

Any suggestions? Grin

Inca

I can get walletnotify to run a shell script.  Similar to user Inca, I cannot get walletnofiy to run a PHP program.

I am using Bitcoin-QT version 0.8.6 in testnet mode on a Mac OSX.  I have tried this in my bitcoin.conf:

walletnotify=php /Users/JLP/git_source/src/bin/walletnotify.php %s

and..

walletnotify="php /Users/JLP/git_source/src/bin/walletnotify.php %s"

I ran this in my terminal:

chmod a+x /Users/JLP/git_source/src/bin/walletnotify.php

but still to no avail.  Can someone help?

Update:  I found out how to invoke the php program.  I used curl:

walletnotify=curl http://localhost:8888/walletnotify.php/?transactionhash=%s

Is this transaction hash equal to the transaction id as required by the gettransaction command from https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list?
kjj
legendary
Activity: 1302
Merit: 1026
December 17, 2013, 08:50:52 AM
#12
If that is a concern for you, use something that you know can handle concurrent writes, like a database.
sr. member
Activity: 332
Merit: 250
AwesomeDice.net
December 17, 2013, 08:41:51 AM
#11
When using shell script, does the log file has write protection?
If for example, two notifications being issued, can the text become scrambled if the two scripts trying to write at the same time?
kjj
legendary
Activity: 1302
Merit: 1026
December 14, 2013, 08:28:33 PM
#10
Specify the path to php.
legendary
Activity: 1176
Merit: 1000
December 14, 2013, 08:15:39 PM
#9
Hi,

I am trying to use the -walletnotify option to run a php script which updates a log file/sql db with transaction id of new transaction affecting wallet.

For some reason I cannot get it working. I am using bitcoin version 80100.

I have tried this in my bitcoin.conf:

walletnotify=php /home/blahblah/Downloads/btcdev/walletnotify.php %s

and..

walletnotify="php /home/blahblah/Downloads/btcdev/walletnotify.php %s"


and also run bitcoind with and without the walletnotify commandline options: bitcoind -datadir=/home/blahblah/Downloads/testnet -testnet -debug -printtoconsole -walletnotify=php /home/blahblah/Downloads/btcdev/walletnotify.php %s

I can see the new transactions coming in but neither bitcoin-qt or bitcoind seem to try to run my script or error.

Any suggestions? Grin

Inca
kjj
legendary
Activity: 1302
Merit: 1026
May 16, 2013, 07:50:20 PM
#8
DDOS?  zero.  There is no amplification, no redirection.

Someone can try to DOS you.  But it'll be expensive.  Your node will spawn a process for each transaction that hits your wallet, not for each output.  You should strive to make the spawned process as light and short lived as possible, but for the most part, there isn't much danger.
hero member
Activity: 740
Merit: 501
May 16, 2013, 12:44:18 PM
#7
On the server I used for testing, in my bitcoin.conf:
Code:
walletnotify=/home/btcdev/walletnotify.sh %s
blocknotify=/home/btcdev/blocknotify.sh %s

The %s in the command line gets replaced with the (ASCII) hex string of the transaction hash, just like -blocknotify replaces it with the block hash.

And the program can be as simple or as complicated as you like.  Here is a simple shell script:

Code:
#!/bin/bash
F=/home/btcdev/wallet_transaction_log
D=`date +"%Y%m%d%H%M%S"`
echo ${D} - ${1} >> ${F}

which gives lines like:

Code:
20130513123015 - 6fa6c8ff08f122327b7a0a329d7632f243038f0fc96cce1248cb4948d0509ecf

You aren't limited to shell scripts, of course.

A pipe would have been better, but they aren't portable.  Even if we had been willing to limit it to just UNIX-ish systems, there would have been horrible locking problems, and these notices simply weren't worth the effort to work around them*.  If you want similar behavior, you can fake a pipe with netcat, so that you could have a long running service that accepts TCP connections from localhost, and just call netcat to dump the txid to that socket.

Did you know that named pipes can stall in both directions, potentially DOSing one of the client threads?  There are ways around it, of course, but you have to throw out a lot of the abstractions, so there would have been a very un-C++ chunk of code in the bitcoin client, just for dealing with the pipes.  At least that was how it looked to me when I was researching it.  I don't do much with C++, so I'm hoping that someone in the audience is more skilled than I am, and will read this and say "You dumbass, why didn't you just do X?", or even better, rewrite it for me.  Smiley

So basically, I can write a quick C# app to send a udp packet to the local host and listen there with the server. I am wondering what is the DDoS potential of such an attack?
kjj
legendary
Activity: 1302
Merit: 1026
May 13, 2013, 02:20:24 PM
#6
On the server I used for testing, in my bitcoin.conf:
Code:
walletnotify=/home/btcdev/walletnotify.sh %s
blocknotify=/home/btcdev/blocknotify.sh %s

The %s in the command line gets replaced with the (ASCII) hex string of the transaction hash, just like -blocknotify replaces it with the block hash.

And the program can be as simple or as complicated as you like.  Here is a simple shell script:

Code:
#!/bin/bash
F=/home/btcdev/wallet_transaction_log
D=`date +"%Y%m%d%H%M%S"`
echo ${D} - ${1} >> ${F}

which gives lines like:

Code:
20130513123015 - 6fa6c8ff08f122327b7a0a329d7632f243038f0fc96cce1248cb4948d0509ecf

You aren't limited to shell scripts, of course.

A pipe would have been better, but they aren't portable.  Even if we had been willing to limit it to just UNIX-ish systems, there would have been horrible locking problems, and these notices simply weren't worth the effort to work around them*.  If you want similar behavior, you can fake a pipe with netcat, so that you could have a long running service that accepts TCP connections from localhost, and just call netcat to dump the txid to that socket.

Did you know that named pipes can stall in both directions, potentially DOSing one of the client threads?  There are ways around it, of course, but you have to throw out a lot of the abstractions, so there would have been a very un-C++ chunk of code in the bitcoin client, just for dealing with the pipes.  At least that was how it looked to me when I was researching it.  I don't do much with C++, so I'm hoping that someone in the audience is more skilled than I am, and will read this and say "You dumbass, why didn't you just do X?", or even better, rewrite it for me.  Smiley
hero member
Activity: 740
Merit: 501
May 13, 2013, 12:50:54 PM
#5
Cron job lol, it's subbitcoin level security that might fly with Paypal or banks that don't care that their accounts with tens of thousands of dollars are being sold for 100 bucks on the darknet...

I've read this four times now, and I still don't know what you are trying to say.

Nevermind, can you please provide a sample of setting up walletnotify to execute an app?
kjj
legendary
Activity: 1302
Merit: 1026
May 13, 2013, 09:27:25 AM
#4
Cron job lol, it's subbitcoin level security that might fly with Paypal or banks that don't care that their accounts with tens of thousands of dollars are being sold for 100 bucks on the darknet...

I've read this four times now, and I still don't know what you are trying to say.
hero member
Activity: 740
Merit: 501
May 13, 2013, 08:56:16 AM
#3
If you are talking about the -walletnotify config option in 0.8.2rc1, it works exactly like -blocknotify.  You specify the path to a program to be run.

The program will be run with a single argument (the transaction hash) when a new transaction hits your wallet.  Actually, it will run once or twice per transaction.  First time will be if you receive that transaction as a transaction, and the second time when you receive it as part of a block.

That program can be a script that uses some other tool (curl, wget, whatever) to issue a call out to an external webservice, or it can do whatever you need directly (update a database, logfile, etc).

If you are a high volume site that gets lots of transactions, you may need to be careful with it.  It can spawn a lot of new processes, so you should make your script fast and simple.  Just dump the txhash to a journal file (or table) and exit, for example, with a cron job to come around later to collect and process them in batches.

People were looking for a simple way to track incoming transactions, and this was the easiest way to do it.  It has some quirks, but it is still vastly superior to the hacks people were having to use before.

Cron job lol, it's subbitcoin level security that might fly with Paypal or banks that don't care that their accounts with tens of thousands of dollars are being sold for 100 bucks on the darknet...
kjj
legendary
Activity: 1302
Merit: 1026
May 13, 2013, 06:24:42 AM
#2
If you are talking about the -walletnotify config option in 0.8.2rc1, it works exactly like -blocknotify.  You specify the path to a program to be run.

The program will be run with a single argument (the transaction hash) when a new transaction hits your wallet.  Actually, it will run once or twice per transaction.  First time will be if you receive that transaction as a transaction, and the second time when you receive it as part of a block.

That program can be a script that uses some other tool (curl, wget, whatever) to issue a call out to an external webservice, or it can do whatever you need directly (update a database, logfile, etc).

If you are a high volume site that gets lots of transactions, you may need to be careful with it.  It can spawn a lot of new processes, so you should make your script fast and simple.  Just dump the txhash to a journal file (or table) and exit, for example, with a cron job to come around later to collect and process them in batches.

People were looking for a simple way to track incoming transactions, and this was the easiest way to do it.  It has some quirks, but it is still vastly superior to the hacks people were having to use before.
Pages:
Jump to: