Skip to content

Commit

Permalink
descriptors: Move FlatSigningProvider pubkey filling to GetPubKey
Browse files Browse the repository at this point in the history
Instead of MakeScripts inconsistently filling the output
FlatSigningProvider with the pubkeys involved, just do it in GetPubKey.
  • Loading branch information
achow101 committed Nov 7, 2024
1 parent 4275855 commit 151fd9d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/script/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class OriginPubkeyProvider final : public PubkeyProvider
{
std::optional<CPubKey> 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);
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -884,7 +887,6 @@ class PKHDescriptor final : public DescriptorImpl
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, Span<const CScript>, FlatSigningProvider& out) const override
{
CKeyID id = keys[0].GetID();
out.pubkeys.emplace(id, keys[0]);
return Vector(GetScriptForDestination(PKHash(id)));
}
public:
Expand Down Expand Up @@ -918,7 +920,6 @@ class WPKHDescriptor final : public DescriptorImpl
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, Span<const CScript>, FlatSigningProvider& out) const override
{
CKeyID id = keys[0].GetID();
out.pubkeys.emplace(id, keys[0]);
return Vector(GetScriptForDestination(WitnessV0KeyHash(id)));
}
public:
Expand Down Expand Up @@ -953,7 +954,6 @@ class ComboDescriptor final : public DescriptorImpl
{
std::vector<CScript> 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()) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 151fd9d

Please sign in to comment.