Bitcoin Forum
April 21, 2019, 05:00:20 PM *
News: Latest Bitcoin Core release: 0.17.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: how to use wallet notify (bitcoind) ?  (Read 3498 times)
HackerBOSS
Full Member
***
Offline Offline

Activity: 210
Merit: 100


View Profile
April 19, 2016, 02:50:25 PM
 #1

Hello,

how to use wallet notify (bitcoind) ?

I generate new address by json-rpc..


I need update info in MySQL after 3 confirmations.

how think how much need confirmations for receive payments?

Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1555866020
Hero Member
*
Offline Offline

Posts: 1555866020

View Profile Personal Message (Offline)

Ignore
1555866020
Reply with quote  #2

1555866020
Report to moderator
1555866020
Hero Member
*
Offline Offline

Posts: 1555866020

View Profile Personal Message (Offline)

Ignore
1555866020
Reply with quote  #2

1555866020
Report to moderator
danda
Full Member
***
Offline Offline

Activity: 188
Merit: 126


View Profile WWW
April 20, 2016, 05:25:45 AM
 #2

    -alertnotify=<cmd>    Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)
   -blocknotify=<cmd>    Execute command when the best block changes (%s in cmd is replaced by block hash)
    -walletnotify=<cmd>    Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)


So for individual transactions, you would want to use walletnotify, eg:

Code:
bitcoind -walletnotify=/path/to/script.php %s

Then in script.php, you could do something like:

Code:
<?php
$tx 
$argv[1];
$txinfo json_decode( `bitcoin-cli gettransaction $tx` );
if( 
$txinfo['confirmations'] >= ) {
    
// update mysql if necessary.
}
of course with sanitization, error checks, etc....   ;-)


If you are likely to have more than one tx in a given block, a more efficient way to do it can be to include the block-hash with the tx in the db, so you can look up all tx by block.  Then use blocknotify instead of walletnotify.


edit:  and don't forget that the txid can change due to transaction malleability. 

mybitprices.info - wallet auditing tools
HackerBOSS
Full Member
***
Offline Offline

Activity: 210
Merit: 100


View Profile
April 20, 2016, 07:46:43 AM
 #3

   -alertnotify=<cmd>    Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)
   -blocknotify=<cmd>    Execute command when the best block changes (%s in cmd is replaced by block hash)
    -walletnotify=<cmd>    Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)


So for individual transactions, you would want to use walletnotify, eg:

Code:
bitcoind -walletnotify=/path/to/script.php %s

Then in script.php, you could do something like:

Code:
<?php
$tx 
$argv[1];
$txinfo json_decode( `bitcoin-cli gettransaction $tx` );
if( 
$txinfo['confirmations'] >= ) {
    
// update mysql if necessary.
}
of course with sanitization, error checks, etc....   ;-)


If you are likely to have more than one tx in a given block, a more efficient way to do it can be to include the block-hash with the tx in the db, so you can look up all tx by block.  Then use blocknotify instead of walletnotify.


edit:  and don't forget that the txid can change due to transaction malleability. 

Thanks!

how much times wallet notify call script.php ?
 

belcher
Sr. Member
****
Offline Offline

Activity: 258
Merit: 312


View Profile
April 20, 2016, 12:15:32 PM
 #4

-walletnotify will run twice per transaction, when it's first seen on the network as unconfirmed, and when it gets it's first confirmation.

To track more than one confirmation you need to use -blocknotify

1HZBd22eQLgbwxjwbCtSjhoPFWxQg8rBd9
JoinMarket - CoinJoin that people will actually use.
PGP fingerprint: 0A8B 038F 5E10 CC27 89BF CFFF EF73 4EA6 77F3 1129
HackerBOSS
Full Member
***
Offline Offline

Activity: 210
Merit: 100


View Profile
April 20, 2016, 12:25:39 PM
 #5

-walletnotify will run twice per transaction, when it's first seen on the network as unconfirmed, and when it gets it's first confirmation.

To track more than one confirmation you need to use -blocknotify

after first confirmation payment not lost?

HackerBOSS
Full Member
***
Offline Offline

Activity: 210
Merit: 100


View Profile
April 20, 2016, 12:29:27 PM
 #6

-walletnotify will run twice per transaction, when it's first seen on the network as unconfirmed, and when it gets it's first confirmation.

