From b65c19e559e2fec511f40a4d5481bcf6a35c311c Mon Sep 17 00:00:00 2001 From: Bitflash Date: Sat, 1 Aug 2026 14:48:27 -0300 Subject: wallet: walk the chain for coins a key owns but the wallet never saw (#88) A transaction only entered the wallet when its block arrived over the network, so a key added afterwards was invisible: coins on the chain, private key in wallet.dat, balance zero. /importwallet has always ended that way -- it writes the keys and the money never shows up, which looks exactly like a failed import. ScanForWalletTransactions walks the main chain and hands every transaction that IsMine() to AddToWalletIfMine, the same two primitives the live path uses. Wired into /importwallet, and offered as /rescan. It is also the half that any recovery-phrase feature has to stand on: deriving keys from twelve words is easy, and without this a restore restores nothing. --- src/main.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/main.h') diff --git a/src/main.h b/src/main.h index 1d9efac..8d9b7e6 100644 --- a/src/main.h +++ b/src/main.h @@ -152,6 +152,11 @@ void TopUpKeyPool(); vector GetKeyFromPool(); bool AddToWallet(const CWalletTx& wtxIn); void ReacceptWalletTransactions(); +// Walk the chain from pindexStart forward, adding every transaction that pays +// a key this wallet holds. Returns how many were added or updated. Needed by +// anything that puts a key into the wallet after the fact -- an import, a +// restored backup, and later a recovery phrase. +int ScanForWalletTransactions(CBlockIndex* pindexStart); // Returns how many wallet transactions the chain corrected. int RescanSpentFlags(); void RelayWalletTransactions(); -- cgit v1.2.3