I'm writing a system where some transactions have to be automatically detected, and wait for 30 blocks to ensure they're confirmed. What I do is that I read all new blocks, and find the transactions that belong to my addresses.
I'm using geth
with getBlockByNumber
RPC call, and then when I find a transaction that belongs to me, I put it in a mempool and wait for 30 blocks to pass, and then consider the transaction final.
The question: How can I detect cancelled transactions to prevent double-spending?
I can imagine a situation where a block becomes orphaned and/or canceled in some way. Before considering the transaction final, how can I check that the transaction is still valid and wasn't canceled in some way?
Is it sufficient to just check the same block (by number) before considering the transaction final, and check that the transaction is still there? Are there other scenarios that I have to worry about? (uncle blocks, etc.) How can I check this systematically?