Skip to content

Commit 96e7a89

Browse files
committed
wallet: Recalculate the wallet's txos after any imports
1 parent ae888c3 commit 96e7a89

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

src/wallet/rpc/addresses.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ RPCHelpMan keypoolrefill()
250250
if (pwallet->GetKeyPoolSize() < kpSize) {
251251
throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
252252
}
253+
pwallet->RefreshAllTXOs();
253254

254255
return UniValue::VNULL;
255256
},

src/wallet/rpc/backup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ RPCHelpMan importdescriptors()
394394
}
395395
}
396396
pwallet->ConnectScriptPubKeyManNotifiers();
397+
pwallet->RefreshAllTXOs();
397398
}
398399

399400
// Rescan the blockchain using the lowest timestamp

src/wallet/wallet.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4451,4 +4451,12 @@ void CWallet::RefreshTXOsFromTx(const CWalletTx& wtx)
44514451
}
44524452
}
44534453
}
4454+
4455+
void CWallet::RefreshAllTXOs()
4456+
{
4457+
AssertLockHeld(cs_wallet);
4458+
for (const auto& [_, wtx] : mapWallet) {
4459+
RefreshTXOsFromTx(wtx);
4460+
}
4461+
}
44544462
} // namespace wallet

src/wallet/wallet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
525525

526526
/** Cache outputs that belong to the wallet from a single transaction */
527527
void RefreshTXOsFromTx(const CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
528+
/** Cache outputs that belong to the wallet for all transactions in the wallet */
529+
void RefreshAllTXOs() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
528530

529531
/**
530532
* Return depth of transaction in blockchain:

0 commit comments

Comments
 (0)