Skip to content

Commit 39640dd

Browse files
committed
wallet: Use scriptPubKeyCache in GetSolvingProvider
1 parent b410f68 commit 39640dd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,11 +3467,17 @@ std::unique_ptr<SigningProvider> CWallet::GetSolvingProvider(const CScript& scri
34673467

34683468
std::unique_ptr<SigningProvider> CWallet::GetSolvingProvider(const CScript& script, SignatureData& sigdata) const
34693469
{
3470-
for (const auto& spk_man_pair : m_spk_managers) {
3471-
if (spk_man_pair.second->CanProvide(script, sigdata)) {
3472-
return spk_man_pair.second->GetSolvingProvider(script);
3473-
}
3470+
// Search the cache for relevant SPKMs instead of iterating m_spk_managers
3471+
const auto& it = m_cached_spks.find(script);
3472+
if (it != m_cached_spks.end()) {
3473+
// All spkms for a given script must already be able to make a SigningProvider for the script, so just return the first one.
3474+
Assume(it->second.at(0)->CanProvide(script, sigdata));
3475+
return it->second.at(0)->GetSolvingProvider(script);
34743476
}
3477+
3478+
// Legacy wallet
3479+
if (IsLegacy() && GetLegacyScriptPubKeyMan()->CanProvide(script, sigdata)) return GetLegacyScriptPubKeyMan()->GetSolvingProvider(script);
3480+
34753481
return nullptr;
34763482
}
34773483

0 commit comments

Comments
 (0)