diff options
author | Ava Chow <github@achow101.com> | 2024-02-02 14:17:02 -0500 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-02-16 14:36:10 -0500 |
commit | b410f68791143800968f4c628beda1c9f898b4f6 (patch) | |
tree | 1ed0d0e0dd5df406ed86a5286d19320bd554f047 /src/wallet/wallet.cpp | |
parent | edf4e73a163739a64eb9a54cd95413583a0e5c1f (diff) | |
download | bitcoin-b410f68791143800968f4c628beda1c9f898b4f6.tar.xz |
wallet: Use scriptPubKey cache in GetScriptPubKeyMans
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 0c61a9b3fa..e43243cb55 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3436,12 +3436,18 @@ ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const OutputType& type, bool intern std::set<ScriptPubKeyMan*> CWallet::GetScriptPubKeyMans(const CScript& script) const { std::set<ScriptPubKeyMan*> spk_mans; - SignatureData sigdata; - for (const auto& spk_man_pair : m_spk_managers) { - if (spk_man_pair.second->CanProvide(script, sigdata)) { - spk_mans.insert(spk_man_pair.second.get()); - } + + // Search the cache for relevant SPKMs instead of iterating m_spk_managers + const auto& it = m_cached_spks.find(script); + if (it != m_cached_spks.end()) { + spk_mans.insert(it->second.begin(), it->second.end()); } + SignatureData sigdata; + Assume(std::all_of(spk_mans.begin(), spk_mans.end(), [&script, &sigdata](ScriptPubKeyMan* spkm) { return spkm->CanProvide(script, sigdata); })); + + // Legacy wallet + if (IsLegacy() && GetLegacyScriptPubKeyMan()->CanProvide(script, sigdata)) spk_mans.insert(GetLegacyScriptPubKeyMan()); + return spk_mans; } |