To track more than one confirmation you need to use -blocknotify

and blocknotify how much times call myscript.php?

Polyatomic
Sr. Member
****
Offline Offline

Activity: 256
Merit: 250


View Profile
April 21, 2016, 12:10:31 AM
Last edit: April 29, 2016, 09:34:32 AM by Polyatomic
 #7

Every new block.
Code:
milton@milton:~$ ps -eo cmd | egrep bitcoind | egrep -v grep
bitcoind -daemon -blocknotify=blocknotify %s

Code:
#!/bin/bash -e

block_message()
{
    local DATE=$1
    local HEIGHT=$2
    local BLOCKHASH=$3
    echo -e "+====================================================================="
    echo -e "| \033[31m ${DATE} \033[0m"
    echo -e "+====================================================================="
    echo -e "| \033[31m ${HEIGHT} \033[0m"
    echo -e "+====================================================================="
    echo -e "| \033[31m ${BLOCKHASH} \033[0m"
    echo -e "+====================================================================="

} >> $HOME/temp/blocknotify.txt

block_message "$(date -u)" "$(bitcoin-cli getblockcount)" "$@"

Code:
milton@milton:~$ tail -f temp/blocknotify.txt
+====================================================================+
| 0000000000000000016c397b5eac0d5b3580d11b585996d2a8452bef2e03fa3e   |
+====================================================================+
+====================================================================+
| Wed Apr 20 23:49:27 UTC 2016                                                            
+====================================================================+
| 408221                                                          
+====================================================================+
| 0000000000000000033ed3a5284a10c8992cb9411bf4fd33a130fc742436e3f7   |
+====================================================================+
HackerBOSS
Full Member
***
Offline Offline

Activity: 210
Merit: 100


View Profile
April 21, 2016, 03:06:32 AM
 #8

i use gettransaction($txid);

how get my wallet address for receiving? (this method get payer wallet address only)

Alaki
Sr. Member
****
Offline Offline

Activity: 266
Merit: 250


View Profile
April 21, 2016, 03:53:47 AM
 #9

i use gettransaction($txid);

how get my wallet address for receiving? (this method get payer wallet address only)
Run this command->
Code:
getaccountaddress <account>
. This'll return the current bitcoin address for receiving payments to this account. If <account> does not exist, it will be created along with an associated new address that'll be returned.
P.S.-> "getaccountaddress" will return the same address until coins are received on that address; once coins have been received, it will generate and return a new address.
HackerBOSS
Full Member
***
Offline Offline

Activity: 210
Merit: 100


View Profile
April 21, 2016, 04:10:15 AM
 #10

i use gettransaction($txid);

how get my wallet address for receiving? (this method get payer wallet address only)
Run this command->
Code:
getaccountaddress <account>
. This'll return the current bitcoin address for receiving payments to this account. If <account> does not exist, it will be created along with an associated new address that'll be returned.
P.S.-> "getaccountaddress" will return the same address until coins are received on that address; once coins have been received, it will generate and return a new address.

ok.

i generated 2 addresses getaccountaddress();
after i send btc to 1 new generated address.

and call gettransaction($txid);

how get address of 2 addresses that received payemnt?

Alaki
Sr. Member
****
Offline Offline

Activity: 266
Merit: 250


View Profile
April 21, 2016, 04:40:40 AM
 #11



 
ok.

i generated 2 addresses getaccountaddress();
after i send btc to 1 new generated address.

and call gettransaction($txid);

how get address of 2 addresses that received payemnt?

You mean listing your addresses that've received payment(in the past)? Yep that's possible as well. Run this command->
Code:
listreceivedbyaddress
. Basically, it lists only addresses that already 've received transactions. However, you can list all the addresses by setting the first argument to 0, and the second one to true->
Code:
listreceivedbyaddress 0 true
HackerBOSS
Full Member
***
Offline Offline

Activity: 210
Merit: 100


View Profile
April 21, 2016, 06:13:39 AM
 #12



 
ok.

i generated 2 addresses getaccountaddress();
after i send btc to 1 new generated address.

and call gettransaction($txid);

how get address of 2 addresses that received payemnt?

