| 613 | } |
| 614 | |
| 615 | bool ExpandHelper(int pos, const SigningProvider& arg, const DescriptorCache* read_cache, std::vector<CScript>& output_scripts, FlatSigningProvider& out, DescriptorCache* write_cache) const |
| 616 | { |
| 617 | std::vector<std::pair<CPubKey, KeyOriginInfo>> entries; |
| 618 | entries.reserve(m_pubkey_args.size()); |
| 619 | |
| 620 | // Construct temporary data in `entries`, `subscripts`, and `subprovider` to avoid producing output in case of failure. |
| 621 | for (const auto& p : m_pubkey_args) { |
| 622 | entries.emplace_back(); |
| 623 | if (!p->GetPubKey(pos, arg, entries.back().first, entries.back().second, read_cache, write_cache)) return false; |
| 624 | } |
| 625 | std::vector<CScript> subscripts; |
| 626 | FlatSigningProvider subprovider; |
| 627 | for (const auto& subarg : m_subdescriptor_args) { |
| 628 | std::vector<CScript> outscripts; |
| 629 | if (!subarg->ExpandHelper(pos, arg, read_cache, outscripts, subprovider, write_cache)) return false; |
| 630 | assert(outscripts.size() == 1); |
| 631 | subscripts.emplace_back(std::move(outscripts[0])); |
| 632 | } |
| 633 | out = Merge(std::move(out), std::move(subprovider)); |
| 634 | |
| 635 | std::vector<CPubKey> pubkeys; |
| 636 | pubkeys.reserve(entries.size()); |
| 637 | for (auto& entry : entries) { |
| 638 | pubkeys.push_back(entry.first); |
| 639 | out.origins.emplace(entry.first.GetID(), std::make_pair<CPubKey, KeyOriginInfo>(CPubKey(entry.first), std::move(entry.second))); |
| 640 | } |
| 641 | |
| 642 | output_scripts = MakeScripts(pubkeys, Span{subscripts}, out); |
| 643 | return true; |
| 644 | } |
| 645 | |
| 646 | bool Expand(int pos, const SigningProvider& provider, std::vector<CScript>& output_scripts, FlatSigningProvider& out, DescriptorCache* write_cache = nullptr) const final |
| 647 | { |