Sorry for this naive question, but honestly it is going to be a great help for me. Say I am tracking a specific bitcoin transaction('TX_1') form bitcoin core. A confirmed block had the transaction information after I decoded the block, and I updated my database as : {transaction: 'TX_1', 'confirmation': 1} now how do I increment the number of confirmation, assuming I am still listening to the network through ZMQ. Should I expect the same transaction ('TX_1') to be present in upcoming blocks?
1 Answer
A tx will only be included in a single block in any given blockchain.
Confirmations is simply a count of how many new blocks extend the chain.
If your tx is in block n, it has 1 confirmation. When block n+1 is mined, you need to check that the prevblockhash is the hash of block n. If it is, you now have 2 confirmations, since the chain has been mined. When block n+2 is mined, you check the prevblockhash against the hash of block n+1. If this is valid, you now have 3 confirmations, since block n+1 builds upon the block with your tx, and block n+2 builds upon block n+1. You can keep checking this for as many blocks as you feel necessary to guarantee that your tx will not be dropped. Most wallets/exchanges check until a tx has 6 confirmations.