You mean listing your addresses that've received payment(in the past)? Yep that's possible as well. Run this command->
Code:
listreceivedbyaddress
. Basically, it lists only addresses that already 've received transactions. However, you can list all the addresses by setting the first argument to 0, and the second one to true->
Code:
listreceivedbyaddress 0 true

for example sport betting..

1 wallet - win #1 team
2 wallet - win #2 team

player placed bet to 2 wallet.. (send paymet to 2 wallet)

my script get hash, amount etc.. but i need wallet of player.

 



shorena
Copper Member
Legendary
*
Offline Offline

Activity: 1484
Merit: 1288


No I dont escrow anymore.


View Profile WWW
April 21, 2016, 07:41:28 AM
 #13

-snip-
my script get hash, amount etc.. but i need wallet of player.

There is no simple way to get the "sending address"[1]. You have to check the inputs, but more often than not there will be several inputs. Its better to let the user set an address you store in your database along with their other information.

Code:
txid = dc8697d1afd6c7ac2f667cd3239e19bf227a7b5ce8be64b2f8bb3c626979425b # "random" one from the block to the hash that Polyatomic posted.
raw_tx = getrawtransaction(txid)
decoded_tx = decoderawtransaction(raw_tx)

within decoded_tx you will find a "vin" section with a value "vout" and a txid. If you check each of the txids you will see that they have a "vout" section. The outputs that created the inputs that are used in the TX you received. Find the one where "vout" matches "n" and look up its address. In this example there are 4 inputs, all "from" the address "1NgrpJJj2PMj9RsHutVK7vf8dchcpfM4YZ", but you need to decide how you want to handle different addresses.

IIRC the data is mixed formatted, arrays within JSON, but that might be different for PHP.

[1] there is no such thing
HackerBOSS
Full Member
***
Offline Offline

Activity: 210
Merit: 100


View Profile
April 21, 2016, 09:49:23 AM
 #14

-snip-
my script get hash, amount etc.. but i need wallet of player.

There is no simple way to get the "sending address"[1]. You have to check the inputs, but more often than not there will be several inputs. Its better to let the user set an address you store in your database along with their other information.

Code:
txid = dc8697d1afd6c7ac2f667cd3239e19bf227a7b5ce8be64b2f8bb3c626979425b # "random" one from the block to the hash that Polyatomic posted.
raw_tx = getrawtransaction(txid)
decoded_tx = decoderawtransaction(raw_tx)

within decoded_tx you will find a "vin" section with a value "vout" and a txid. If you check each of the txids you will see that they have a "vout" section. The outputs that created the inputs that are used in the TX you received. Find the one where "vout" matches "n" and look up its address. In this example there are 4 inputs, all "from" the address "1NgrpJJj2PMj9RsHutVK7vf8dchcpfM4YZ", but you need to decide how you want to handle different addresses.

IIRC the data is mixed formatted, arrays within JSON, but that might be different for PHP.

[1] there is no such thing

ok. i will experience..

but how make it secondstrade.com ?

bet is send to address only. no need enter player wallet

Alaki
Sr. Member
****
Offline Offline

Activity: 266
Merit: 250


View Profile
April 21, 2016, 10:27:54 AM
 #15


but how make it secondstrade.com ?

bet is send to address only. no need enter player wallet
Secondstrade do have a notice board[1] that'll(can) answer your above question. Basically, you'll not receive your payment if you do make a bet(transaction) with multiple(or >2) input addresses(&/or a shared wallet) AFAIK.
[1]-> http://secondstrade.com/notice.html
shorena
Copper Member
Legendary
*
Offline Offline

Activity: 1484
Merit: 1288


No I dont escrow anymore.


View Profile WWW
April 21, 2016, 11:09:18 AM
 #16

-snip-
my script get hash, amount etc.. but i need wallet of player.

There is no simple way to get the "sending address"[1]. You have to check the inputs, but more often than not there will be several inputs. Its better to let the user set an address you store in your database along with their other information.

Code:
txid = dc8697d1afd6c7ac2f667cd3239e19bf227a7b5ce8be64b2f8bb3c626979425b # "random" one from the block to the hash that Polyatomic posted.
raw_tx = getrawtransaction(txid)
decoded_tx = decoderawtransaction(raw_tx)

