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.
pull/826/head
Pieter Wuille 4 years ago
parent 84f3939ece
commit a917478db0

@ -497,7 +497,7 @@ protected:
* @param pubkeys The evaluations of the m_pubkey_args field.
* @param script The evaluation of m_subdescriptor_arg (or nullptr when m_subdescriptor_arg is nullptr).
* @param out A FlatSigningProvider to put scripts or public keys in that are necessary to the solver.
* The script arguments to this function are automatically added, as is the origin info of the provided pubkeys.
* The origin info of the provided pubkeys is automatically added.
* @return A vector with scriptPubKeys for this descriptor.
*/
virtual std::vector<CScript> MakeScripts(const std::vector<CPubKey>& pubkeys, const CScript* script, FlatSigningProvider& out) const = 0;
@ -597,7 +597,6 @@ public:
out.origins.emplace(entry.first.GetID(), std::make_pair<CPubKey, KeyOriginInfo>(CPubKey(entry.first), std::move(entry.second)));
}
if (m_subdescriptor_arg) {
out.scripts.emplace(CScriptID(subscripts[0]), subscripts[0]);
output_scripts = MakeScripts(pubkeys, &subscripts[0], out);
} else {
output_scripts = MakeScripts(pubkeys, nullptr, out);
@ -776,7 +775,12 @@ public:
class SHDescriptor final : public DescriptorImpl
{
protected:
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Vector(GetScriptForDestination(ScriptHash(*script))); }
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider& out) const override
{
auto ret = Vector(GetScriptForDestination(ScriptHash(*script)));
if (ret.size()) out.scripts.emplace(CScriptID(*script), *script);
return ret;
}
public:
SHDescriptor(std::unique_ptr<DescriptorImpl> desc) : DescriptorImpl({}, std::move(desc), "sh") {}
@ -793,7 +797,12 @@ public:
class WSHDescriptor final : public DescriptorImpl
{
protected:
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Vector(GetScriptForDestination(WitnessV0ScriptHash(*script))); }
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider& out) const override
{
auto ret = Vector(GetScriptForDestination(WitnessV0ScriptHash(*script)));
if (ret.size()) out.scripts.emplace(CScriptID(*script), *script);
return ret;
}
public:
WSHDescriptor(std::unique_ptr<DescriptorImpl> desc) : DescriptorImpl({}, std::move(desc), "wsh") {}
std::optional<OutputType> GetOutputType() const override { return OutputType::BECH32; }

Loading…
Cancel
Save