Transaction tracking

When we learn about a new block the BlockConnected signal is fired after successful validation. This prompts the wallet to iterate all inputs and outputs, calling IsMine() on all of them. As part of the check, we loop over the wallet’s scriptPubkeyMans to check if any of the scripts belong to us.

If a script does belong to us, it will be inserted into mapWallet along with some metadata related to the time. mapWallet contains all the transactions the wallet is interested in, including received and sent transactions.

When we load a wallet into memory, we iterate all TxSpends. TxSpends stores wallet transactions which were already spent and confirmed.

Therefore, when the wallet needs to select coins to spend, it can select from the coins:

mapWallet - TxSpends - notMine