Skip to content

Commit b410f68

Browse files
committed
wallet: Use scriptPubKey cache in GetScriptPubKeyMans
1 parent edf4e73 commit b410f68

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/wallet/wallet.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,12 +3436,18 @@ ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const OutputType& type, bool intern
34363436
std::set<ScriptPubKeyMan*> CWallet::GetScriptPubKeyMans(const CScript& script) const
34373437
{
34383438
std::set<ScriptPubKeyMan*> spk_mans;
3439-
SignatureData sigdata;
3440-
for (const auto& spk_man_pair : m_spk_managers) {
3441-
if (spk_man_pair.second->CanProvide(script, sigdata)) {
3442-
spk_mans.insert(spk_man_pair.second.get());
3443-
}
3439+
3440+
// Search the cache for relevant SPKMs instead of iterating m_spk_managers
3441+
const auto& it = m_cached_spks.find(script);
3442+
if (it != m_cached_spks.end()) {
3443+
spk_mans.insert(it->second.begin(), it->second.end());
34443444
}
3445+
SignatureData sigdata;
3446+
Assume(std::all_of(spk_mans.begin(), spk_mans.end(), [&script, &sigdata](ScriptPubKeyMan* spkm) { return spkm->CanProvide(script, sigdata); }));
3447+
3448+
// Legacy wallet
3449+
if (IsLegacy() && GetLegacyScriptPubKeyMan()->CanProvide(script, sigdata)) spk_mans.insert(GetLegacyScriptPubKeyMan());
3450+
34453451
return spk_mans;
34463452
}
34473453

0 commit comments

Comments
 (0)