1

Is it possible to enumerate all blocks/transactions, in order, using bitcoind API? The listsinceblock call seems to return the transactions without any ordering so assuming I get a very long list, I cannot process half of it, store last processed block hash and later ask again for transaction since that block.

3

Yes there is a total order over all confirmed transactions, namely the order over all the blocks by blockchain height, and internally by the order in which transactions appear in the block message. This block-internal order by the way is the same order which is also used to calculate the merkle tree root.

I would suggest calling bitcoind getblockcount to get the blockchain height. Then use bitcoind getblockhash for each block from 0 to that blockcount to retrieve each block and then traverse the tx part of the result, which should give you the transactions in the order they appear in the serialized block form (which is agreed upon by all nodes). Whether you count the block before or after its transactions is a matter of taste, but I'd suggest counting it after the transactions as they had to exist before the block was found.

So if you want to stop the process somewhere, simply remember the height of the block you last processed and the number of transactions you processed for that block, and you'll be ready to continue right where you left off.

Notice that there is no way to enumerate non-confirmed transactions, and orphan blocks. This is due to the fact that there simply is no unique ordering among them, which all nodes in the network would agree upon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.