mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
wallet: resolve ambiguity of two ScriptPubKey managers providing same script
This commit is contained in:
parent
69a66dcd0d
commit
456e350926
3 changed files with 17 additions and 28 deletions
|
@ -3982,8 +3982,12 @@ RPCHelpMan getaddressinfo()
|
|||
ret.pushKV("solvable", false);
|
||||
}
|
||||
|
||||
const auto& spk_mans = pwallet->GetScriptPubKeyMans(scriptPubKey);
|
||||
// In most cases there is only one matching ScriptPubKey manager and we can't resolve ambiguity in a better way
|
||||
ScriptPubKeyMan* spk_man{nullptr};
|
||||
if (spk_mans.size()) spk_man = *spk_mans.begin();
|
||||
|
||||
DescriptorScriptPubKeyMan* desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(pwallet->GetScriptPubKeyMan(scriptPubKey));
|
||||
DescriptorScriptPubKeyMan* desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
|
||||
if (desc_spk_man) {
|
||||
std::string desc_str;
|
||||
if (desc_spk_man->GetDescriptorString(desc_str, /* priv */ false)) {
|
||||
|
@ -3998,7 +4002,6 @@ RPCHelpMan getaddressinfo()
|
|||
|
||||
ret.pushKV("ischange", ScriptIsChange(*pwallet, scriptPubKey));
|
||||
|
||||
ScriptPubKeyMan* spk_man = pwallet->GetScriptPubKeyMan(scriptPubKey);
|
||||
if (spk_man) {
|
||||
if (const std::unique_ptr<CKeyMetadata> meta = spk_man->GetMetadata(dest)) {
|
||||
ret.pushKV("timestamp", meta->nCreateTime);
|
||||
|
|
|
@ -2253,16 +2253,15 @@ void ReserveDestination::ReturnDestination()
|
|||
bool CWallet::DisplayAddress(const CTxDestination& dest)
|
||||
{
|
||||
CScript scriptPubKey = GetScriptForDestination(dest);
|
||||
const auto spk_man = GetScriptPubKeyMan(scriptPubKey);
|
||||
if (spk_man == nullptr) {
|
||||
return false;
|
||||
for (const auto& spk_man : GetScriptPubKeyMans(scriptPubKey)) {
|
||||
auto signer_spk_man = dynamic_cast<ExternalSignerScriptPubKeyMan *>(spk_man);
|
||||
if (signer_spk_man == nullptr) {
|
||||
continue;
|
||||
}
|
||||
ExternalSigner signer = ExternalSignerScriptPubKeyMan::GetExternalSigner();
|
||||
return signer_spk_man->DisplayAddress(scriptPubKey, signer);
|
||||
}
|
||||
auto signer_spk_man = dynamic_cast<ExternalSignerScriptPubKeyMan*>(spk_man);
|
||||
if (signer_spk_man == nullptr) {
|
||||
return false;
|
||||
}
|
||||
ExternalSigner signer = ExternalSignerScriptPubKeyMan::GetExternalSigner();
|
||||
return signer_spk_man->DisplayAddress(scriptPubKey, signer);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CWallet::LockCoin(const COutPoint& output, WalletBatch* batch)
|
||||
|
@ -3035,9 +3034,10 @@ ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const OutputType& type, bool intern
|
|||
return it->second;
|
||||
}
|
||||
|
||||
std::set<ScriptPubKeyMan*> CWallet::GetScriptPubKeyMans(const CScript& script, SignatureData& sigdata) const
|
||||
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());
|
||||
|
@ -3046,17 +3046,6 @@ std::set<ScriptPubKeyMan*> CWallet::GetScriptPubKeyMans(const CScript& script, S
|
|||
return spk_mans;
|
||||
}
|
||||
|
||||
ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const CScript& script) const
|
||||
{
|
||||
SignatureData sigdata;
|
||||
for (const auto& spk_man_pair : m_spk_managers) {
|
||||
if (spk_man_pair.second->CanProvide(script, sigdata)) {
|
||||
return spk_man_pair.second.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const uint256& id) const
|
||||
{
|
||||
if (m_spk_managers.count(id) > 0) {
|
||||
|
|
|
@ -805,14 +805,11 @@ public:
|
|||
//! Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
|
||||
ScriptPubKeyMan* GetScriptPubKeyMan(const OutputType& type, bool internal) const;
|
||||
|
||||
//! Get the ScriptPubKeyMan for a script
|
||||
ScriptPubKeyMan* GetScriptPubKeyMan(const CScript& script) const;
|
||||
//! Get all the ScriptPubKeyMans for a script
|
||||
std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script) const;
|
||||
//! Get the ScriptPubKeyMan by id
|
||||
ScriptPubKeyMan* GetScriptPubKeyMan(const uint256& id) const;
|
||||
|
||||
//! Get all of the ScriptPubKeyMans for a script given additional information in sigdata (populated by e.g. a psbt)
|
||||
std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script, SignatureData& sigdata) const;
|
||||
|
||||
//! Get the SigningProvider for a script
|
||||
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const;
|
||||
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const;
|
||||
|
|
Loading…
Reference in a new issue