How do I know one transaction has confirmed?

1

I am running my bitcoind with -zmqpubhashtx optional, and I receive notification once a new transaction has broadcast to public chain! I can also parser it by getrawtransaction and decoderawtransaction. But I couldn't validated if a transaction is confirmed.

Additionally, there are also exists an optional name as -zmqpubhashblock, I can also parser it by getblock and read its all transactions, compare it all with my MySQL data, if it's exists with the same txid, I'll update my column (confirmations to plus one), but it's a little bit ineffective.

Let's say, After I ran getblock <hash>, and then give me a tons of transaction. and I have to check each something like:

UPDATE t_unspent_tx
SET confirmations = confirmations + 1
WHERE addr in (addresses)    

BTW, Can I trust the block hash from notification? Is it may not be the longest on the chain?

PS, I don't want to check confirmation from the blockchain.info or some other site else.

Frank AK

Posted 2018-08-01T08:12:21.050

Reputation: 141

Answers

1

If you have txindex=1, you can call getrawtransaction <txid> 1 to receive a decoded tx object, which will include the number of confirmations and the blockhash.

Raghav Sood

Posted 2018-08-01T08:12:21.050

Reputation: 10 897

Oh! I am definitely sure there is no confirmations after you decode the hex, which get by getrawtransaction.Frank AK 2018-08-01T09:07:53.503

Seems to work on chainquery. What version of Bitcoin are you running?Raghav Sood 2018-08-01T09:10:38.730

I am using the V0.16.1 version. The link that you given should be processed.Frank AK 2018-08-01T09:13:18.947

It also seems to be in the source. Not sure why it won't show up on your local node. Are you sure you're using getrawtransaction, and not decoderawtransaction?Raghav Sood 2018-08-01T09:21:07.580

Oh! getrawtransaction only return me a hash, and I have to use decoderawtransaction to parser it.Frank AK 2018-08-01T09:22:34.960

getrawtransaction has a verbose mode, as described in my answer, use that insteadRaghav Sood 2018-08-01T09:23:08.503