2

I am looking for a filename and a line, or multiple ones if necessary. My goal is to maintain an index of addresses to UTXOs.

2

In the case of a fork, you have to Disconnect the blocks that are on the losing side of the fork, and then Connect the blocks on the winning side of the fork, in order. If you look at the CCoinsViewCache input into the function, you can see how the UTXO set is updated.

Essentially, though, you have to reverse the effects of all of the transactions in the losing blocks and apply the effects of the transactions in the new blocks. Reversing means processing inputs to mark STXOs as UTXOs and removing UTXOs created in the block. Processing new transactions into the UTXO set means, in addition to verifying the transactions are valid, you mark UTXOs spent by the inputs of transactions as STXOs (or remove them, depending on how your system works), and you create new UTXOs for the outputs in the block.

Keep in mind that you have apply these processes for each transaction in the block in order (or reverse order if Disconnecting a block), because transaction B can spend from outputs created in transaction A, where A & B are in the same block.


My goal is to maintain an index of addresses to UTXOs.

If I were you, I would keep an index of the scriptPubKey and then convert an address to the scriptPubKey you need when you need to do a lookup.

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.