Skip to content

Commit 4b03031

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 25a3b9b commit 4b03031

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/script/descriptor.cpp

Lines changed: 5 additions & 6 deletions
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); // m_provider must have a valid origin by this point.
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; }
@@ -439,6 +441,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider
439441
if (!der) return std::nullopt;
440442

441443
out.origins.emplace(final_extkey.pubkey.GetID(), std::make_pair(final_extkey.pubkey, info));
444+
out.pubkeys.emplace(final_extkey.pubkey.GetID(), final_extkey.pubkey);
442445

443446
if (write_cache) {
444447
// Only cache parent if there is any unhardened derivation
@@ -874,10 +877,9 @@ class PKDescriptor final : public DescriptorImpl
874877
class PKHDescriptor final : public DescriptorImpl
875878
{
876879
protected:
877-
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, std::span<const CScript>, FlatSigningProvider& out) const override
880+
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, std::span<const CScript>, FlatSigningProvider&) const override
878881
{
879882
CKeyID id = keys[0].GetID();
880-
out.pubkeys.emplace(id, keys[0]);
881883
return Vector(GetScriptForDestination(PKHash(id)));
882884
}
883885
public:
@@ -909,10 +911,9 @@ class PKHDescriptor final : public DescriptorImpl
909911
class WPKHDescriptor final : public DescriptorImpl
910912
{
911913
protected:
912-
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, std::span<const CScript>, FlatSigningProvider& out) const override
914+
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, std::span<const CScript>, FlatSigningProvider&) const override
913915
{
914916
CKeyID id = keys[0].GetID();
915-
out.pubkeys.emplace(id, keys[0]);
916917
return Vector(GetScriptForDestination(WitnessV0KeyHash(id)));
917918
}
918919
public:
@@ -948,7 +949,6 @@ class ComboDescriptor final : public DescriptorImpl
948949
{
949950
std::vector<CScript> ret;
950951
CKeyID id = keys[0].GetID();
951-
out.pubkeys.emplace(id, keys[0]);
952952
ret.emplace_back(GetScriptForRawPubKey(keys[0])); // P2PK
953953
ret.emplace_back(GetScriptForDestination(PKHash(id))); // P2PKH
954954
if (keys[0].IsCompressed()) {
@@ -1175,7 +1175,6 @@ class TRDescriptor final : public DescriptorImpl
11751175
builder.Finalize(xpk);
11761176
WitnessV1Taproot output = builder.GetOutput();
11771177
out.tr_trees[output] = builder;
1178-
out.pubkeys.emplace(keys[0].GetID(), keys[0]);
11791178
return Vector(GetScriptForDestination(output));
11801179
}
11811180
bool ToStringSubScriptHelper(const SigningProvider* arg, std::string& ret, const StringType type, const DescriptorCache* cache = nullptr) const override

0 commit comments

Comments
 (0)