Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
3001std::vector<std::unique_ptr<Descriptor>> descs;3002descs.reserve(ret.size());3003for (auto& r : ret) {3004descs.emplace_back(std::unique_ptr<Descriptor>(std::move(r)));3005}3006return descs;3007}3008return {};3009}3011std::string GetDescriptorChecksum(const std::string& descriptor)3012{3013std::string ret;3014std::string error;3015std::span<const char> sp{descriptor};3016if (!CheckChecksum(sp, false, error, &ret)) return "";3017return ret;3018}3020std::unique_ptr<Descriptor> InferDescriptor(const CScript& script, const SigningProvider& provider)3021{3022return InferScript(script, ParseScriptContext::TOP, provider);3023}3025uint256 CompatDescriptorHash(const Descriptor& desc)3026{3027std::string desc_str = desc.ToString(/*compat_format=*/true);3028uint256 id;3029CSHA256().Write((unsigned char*)desc_str.data(), desc_str.size()).Finalize(id.begin());3030return id;3031}3033void DescriptorCache::CacheParentExtPubKey(uint32_t key_exp_pos, const CExtPubKey& xpub)3034{3035m_parent_xpubs[key_exp_pos] = xpub;3036}3038void DescriptorCache::CacheDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, const CExtPubKey& xpub)3039{3040auto& xpubs = m_derived_xpubs[key_exp_pos];3041xpubs[der_index] = xpub;3042}3044void DescriptorCache::CacheLastHardenedExtPubKey(uint32_t key_exp_pos, const CExtPubKey& xpub)3045{3046m_last_hardened_xpubs[key_exp_pos] = xpub;3047}3049bool DescriptorCache::GetCachedParentExtPubKey(uint32_t key_exp_pos, CExtPubKey& xpub) const3050{3051const auto& it = m_parent_xpubs.find(key_exp_pos);3052if (it == m_parent_xpubs.end()) return false;3053xpub = it->second;3054return true;3055}3057bool DescriptorCache::GetCachedDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, CExtPubKey& xpub) const3058{3059const auto& key_exp_it = m_derived_xpubs.find(key_exp_pos);3060if (key_exp_it == m_derived_xpubs.end()) return false;3061const auto& der_it = key_exp_it->second.find(der_index);3062if (der_it == key_exp_it->second.end()) return false;3063xpub = der_it->second;3064return true;3065}3067bool DescriptorCache::GetCachedLastHardenedExtPubKey(uint32_t key_exp_pos, CExtPubKey& xpub) const3068{3069const auto& it = m_last_hardened_xpubs.find(key_exp_pos);3070if (it == m_last_hardened_xpubs.end()) return false;3071xpub = it->second;3072return true;3073}3075DescriptorCache DescriptorCache::MergeAndDiff(const DescriptorCache& other)3076{3077DescriptorCache diff;3078for (const auto& parent_xpub_pair : other.GetCachedParentExtPubKeys()) {3079CExtPubKey xpub;3080if (GetCachedParentExtPubKey(parent_xpub_pair.first, xpub)) {3081if (xpub != parent_xpub_pair.second) {3082throw std::runtime_error(std::string(__func__) + ": New cached parent xpub does not match already cached parent xpub");3083}3084continue;3085}3086CacheParentExtPubKey(parent_xpub_pair.first, parent_xpub_pair.second);3087diff.CacheParentExtPubKey(parent_xpub_pair.first, parent_xpub_pair.second);3088}3089for (const auto& derived_xpub_map_pair : other.GetCachedDerivedExtPubKeys()) {3090for (const auto& derived_xpub_pair : derived_xpub_map_pair.second) {3091CExtPubKey xpub;3092if (GetCachedDerivedExtPubKey(derived_xpub_map_pair.first, derived_xpub_pair.first, xpub)) {3093if (xpub != derived_xpub_pair.second) {3094throw std::runtime_error(std::string(__func__) + ": New cached derived xpub does not match already cached derived xpub");3095}3096continue;3097}3098CacheDerivedExtPubKey(derived_xpub_map_pair.first, derived_xpub_pair.first, derived_xpub_pair.second);3099diff.CacheDerivedExtPubKey(derived_xpub_map_pair.first, derived_xpub_pair.first, derived_xpub_pair.second);3100}3101}3102for (const auto& lh_xpub_pair : other.GetCachedLastHardenedExtPubKeys()) {3103CExtPubKey xpub;3104if (GetCachedLastHardenedExtPubKey(lh_xpub_pair.first, xpub)) {3105if (xpub != lh_xpub_pair.second) {3106throw std::runtime_error(std::string(__func__) + ": New cached last hardened xpub does not match already cached last hardened xpub");3107}3108continue;3109}3110CacheLastHardenedExtPubKey(lh_xpub_pair.first, lh_xpub_pair.second);3111diff.CacheLastHardenedExtPubKey(lh_xpub_pair.first, lh_xpub_pair.second);3112}3113return diff;3114}3116ExtPubKeyMap DescriptorCache::GetCachedParentExtPubKeys() const3117{3118return m_parent_xpubs;3119}3121std::unordered_map<uint32_t, ExtPubKeyMap> DescriptorCache::GetCachedDerivedExtPubKeys() const3122{3123return m_derived_xpubs;3124}3126ExtPubKeyMap DescriptorCache::GetCachedLastHardenedExtPubKeys() const3127{3128return m_last_hardened_xpubs;3129}