0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

wallet: Use scriptPubKey cache in IsMine

This commit is contained in:
Ava Chow 2024-02-02 14:16:54 -05:00
parent 37232332bd
commit edf4e73a16

View file

@ -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