within decoded_tx you will find a "vin" section with a value "vout" and a txid. If you check each of the txids you will see that they have a "vout" section. The outputs that created the inputs that are used in the TX you received. Find the one where "vout" matches "n" and look up its address. In this example there are 4 inputs, all "from" the address "1NgrpJJj2PMj9RsHutVK7vf8dchcpfM4YZ", but you need to decide how you want to handle different addresses.

IIRC the data is mixed formatted, arrays within JSON, but that might be different for PHP.

[1] there is no such thing

ok. i will experience..

but how make it secondstrade.com ?

bet is send to address only. no need enter player wallet

AFAIK they do it in this crude way, same as most ponzi "games". If they warn you not to use certain wallets, they almost always just assume which is your address. This can fail horribly if your customer/user uses a wallet where they share addresses with others or use something like CoinJoin. A common example for shared wallets are most exchanges. You have your own deposit address, but when you withdraw the coins come from a different address. If you return coins to the address they came from they will be credited to a different account (if at all).
HackerBOSS
Full Member
***
Offline Offline

Activity: 210
Merit: 100


View Profile
April 26, 2016, 05:27:18 PM
 #17

-snip-
my script get hash, amount etc.. but i need wallet of player.

There is no simple way to get the "sending address"[1]. You have to check the inputs, but more often than not there will be several inputs. Its better to let the user set an address you store in your database along with their other information.

Code:
txid = dc8697d1afd6c7ac2f667cd3239e19bf227a7b5ce8be64b2f8bb3c626979425b # "random" one from the block to the hash that Polyatomic posted.
raw_tx = getrawtransaction(txid)
decoded_tx = decoderawtransaction(raw_tx)

within decoded_tx you will find a "vin" section with a value "vout" and a txid. If you check each of the txids you will see that they have a "vout" section. The outputs that created the inputs that are used in the TX you received. Find the one where "vout" matches "n" and look up its address. In this example there are 4 inputs, all "from" the address "1NgrpJJj2PMj9RsHutVK7vf8dchcpfM4YZ", but you need to decide how you want to handle different addresses.

IIRC the data is mixed formatted, arrays within JSON, but that might be different for PHP.

[1] there is no such thing

ok. i will experience..

but how make it secondstrade.com ?

bet is send to address only. no need enter player wallet

AFAIK they do it in this crude way, same as most ponzi "games". If they warn you not to use certain wallets, they almost always just assume which is your address. This can fail horribly if your customer/user uses a wallet where they share addresses with others or use something like CoinJoin. A common example for shared wallets are most exchanges. You have your own deposit address, but when you withdraw the coins come from a different address. If you return coins to the address they came from they will be credited to a different account (if at all).

thanks for your answer sir.

i have problem get who send payment..

for example this hash:
3d919bf7929b983954e9c439348649e11ba21f8f740530aa4ecbbd3c5f496071

a64020eea0719df9318e185d1a44cea8f9b5e872ced67e1e746fe1b9fbb6670c

who sent payment?
could you help me please


shorena
Copper Member
Legendary
*
Offline Offline

Activity: 1484
Merit: 1288


No I dont escrow anymore.


View Profile WWW
April 26, 2016, 05:37:58 PM
 #18

-snip-
my script get hash, amount etc.. but i need wallet of player.

There is no simple way to get the "sending address"[1]. You have to check the inputs, but more often than not there will be several inputs. Its better to let the user set an address you store in your database along with their other information.

Code:
txid = dc8697d1afd6c7ac2f667cd3239e19bf227a7b5ce8be64b2f8bb3c626979425b # "random" one from the block to the hash that Polyatomic posted.
raw_tx = getrawtransaction(txid)
decoded_tx = decoderawtransaction(raw_tx)

within decoded_tx you will find a "vin" section with a value "vout" and a txid. If you check each of the txids you will see that they have a "vout" section. The outputs that created the inputs that are used in the TX you received. Find the one where "vout" matches "n" and look up its address. In this example there are 4 inputs, all "from" the address "1NgrpJJj2PMj9RsHutVK7vf8dchcpfM4YZ", but you need to decide how you want to handle different addresses.

IIRC the data is mixed formatted, arrays within JSON, but that might be different for PHP.

[1] there is no such thing

ok. i will experience..

but how make it secondstrade.com ?

bet is send to address only. no need enter player wallet

