aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2024-02-02 14:16:54 -0500
committerAva Chow <github@achow101.com>2024-02-16 14:36:10 -0500
commitedf4e73a163739a64eb9a54cd95413583a0e5c1f (patch)
treed4edc5aa8ca3cb390d251ffcf9309738e8f87511 /src/wallet/wallet.cpp
parent37232332bd7253422ea92a8c9eeb36b12fc84b56 (diff)
downloadbitcoin-edf4e73a163739a64eb9a54cd95413583a0e5c1f.tar.xz
wallet: Use scriptPubKey cache in IsMine
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index a416276d05..0c61a9b3fa 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1571,11 +1571,22 @@ isminetype CWallet::IsMine(const CTxDestination& dest) const
isminetype CWallet::IsMine(const CScript& script) const
{
AssertLockHeld(cs_wallet);
- isminetype result = ISMINE_NO;
- for (const auto& spk_man_pair : m_spk_managers) {
- result = std::max(result, spk_man_pair.second->IsMine(script));
+
+ // Search the cache so that IsMine is called only on the relevant SPKMs instead of on everything in m_spk_managers
+ const auto& it = m_cached_spks.find(script);
+ if (it != m_cached_spks.end()) {
+ isminetype res = ISMINE_NO;
+ for (const auto& spkm : it->second) {
+ res = std::max(res, spkm->IsMine(script));
+ }
+ Assume(res == ISMINE_SPENDABLE);
+ return res;
}
- return result;
+
+ // Legacy wallet
+ if (IsLegacy()) return GetLegacyScriptPubKeyMan()->IsMine(script);
+
+ return ISMINE_NO;
}
bool CWallet::IsMine(const CTransaction& tx) const