aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2021-02-04 16:11:05 -0800
committerPieter Wuille <pieter@wuille.net>2021-03-29 16:40:22 -0700
commita917478db0788b244c0c799b98bf67a94df7035e (patch)
tree1316a8a78be54d563778e43b5cde2353c1e70077 /src/script
parent84f3939ece9f4901141b28fd2dd6e3899d01d66e (diff)
downloadbitcoin-a917478db0788b244c0c799b98bf67a94df7035e.tar.xz
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.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/descriptor.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp
index ed382f2a54..d15cba1fa8 100644
--- a/src/script/descriptor.cpp
+++ b/src/script/descriptor.cpp
@@ -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; }