diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 054d8de795..bc42d65e21 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -1162,6 +1162,14 @@ std::unique_ptr InferDescriptor(const CScript& script, const Signing return InferScript(script, ParseScriptContext::TOP, provider); } +uint256 DescriptorID(const Descriptor& desc) +{ + std::string desc_str = desc.ToString(); + uint256 id; + CSHA256().Write((unsigned char*)desc_str.data(), desc_str.size()).Finalize(id.begin()); + return id; +} + void DescriptorCache::CacheParentExtPubKey(uint32_t key_exp_pos, const CExtPubKey& xpub) { m_parent_xpubs[key_exp_pos] = xpub; diff --git a/src/script/descriptor.h b/src/script/descriptor.h index f5bbf487c6..c10329c484 100644 --- a/src/script/descriptor.h +++ b/src/script/descriptor.h @@ -182,4 +182,9 @@ std::string GetDescriptorChecksum(const std::string& descriptor); */ std::unique_ptr InferDescriptor(const CScript& script, const SigningProvider& provider); +/** Unique identifier that may not change over time, unless explicitly marked as not backwards compatible. +* This is not part of BIP 380, not guaranteed to be interoperable and should not be exposed to the user. +*/ +uint256 DescriptorID(const Descriptor& desc); + #endif // BITCOIN_SCRIPT_DESCRIPTOR_H diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index db8cee6b5b..a2646df64f 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -2309,10 +2309,7 @@ std::unique_ptr DescriptorScriptPubKeyMan::GetMetadata(const CTxDe uint256 DescriptorScriptPubKeyMan::GetID() const { LOCK(cs_desc_man); - std::string desc_str = m_wallet_descriptor.descriptor->ToString(); - uint256 id; - CSHA256().Write((unsigned char*)desc_str.data(), desc_str.size()).Finalize(id.begin()); - return id; + return DescriptorID(*m_wallet_descriptor.descriptor); } void DescriptorScriptPubKeyMan::SetInternal(bool internal)