Skip to content

Commit 456e350

Browse files
committed
wallet: resolve ambiguity of two ScriptPubKey managers providing same script
1 parent 69a66dc commit 456e350

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3982,8 +3982,12 @@ RPCHelpMan getaddressinfo()
39823982
ret.pushKV("solvable", false);
39833983
}
39843984

3985+
const auto& spk_mans = pwallet->GetScriptPubKeyMans(scriptPubKey);
3986+
// In most cases there is only one matching ScriptPubKey manager and we can't resolve ambiguity in a better way
3987+
ScriptPubKeyMan* spk_man{nullptr};
3988+
if (spk_mans.size()) spk_man = *spk_mans.begin();
39853989

3986-
DescriptorScriptPubKeyMan* desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(pwallet->GetScriptPubKeyMan(scriptPubKey));
3990+
DescriptorScriptPubKeyMan* desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
39873991
if (desc_spk_man) {
39883992
std::string desc_str;
39893993
if (desc_spk_man->GetDescriptorString(desc_str, /* priv */ false)) {
@@ -3998,7 +4002,6 @@ RPCHelpMan getaddressinfo()
39984002

39994003
ret.pushKV("ischange", ScriptIsChange(*pwallet, scriptPubKey));
40004004

4001-
ScriptPubKeyMan* spk_man = pwallet->GetScriptPubKeyMan(scriptPubKey);
40024005
if (spk_man) {
40034006
if (const std::unique_ptr<CKeyMetadata> meta = spk_man->GetMetadata(dest)) {
40044007
ret.pushKV("timestamp", meta->nCreateTime);

src/wallet/wallet.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,16 +2253,15 @@ void ReserveDestination::ReturnDestination()
22532253
bool CWallet::DisplayAddress(const CTxDestination& dest)
22542254
{
22552255
CScript scriptPubKey = GetScriptForDestination(dest);
2256-
const auto spk_man = GetScriptPubKeyMan(scriptPubKey);
2257-
if (spk_man == nullptr) {
2258-
return false;
2259-
}
2260-
auto signer_spk_man = dynamic_cast<ExternalSignerScriptPubKeyMan*>(spk_man);
2261-
if (signer_spk_man == nullptr) {
2262-
return false;
2256+
for (const auto& spk_man : GetScriptPubKeyMans(scriptPubKey)) {
2257+
auto signer_spk_man = dynamic_cast<ExternalSignerScriptPubKeyMan *>(spk_man);
2258+
if (signer_spk_man == nullptr) {
2259+
continue;
2260+
}
2261+
ExternalSigner signer = ExternalSignerScriptPubKeyMan::GetExternalSigner();
2262+
return signer_spk_man->DisplayAddress(scriptPubKey, signer);
22632263
}
2264-
ExternalSigner signer = ExternalSignerScriptPubKeyMan::GetExternalSigner();
2265-
return signer_spk_man->DisplayAddress(scriptPubKey, signer);
2264+
return false;
22662265
}
22672266

22682267
bool CWallet::LockCoin(const COutPoint& output, WalletBatch* batch)
@@ -3035,9 +3034,10 @@ ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const OutputType& type, bool intern
30353034
return it->second;
30363035
}
30373036

3038-
std::set<ScriptPubKeyMan*> CWallet::GetScriptPubKeyMans(const CScript& script, SignatureData& sigdata) const
3037+
std::set<ScriptPubKeyMan*> CWallet::GetScriptPubKeyMans(const CScript& script) const
30393038
{
30403039
std::set<ScriptPubKeyMan*> spk_mans;
3040+
SignatureData sigdata;
30413041
for (const auto& spk_man_pair : m_spk_managers) {
30423042
if (spk_man_pair.second->CanProvide(script, sigdata)) {
30433043
spk_mans.insert(spk_man_pair.second.get());
@@ -3046,17 +3046,6 @@ std::set<ScriptPubKeyMan*> CWallet::GetScriptPubKeyMans(const CScript& script, S
30463046
return spk_mans;
30473047
}
30483048

3049-
ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const CScript& script) const
3050-
{
3051-
SignatureData sigdata;
3052-
for (const auto& spk_man_pair : m_spk_managers) {
3053-
if (spk_man_pair.second->CanProvide(script, sigdata)) {
3054-
return spk_man_pair.second.get();
3055-
}
3056-
}
3057-
return nullptr;
3058-
}
3059-
30603049
ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const uint256& id) const
30613050
{
30623051
if (m_spk_managers.count(id) > 0) {

src/wallet/wallet.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -805,14 +805,11 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
805805
//! Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
806806
ScriptPubKeyMan* GetScriptPubKeyMan(const OutputType& type, bool internal) const;
807807

808-
//! Get the ScriptPubKeyMan for a script
809-
ScriptPubKeyMan* GetScriptPubKeyMan(const CScript& script) const;
808+
//! Get all the ScriptPubKeyMans for a script
809+
std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script) const;
810810
//! Get the ScriptPubKeyMan by id
811811
ScriptPubKeyMan* GetScriptPubKeyMan(const uint256& id) const;
812812

813-
//! Get all of the ScriptPubKeyMans for a script given additional information in sigdata (populated by e.g. a psbt)
814-
std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script, SignatureData& sigdata) const;
815-
816813
//! Get the SigningProvider for a script
817814
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const;
818815
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const;

0 commit comments

Comments
 (0)