AFAIK they do it in this crude way, same as most ponzi "games". If they warn you not to use certain wallets, they almost always just assume which is your address. This can fail horribly if your customer/user uses a wallet where they share addresses with others or use something like CoinJoin. A common example for shared wallets are most exchanges. You have your own deposit address, but when you withdraw the coins come from a different address. If you return coins to the address they came from they will be credited to a different account (if at all).

thanks for your answer sir.

i have problem get who send payment..

for example this hash:
3d919bf7929b983954e9c439348649e11ba21f8f740530aa4ecbbd3c5f496071

You are asking "who" but there is no such info on the blockchain. The inputs the TX uses have been received on two addresses, which is exactly what I warned you about. There is no right answer to this. Its possible that the sender controls both, one or none of the addresses the coins came "from".

a64020eea0719df9318e185d1a44cea8f9b5e872ced67e1e746fe1b9fbb6670c

who sent payment?
could you help me please

That one has a confirmed double spend -> https://blockchain.info/tx/3a07b7957cf29d267cd8c20fbd5eb8824366096e09d722d888ce635098851b70

The inputs the TXs use came from a single address '15iET5Zp3GdXkp2sbUvsenUysFCAzoW1Fq', but same here its possible that the person behind the coins controls it or not.
HackerBOSS
Full Member
***
Offline Offline

Activity: 210
Merit: 100


View Profile
April 27, 2016, 02:10:18 AM
 #19

-snip-
my script get hash, amount etc.. but i need wallet of player.

There is no simple way to get the "sending address"[1]. You have to check the inputs, but more often than not there will be several inputs. Its better to let the user set an address you store in your database along with their other information.

Code:
txid = dc8697d1afd6c7ac2f667cd3239e19bf227a7b5ce8be64b2f8bb3c626979425b # "random" one from the block to the hash that Polyatomic posted.
raw_tx = getrawtransaction(txid)
decoded_tx = decoderawtransaction(raw_tx)

within decoded_tx you will find a "vin" section with a value "vout" and a txid. If you check each of the txids you will see that they have a "vout" section. The outputs that created the inputs that are used in the TX you received. Find the one where "vout" matches "n" and look up its address. In this example there are 4 inputs, all "from" the address "1NgrpJJj2PMj9RsHutVK7vf8dchcpfM4YZ", but you need to decide how you want to handle different addresses.

IIRC the data is mixed formatted, arrays within JSON, but that might be different for PHP.

[1] there is no such thing

ok. i will experience..

but how make it secondstrade.com ?

bet is send to address only. no need enter player wallet

AFAIK they do it in this crude way, same as most ponzi "games". If they warn you not to use certain wallets, they almost always just assume which is your address. This can fail horribly if your customer/user uses a wallet where they share addresses with others or use something like CoinJoin. A common example for shared wallets are most exchanges. You have your own deposit address, but when you withdraw the coins come from a different address. If you return coins to the address they came from they will be credited to a different account (if at all).

thanks for your answer sir.

i have problem get who send payment..

for example this hash:
3d919bf7929b983954e9c439348649e11ba21f8f740530aa4ecbbd3c5f496071

You are asking "who" but there is no such info on the blockchain. The inputs the TX uses have been received on two addresses, which is exactly what I warned you about. There is no right answer to this. Its possible that the sender controls both, one or none of the addresses the coins came "from".

a64020eea0719df9318e185d1a44cea8f9b5e872ced67e1e746fe1b9fbb6670c

who sent payment?
could you help me please

That one has a confirmed double spend -> https://blockchain.info/tx/3a07b7957cf29d267cd8c20fbd5eb8824366096e09d722d888ce635098851b70

The inputs the TXs use came from a single address '15iET5Zp3GdXkp2sbUvsenUysFCAzoW1Fq', but same here its possible that the person behind the coins controls it or not.

how resolve this problem?
what function rpc-api need use?

i need know sender wallet for refund amount..

danda
Full Member
***
Offline Offline

Activity: 188
Merit: 126


View Profile WWW
April 27, 2016, 06:35:19 AM
 #20

If you potentially need to send refunds then the only correct way is to ask the user to provide a refund address at the time of payment.

The concept of a single guaranteed "from address" simply does not exist in bitcoin.

Quote
how resolve this problem?
what function rpc-api need use?

i need know sender wallet for refund amount..

mybitprices.info - wallet auditing tools
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!