Skip to content

Commit 08d22b4

Browse files
committed
descriptors: Move FlatSigningProvider pubkey filling to GetPubKey
Instead of MakeScripts inconsistently filling the output FlatSigningProvider with the pubkeys involved, just do it in GetPubKey.
1 parent 070e746 commit 08d22b4

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/script/descriptor.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ class OriginPubkeyProvider final : public PubkeyProvider
242242
{
243243
std::optional<CPubKey> pub = m_provider->GetPubKey(pos, arg, out, read_cache, write_cache);
244244
if (!pub) return std::nullopt;
245+
Assert(out.pubkeys.contains(pub->GetID()));
245246
auto& [pubkey, suborigin] = out.origins[pub->GetID()];
246247
Assert(pubkey == *pub); // All subproviders must be inserting a valid origin already
247248
std::copy(std::begin(m_origin.fingerprint), std::end(m_origin.fingerprint), suborigin.fingerprint);
@@ -305,6 +306,7 @@ class ConstPubkeyProvider final : public PubkeyProvider
305306
CKeyID keyid = m_pubkey.GetID();
306307
std::copy(keyid.begin(), keyid.begin() + sizeof(info.fingerprint), info.fingerprint);
307308
out.origins.emplace(keyid, std::make_pair(m_pubkey, info));
309+
out.pubkeys.emplace(keyid, m_pubkey);
308310
return m_pubkey;
309311
}
310312
bool IsRange() const override { return false; }
@@ -442,6 +444,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider
442444
if (!der) return std::nullopt;
443445

444446
out.origins.emplace(final_extkey.pubkey.GetID(), std::make_pair(final_extkey.pubkey, info));
447+
out.pubkeys.emplace(final_extkey.pubkey.GetID(), final_extkey.pubkey);
445448

446449
if (write_cache) {
447450
// Only cache parent if there is any unhardened derivation
@@ -877,10 +880,9 @@ class PKDescriptor final : public DescriptorImpl
877880
class PKHDescriptor final : public DescriptorImpl
878881
{
879882
protected:
880-
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, Span<const CScript>, FlatSigningProvider& out) const override
883+
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, Span<const CScript>, FlatSigningProvider&) const override
881884
{
882885
CKeyID id = keys[0].GetID();
883-
out.pubkeys.emplace(id, keys[0]);
884886
return Vector(GetScriptForDestination(PKHash(id)));
885887
}
886888
public:
@@ -912,10 +914,9 @@ class PKHDescriptor final : public DescriptorImpl
912914
class WPKHDescriptor final : public DescriptorImpl
913915
{
914916
protected:
915-
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, Span<const CScript>, FlatSigningProvider& out) const override
917+
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, Span<const CScript>, FlatSigningProvider&) const override
916918
{
917919
CKeyID id = keys[0].GetID();
918-
out.pubkeys.emplace(id, keys[0]);
919920
return Vector(GetScriptForDestination(WitnessV0KeyHash(id)));
920921
}
921922
public:
@@ -951,7 +952,6 @@ class ComboDescriptor final : public DescriptorImpl
951952
{
952953
std::vector<CScript> ret;
953954
CKeyID id = keys[0].GetID();
954-
out.pubkeys.emplace(id, keys[0]);
955955
ret.emplace_back(GetScriptForRawPubKey(keys[0])); // P2PK
956956
ret.emplace_back(GetScriptForDestination(PKHash(id))); // P2PKH
957957
if (keys[0].IsCompressed()) {
@@ -1178,7 +1178,6 @@ class TRDescriptor final : public DescriptorImpl
11781178
builder.Finalize(xpk);
11791179
WitnessV1Taproot output = builder.GetOutput();
11801180
out.tr_trees[output] = builder;
1181-
out.pubkeys.emplace(keys[0].GetID(), keys[0]);
11821181
return Vector(GetScriptForDestination(output));
11831182
}
11841183
bool ToStringSubScriptHelper(const SigningProvider* arg, std::string& ret, const StringType type, const DescriptorCache* cache = nullptr) const override

0 commit comments

Comments
 (0)