Bitcoin Forum
May 13, 2024, 07:13:42 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to use walletnotify and blocknotify?  (Read 6452 times)
cryptoxloubis (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 1


View Profile
February 04, 2014, 12:52:00 PM
Merited by ABCbits (1)
 #1

Well I am developing an application that I want the user to deposit some coins (same for withdrawal). I want to do 2 things:

  • When I ack that the deposit has taken place I want to create an "unconfirmed" record to an SQL db with the details of the transaction and change the balance of the user (0 confirms ATM).
  • Afterwards I want to "monitor" these transactions in order to confirm that they had actually taken place i.e. the number of confirmations are >= MIN_CONFIRMS. This confirmation merely changes the status of the record created on no.1 to confirmed.

I have read that with the walletnotify option, a program can be run every time a wallet transaction changes (Can anyone clarify when a wallet transaction changes?). This program (in the walletnotify option) must be really simple and fast thus I cannot use it to achieve no.1 because in order to get the details of the transaction I have to make RPC call which is slow.

On the other hand there is the blocknotify option that specifies a program to run every time the best block changes (I still need clarification on when the best block changes?).

So how one can achieve these 2 things using walletnotify and/or blocknotify?

Thanks!

P.S. Newbie here, so be gentle Wink
1715627622
Hero Member
*
Offline Offline

Posts: 1715627622

View Profile Personal Message (Offline)

Ignore
1715627622
Reply with quote  #2

1715627622
Report to moderator
Each block is stacked on top of the previous one. Adding another block to the top makes all lower blocks more difficult to remove: there is more "weight" above each block. A transaction in a block 6 blocks deep (6 confirmations) will be very difficult to remove.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715627622
Hero Member
*
Offline Offline

Posts: 1715627622

View Profile Personal Message (Offline)

Ignore
1715627622
Reply with quote  #2

1715627622
Report to moderator
1715627622
Hero Member
*
Offline Offline

Posts: 1715627622

View Profile Personal Message (Offline)

Ignore
1715627622
Reply with quote  #2

1715627622
Report to moderator
Automatic
Full Member
***
Offline Offline

Activity: 238
Merit: 105


View Profile
February 04, 2014, 03:38:10 PM
Merited by ABCbits (3), paid2 (1)
 #2

How I currently do it:-

bitcoin.conf:-
Code:
rpcuser=Hellno
rpcpassword=Hellno
maxconnections=1000
checklevel=4
keypool=10000
rpcallowip=127.0.0.1
server=1
blocknotify=/home/bitcoin/block.sh %s
walletnotify=/home/bitcoin/wallet.sh %s
alertnotify=/home/bitcoin/alert.sh %s

Then the .sh's are as follows:-
alert.sh:-
Code:
#!/bin/sh
curl "http://127.0.0.1:9485/alert" -d "$@"

block.sh:-
Code:
#!/bin/sh
curl "http://127.0.0.1:9485/block" -d "$@"

wallet.sh:-
Code:
#!/bin/sh
curl "http://127.0.0.1:9485/wallet" -d "$@"

In the program itself, I listen on local host like this:-
Code:
//HTTP objects
var http = require('http');
var httpServer = http.createServer(function (req, res) {
dealWithHTTP(req, res);
}).listen("9485", "127.0.0.1", 511, function (err) {
if(err) {
console.log("HTTP ERROR:-", err);
}
});

Then the 'dealwithhttp' is basically a switch statement based on /alert, /block, or, /wallet. /Alert sends me a message directly, /wallet (I.E. payment incoming) applies an update to the DB based on the arguments (Post data), and, messages me also (I like to know!), finally, /block looks for any unconfirmed addresses, and, rechecks them with the bitcoind. Maybe not the best way of doing it, but, a way. As you said you didn't want to do another RPC call, I can't help you, but, least this is a starting place.

Code:
(Can anyone clarify when a [i]wallet transaction changes[/i]?).

From what I've seen, once when it receives a payment, once when it receives the first confirmation (I.E. first time it sees it past the broadcast), and once when you send a payment.

Please ask for a signed message from my on-site Bitcoin address (Check my profile) before doing any offsite trades with me.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!