diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index acfe0c0594852f..70294629670b02 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -242,6 +242,7 @@ class OriginPubkeyProvider final : public PubkeyProvider { std::optional pub = m_provider->GetPubKey(pos, arg, out, read_cache, write_cache); if (!pub) return std::nullopt; + Assert(out.pubkeys.contains(pub->GetID())); auto& [pubkey, suborigin] = out.origins[pub->GetID()]; Assert(pubkey == *pub); // All subproviders must be inserting a valid origin already std::copy(std::begin(m_origin.fingerprint), std::end(m_origin.fingerprint), suborigin.fingerprint); @@ -305,6 +306,7 @@ class ConstPubkeyProvider final : public PubkeyProvider CKeyID keyid = m_pubkey.GetID(); std::copy(keyid.begin(), keyid.begin() + sizeof(info.fingerprint), info.fingerprint); out.origins.emplace(keyid, std::make_pair(m_pubkey, info)); + out.pubkeys.emplace(keyid, m_pubkey); return m_pubkey; } bool IsRange() const override { return false; } @@ -449,6 +451,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider if (!der) return std::nullopt; out.origins.emplace(final_extkey.pubkey.GetID(), std::make_pair(final_extkey.pubkey, info)); + out.pubkeys.emplace(final_extkey.pubkey.GetID(), final_extkey.pubkey); if (write_cache) { // Only cache parent if there is any unhardened derivation @@ -884,7 +887,6 @@ class PKHDescriptor final : public DescriptorImpl std::vector MakeScripts(const std::vector& keys, Span, FlatSigningProvider& out) const override { CKeyID id = keys[0].GetID(); - out.pubkeys.emplace(id, keys[0]); return Vector(GetScriptForDestination(PKHash(id))); } public: @@ -918,7 +920,6 @@ class WPKHDescriptor final : public DescriptorImpl std::vector MakeScripts(const std::vector& keys, Span, FlatSigningProvider& out) const override { CKeyID id = keys[0].GetID(); - out.pubkeys.emplace(id, keys[0]); return Vector(GetScriptForDestination(WitnessV0KeyHash(id))); } public: @@ -953,7 +954,6 @@ class ComboDescriptor final : public DescriptorImpl { std::vector ret; CKeyID id = keys[0].GetID(); - out.pubkeys.emplace(id, keys[0]); ret.emplace_back(GetScriptForRawPubKey(keys[0])); // P2PK ret.emplace_back(GetScriptForDestination(PKHash(id))); // P2PKH if (keys[0].IsCompressed()) { @@ -1175,7 +1175,6 @@ class TRDescriptor final : public DescriptorImpl builder.Finalize(xpk); WitnessV1Taproot output = builder.GetOutput(); out.tr_trees[output] = builder; - out.pubkeys.emplace(keys[0].GetID(), keys[0]); return Vector(GetScriptForDestination(output)); } bool ToStringSubScriptHelper(const SigningProvider* arg, std::string& ret, const StringType type, const DescriptorCache* cache = nullptr) const override