Skip to content

Commit 05e5966

Browse files
furszyknst
authored andcommitted
partial Merge bitcoin#27920: wallet: bugfix, always use apostrophe for spkm descriptor ID
BACKPORT NOTICE It includes only this commit: 97a965d refactor: extract descriptor ID calculation from spkm GetID() This allows us to verify the descriptor ID on the descriptors unit tests in different software versions without requiring to use the entire DescriptorScriptPubKeyMan machinery. Note: The unit test changes are introduced after the bugfix commit but this commit + the unit test commit can be cherry-picked on top of the v25 branch to verify IDs correctness. IDs must be the same for v25 and after the bugfix commit.
1 parent f675fcb commit 05e5966

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/script/descriptor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,14 @@ std::unique_ptr<Descriptor> InferDescriptor(const CScript& script, const Signing
11621162
return InferScript(script, ParseScriptContext::TOP, provider);
11631163
}
11641164

1165+
uint256 DescriptorID(const Descriptor& desc)
1166+
{
1167+
std::string desc_str = desc.ToString();
1168+
uint256 id;
1169+
CSHA256().Write((unsigned char*)desc_str.data(), desc_str.size()).Finalize(id.begin());
1170+
return id;
1171+
}
1172+
11651173
void DescriptorCache::CacheParentExtPubKey(uint32_t key_exp_pos, const CExtPubKey& xpub)
11661174
{
11671175
m_parent_xpubs[key_exp_pos] = xpub;

src/script/descriptor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,9 @@ std::string GetDescriptorChecksum(const std::string& descriptor);
182182
*/
183183
std::unique_ptr<Descriptor> InferDescriptor(const CScript& script, const SigningProvider& provider);
184184

185+
/** Unique identifier that may not change over time, unless explicitly marked as not backwards compatible.
186+
* This is not part of BIP 380, not guaranteed to be interoperable and should not be exposed to the user.
187+
*/
188+
uint256 DescriptorID(const Descriptor& desc);
189+
185190
#endif // BITCOIN_SCRIPT_DESCRIPTOR_H

src/wallet/scriptpubkeyman.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,10 +2309,7 @@ std::unique_ptr<CKeyMetadata> DescriptorScriptPubKeyMan::GetMetadata(const CTxDe
23092309
uint256 DescriptorScriptPubKeyMan::GetID() const
23102310
{
23112311
LOCK(cs_desc_man);
2312-
std::string desc_str = m_wallet_descriptor.descriptor->ToString();
2313-
uint256 id;
2314-
CSHA256().Write((unsigned char*)desc_str.data(), desc_str.size()).Finalize(id.begin());
2315-
return id;
2312+
return DescriptorID(*m_wallet_descriptor.descriptor);
23162313
}
23172314

23182315
void DescriptorScriptPubKeyMan::SetInternal(bool internal)

0 commit comments

Comments
 (0)