@@ -484,15 +484,15 @@ class DescriptorImpl : public Descriptor
484
484
// ! The sub-descriptor argument (nullptr for everything but SH and WSH).
485
485
// ! In doc/descriptors.m this is referred to as SCRIPT expressions sh(SCRIPT)
486
486
// ! and wsh(SCRIPT), and distinct from KEY expressions and ADDR expressions.
487
+ // ! Subdescriptors can only ever generate a single script.
487
488
const std::unique_ptr<DescriptorImpl> m_subdescriptor_arg;
488
489
489
490
// ! Return a serialization of anything except pubkey and script arguments, to be prepended to those.
490
491
virtual std::string ToStringExtra () const { return " " ; }
491
492
492
493
/* * A helper function to construct the scripts for this descriptor.
493
494
*
494
- * This function is invoked once for every CScript produced by evaluating
495
- * m_subdescriptor_arg, or just once in case m_subdescriptor_arg is nullptr.
495
+ * This function is invoked once by ExpandHelper.
496
496
497
497
* @param pubkeys The evaluations of the m_pubkey_args field.
498
498
* @param script The evaluation of m_subdescriptor_arg (or nullptr when m_subdescriptor_arg is nullptr).
@@ -586,6 +586,7 @@ class DescriptorImpl : public Descriptor
586
586
if (m_subdescriptor_arg) {
587
587
FlatSigningProvider subprovider;
588
588
if (!m_subdescriptor_arg->ExpandHelper (pos, arg, read_cache, subscripts, subprovider, write_cache)) return false ;
589
+ assert (subscripts.size () == 1 );
589
590
out = Merge (out, subprovider);
590
591
}
591
592
@@ -596,13 +597,8 @@ class DescriptorImpl : public Descriptor
596
597
out.origins .emplace (entry.first .GetID (), std::make_pair<CPubKey, KeyOriginInfo>(CPubKey (entry.first ), std::move (entry.second )));
597
598
}
598
599
if (m_subdescriptor_arg) {
599
- for (const auto & subscript : subscripts) {
600
- out.scripts .emplace (CScriptID (subscript), subscript);
601
- std::vector<CScript> addscripts = MakeScripts (pubkeys, &subscript, out);
602
- for (auto & addscript : addscripts) {
603
- output_scripts.push_back (std::move (addscript));
604
- }
605
- }
600
+ out.scripts .emplace (CScriptID (subscripts[0 ]), subscripts[0 ]);
601
+ output_scripts = MakeScripts (pubkeys, &subscripts[0 ], out);
606
602
} else {
607
603
output_scripts = MakeScripts (pubkeys, nullptr , out);
608
604
}
0 commit comments