diff options
author | Andrew Chow <achow101-github@achow101.com> | 2020-02-24 15:09:15 -0500 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2020-03-07 10:13:43 -0500 |
commit | 474ea3b927ddc67e64ae78e08c20c9264817e84d (patch) | |
tree | 9df5a282c1556c87a807c389b811fbc83867bdf5 /src/script/descriptor.cpp | |
parent | c3b471592346b98ae9aedf7cbc2a4058061b1ad8 (diff) |
Introduce DescriptorCache struct which caches xpubs
Diffstat (limited to 'src/script/descriptor.cpp')
-rw-r--r-- | src/script/descriptor.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index b1d9a5bda7..f71e3b901f 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -1050,3 +1050,42 @@ std::unique_ptr<Descriptor> InferDescriptor(const CScript& script, const Signing { return InferScript(script, ParseScriptContext::TOP, provider); } + +void DescriptorCache::CacheParentExtPubKey(uint32_t key_exp_pos, const CExtPubKey& xpub) +{ + m_parent_xpubs[key_exp_pos] = xpub; +} + +void DescriptorCache::CacheDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, const CExtPubKey& xpub) +{ + auto& xpubs = m_derived_xpubs[key_exp_pos]; + xpubs[der_index] = xpub; +} + +bool DescriptorCache::GetCachedParentExtPubKey(uint32_t key_exp_pos, CExtPubKey& xpub) const +{ + const auto& it = m_parent_xpubs.find(key_exp_pos); + if (it == m_parent_xpubs.end()) return false; + xpub = it->second; + return true; +} + +bool DescriptorCache::GetCachedDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, CExtPubKey& xpub) const +{ + const auto& key_exp_it = m_derived_xpubs.find(key_exp_pos); + if (key_exp_it == m_derived_xpubs.end()) return false; + const auto& der_it = key_exp_it->second.find(der_index); + if (der_it == key_exp_it->second.end()) return false; + xpub = der_it->second; + return true; +} + +const ExtPubKeyMap DescriptorCache::GetCachedParentExtPubKeys() const +{ + return m_parent_xpubs; +} + +const std::unordered_map<uint32_t, ExtPubKeyMap> DescriptorCache::GetCachedDerivedExtPubKeys() const +{ + return m_derived_xpubs; +} |