From 97a965d98f1582ea1b1377bd258c9088380e1b8b Mon Sep 17 00:00:00 2001 From: furszy Date: Fri, 23 Jun 2023 11:32:28 -0300 Subject: 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. --- src/script/descriptor.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/script/descriptor.cpp') diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index b8ade1684a..2d10b5dd0f 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -1778,6 +1778,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; -- cgit v1.2.3