Title: Wallet notify using a PHP routing system? Post by: StayCool93 on May 15, 2018, 06:43:17 AM Hi.
I'm running a Symfony4 (PHP) project which makes use of a routing system. I want to use walletnotify in the following way, but i want to make sure that it's right before testing: bitcoin.conf: walletnotify=curl http://127.0.0.1:8000/wallet/notify/%s Route: https://i.stack.imgur.com/nBDNl.png how would i use the argv function in this case and would it work without specifying a .php extension? Title: Re: Wallet notify using a PHP routing system? Post by: bob123 on May 15, 2018, 07:26:09 AM I'm running a Symfony4 (PHP) project which makes use of a routing system. Routing system? ??? Mind explaining what you mean? I want to use walletnotify in the following way, but i want to make sure that it's right before testing: bitcoin.conf: walletnotify=curl http://127.0.0.1:8000/wallet/notify/%s ~snip~ how would i use the argv function in this case and would it work? You have to specify the path to your script. E.g. : Code: walletnotify = /home/path/to/your/script.sh %s And inside your script.sh you can have the following: Code: #!/bin/sh %s (transaction ID) will be passed to your script and can be used/accessed via $1 (argv). Note that walletnotify is called when: 1) You receive a transaction 2) You send a transaction 3) A (receiving) transaction gets the first confirmation If you want to check for a further status (2+ confirmations), you have to use blocknotify instead of walletnotify. Title: Re: Wallet notify using a PHP routing system? Post by: StayCool93 on May 15, 2018, 07:29:53 AM I'm running a Symfony4 (PHP) project which makes use of a routing system. Routing system? ??? Mind explaining what you mean? You can read more here: https://symfony.com/doc/current/routing.html It's essentially just removing the uglyness in URL's, such as the .php extension... I want to use walletnotify in the following way, but i want to make sure that it's right before testing: bitcoin.conf: walletnotify=curl http://127.0.0.1:8000/wallet/notify/%s ~snip~ how would i use the argv function in this case and would it work? You have to specify the path to your script. E.g. : Code: walletnotify = /home/path/to/your/script.sh %s And inside your script.sh you can have the following: Code: #!/bin/sh %s (transaction ID) will be passed to your script and can be used/accessed via $1 (argv). Note that walletnotify is called when: 1) You receive a transaction 2) You send a transaction 3) A (receiving) transaction gets the first confirmation If you want to check for a further status (2+ confirmations), you have to use blocknotify instead of walletnotify. Thank you very much, i'll try it out! Is there no way to do it directly without the need for a bash script? Also in regards to the path, is it starting from the folder where bitcoin.conf is located? or the root of the system? I suppose i should create a home folder where the bitcoin.conf is? & to access the $1 in argv, do i simply do $transactionID = $argv[$1]; ? Title: Re: Wallet notify using a PHP routing system? Post by: bob123 on May 15, 2018, 08:05:47 AM Is there no way to do it directly without the need for a bash script? walletnotify and blocknotify do run a script if a specific event happens. You don't have to use a bash script. Python/PHP would work too, or any other scripting language. But a script is needed. Also in regards to the path, is it starting from the folder where bitcoin.conf is located? or the root of the system? I suppose i should create a home folder where the bitcoin.conf is? If you specify the path like directory1/test.sh then it is a relative path (from where the executable is being started started (e.g. bitcoind folder)). If you specify the path like /directory1/test.sh then it is an absolute path (from root folder). & to access the $1 in argv, do i simply do $transactionID = $argv[$1]; ? IIRC you just have to use $transactionID = $1. But i am not completely sure about that. It may also be $argv[1] or $argv[0](less probable, since this should be the command 'itself'). Title: Re: Wallet notify using a PHP routing system? Post by: starmyc on May 15, 2018, 09:40:36 AM Hi. I'm running a Symfony4 (PHP) project which makes use of a routing system. I want to use walletnotify in the following way, but i want to make sure that it's right before testing: bitcoin.conf: walletnotify=curl http://127.0.0.1:8000/wallet/notify/%s Route: https://i.stack.imgur.com/nBDNl.png how would i use the argv function in this case and would it work without specifying a .php extension? argv is for CLI - command line - usage. If you are going through an web server (and you will, if you're using Symfony controllers), $argv will not be defined. If your Symfony route is /wallet/notify/{txid}, then your function will be most likely be prototyped like the following, and you'll be able to retrieve your transaction id using $txid (given as a parameter in your function): Code: class WalletNotifyController Extends Controller Symfony documentation is pretty much complete, with a lot of samples (https://symfony.com/doc/current/routing.html). You should give it a try. Title: Re: Wallet notify using a PHP routing system? Post by: StayCool93 on May 15, 2018, 10:04:56 AM Hi. I'm running a Symfony4 (PHP) project which makes use of a routing system. I want to use walletnotify in the following way, but i want to make sure that it's right before testing: bitcoin.conf: walletnotify=curl http://127.0.0.1:8000/wallet/notify/%s Route: https://i.stack.imgur.com/nBDNl.png how would i use the argv function in this case and would it work without specifying a .php extension? argv is for CLI - command line - usage. If you are going through an web server (and you will, if you're using Symfony controllers), $argv will not be defined. If your Symfony route is /wallet/notify/{txid}, then your function will be most likely be prototyped like the following, and you'll be able to retrieve your transaction id using $txid (given as a parameter in your function): Code: class WalletNotifyController Extends Controller Symfony documentation is pretty much complete, with a lot of samples (https://symfony.com/doc/current/routing.html). You should give it a try. Yes i realise how Symfony works, the primary concern i had was how i should formulate the walletnotify script to be able to pass the TXID parameter into the controller and if the following would work :-) Thanks! walletnotify=curl http://127.0.0.1:8000/wallet/notify/%s but it seems like i have to use a bash script. Title: Re: Wallet notify using a PHP routing system? Post by: bob123 on May 15, 2018, 10:11:57 AM but it seems like i have to use a bash script. You should have read my post more carefully ;) You don't have to use a bash script. Python/PHP would work too, or any other scripting language. Title: Re: Wallet notify using a PHP routing system? Post by: StayCool93 on May 15, 2018, 10:24:35 AM but it seems like i have to use a bash script. You should have read my post more carefully ;) You don't have to use a bash script. Python/PHP would work too, or any other scripting language. Can you provide an PHP example? it seems like you want me to link to a file.php (which then takes args as a input), but i'm using controllers without extensions and would like to simply pass it to that :-) i would really like if i could just do it in one line... Title: Re: Wallet notify using a PHP routing system? Post by: bob123 on May 15, 2018, 10:43:30 AM Can you provide an PHP example? it seems like you want me to link to a file.php (which then takes args as a input), but i'm using controllers without extensions and would like to simply pass it to that :-) Your config or startup command: Code: walletnotify = /home/path/to/your/script.php %s walletnotify does pass the transaction hash to your PHP script. In your php script: Code: $TransactionHash = $argv[1] Afterwards you can do whatever you want with the TX ID. Curl example: Code: $curl = curl_init(); i would really like if i could just do it in one line... What exactly are you trying to do? Not everything can be implemented as a one-liner :P Curl itself (executed inside a php script) does need 4 lines. Title: Re: Wallet notify using a PHP routing system? Post by: starmyc on May 15, 2018, 10:46:15 AM Can you provide an PHP example? it seems like you want me to link to a file.php (which then takes args as a input), but i'm using controllers without extensions and would like to simply pass it to that :-) i would really like if i could just do it in one line... If you want to use Symfony, and your Symfony application is on the same host, you can do it simpler that using the whole curl/http/controller stuff, why don't you try to create and use a custom console Command (https://symfony.com/doc/current/console.html) ? Don't copy/paste the following example as I did not test it (just wrote like this), but this should work: Code: <?php Your commande will be usable doing the following: Code: php /path/to/your/symfony-app/bin/console my-app:notify-tx THE_TX_ID Then you'll be able to put in the Bitcoin's bitcoin.conf configuration file: Code: walletnotify = php /path/to/your/symfony-app/bin/console my-app:notify-tx %s If your symfony app is not on the same host than bitcoin's wallet, you have to use curl to reach the external web server. You can do a php script like this (again, wrote it quickly, didn't test it): Code: <?php And put in bitcoin.conf: Code: walletnotify=php /path/to/your/script.php %s Title: Re: Wallet notify using a PHP routing system? Post by: StayCool93 on May 15, 2018, 03:35:39 PM Thanks for the help guys. However i found the following solution:
walletnotify=curl 'http://localhost:8000/wallet/notify/'%s which is working perfectly, without the need of a script. |