Skip to content

Commit a917478

Browse files
committed
refactor: move population of out.scripts from ExpandHelper to MakeScripts
There are currently two DescriptorImpl subclasses that rely on the functionality that ExpandHelper automatically adds subscripts to the output SigningProvider. Taproot descriptors will have subscripts, but we don't want them in the SigningProvider's bare script field. To avoid them ending up there, move this functionality into the specific classes' MakeScripts implementation.
1 parent 84f3939 commit a917478

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/script/descriptor.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ class DescriptorImpl : public Descriptor
497497
* @param pubkeys The evaluations of the m_pubkey_args field.
498498
* @param script The evaluation of m_subdescriptor_arg (or nullptr when m_subdescriptor_arg is nullptr).
499499
* @param out A FlatSigningProvider to put scripts or public keys in that are necessary to the solver.
500-
* The script arguments to this function are automatically added, as is the origin info of the provided pubkeys.
500+
* The origin info of the provided pubkeys is automatically added.
501501
* @return A vector with scriptPubKeys for this descriptor.
502502
*/
503503
virtual std::vector<CScript> MakeScripts(const std::vector<CPubKey>& pubkeys, const CScript* script, FlatSigningProvider& out) const = 0;
@@ -597,7 +597,6 @@ class DescriptorImpl : public Descriptor
597597
out.origins.emplace(entry.first.GetID(), std::make_pair<CPubKey, KeyOriginInfo>(CPubKey(entry.first), std::move(entry.second)));
598598
}
599599
if (m_subdescriptor_arg) {
600-
out.scripts.emplace(CScriptID(subscripts[0]), subscripts[0]);
601600
output_scripts = MakeScripts(pubkeys, &subscripts[0], out);
602601
} else {
603602
output_scripts = MakeScripts(pubkeys, nullptr, out);
@@ -776,7 +775,12 @@ class MultisigDescriptor final : public DescriptorImpl
776775
class SHDescriptor final : public DescriptorImpl
777776
{
778777
protected:
779-
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Vector(GetScriptForDestination(ScriptHash(*script))); }
778+
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider& out) const override
779+
{
780+
auto ret = Vector(GetScriptForDestination(ScriptHash(*script)));
781+
if (ret.size()) out.scripts.emplace(CScriptID(*script), *script);
782+
return ret;
783+
}
780784
public:
781785
SHDescriptor(std::unique_ptr<DescriptorImpl> desc) : DescriptorImpl({}, std::move(desc), "sh") {}
782786

@@ -793,7 +797,12 @@ class SHDescriptor final : public DescriptorImpl
793797
class WSHDescriptor final : public DescriptorImpl
794798
{
795799
protected:
796-
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Vector(GetScriptForDestination(WitnessV0ScriptHash(*script))); }
800+
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider& out) const override
801+
{
802+
auto ret = Vector(GetScriptForDestination(WitnessV0ScriptHash(*script)));
803+
if (ret.size()) out.scripts.emplace(CScriptID(*script), *script);
804+
return ret;
805+
}
797806
public:
798807
WSHDescriptor(std::unique_ptr<DescriptorImpl> desc) : DescriptorImpl({}, std::move(desc), "wsh") {}
799808
std::optional<OutputType> GetOutputType() const override { return OutputType::BECH32; }

0 commit comments

Comments
 (0)