diff --git a/src/script/descriptor.h b/src/script/descriptor.h --- a/src/script/descriptor.h +++ b/src/script/descriptor.h @@ -57,10 +57,10 @@ * false, this is ignored. * provider: the provider to query for private keys in case of hardened * derivation. - * output_script: the expanded scriptPubKeys will be put here. + * output_scripts: the expanded scriptPubKeys will be put here. * out: scripts and public keys necessary for solving the expanded * scriptPubKeys will be put here (may be equal to provider). cache: vector - * which will be overwritten with cache data necessary to-evaluate the + * which will be overwritten with cache data necessary to evaluate the * descriptor at this point without access to private keys. */ virtual bool Expand(int pos, const SigningProvider &provider, @@ -73,8 +73,8 @@ * * pos: the position at which to expand the descriptor. If IsRange() is * false, this is ignored. cache: vector from which cached expansion data - * will be read. output_script: the expanded scriptPubKeys will be put here. - * out: scripts and public keys necessary for solving the expanded + * will be read. output_scripts: the expanded scriptPubKeys will be put + * here. out: scripts and public keys necessary for solving the expanded * scriptPubKeys will be put here (may be equal to provider). */ virtual bool ExpandFromCache(int pos, const std::vector &cache, diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -394,10 +394,12 @@ /** Base class for all Descriptor implementations. */ class DescriptorImpl : public Descriptor { //! Public key arguments for this descriptor (size 1 for PK, PKH; any size - //! of Multisig). + //! for Multisig). const std::vector> m_pubkey_args; //! The sub-descriptor argument (nullptr for everything but SH). - const std::unique_ptr m_script_arg; + //! In doc/descriptors.m this is referred to as SCRIPT expressions + //! sh(SCRIPT), and distinct from KEY expressions and ADDR expressions. + const std::unique_ptr m_subdescriptor_arg; //! The string name of the descriptor function. const std::string m_name; @@ -410,11 +412,12 @@ * A helper function to construct the scripts for this descriptor. * * This function is invoked once for every CScript produced by evaluating - * m_script_arg, or just once in case m_script_arg is nullptr. + * m_subdescriptor_arg, or just once in case m_subdescriptor_arg is + nullptr. * @param pubkeys The evaluations of the m_pubkey_args field. - * @param script The evaluation of m_script_arg (or nullptr when - m_script_arg is nullptr). + * @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 @@ -429,12 +432,12 @@ DescriptorImpl(std::vector> pubkeys, std::unique_ptr script, const std::string &name) - : m_pubkey_args(std::move(pubkeys)), m_script_arg(std::move(script)), - m_name(name) {} + : m_pubkey_args(std::move(pubkeys)), + m_subdescriptor_arg(std::move(script)), m_name(name) {} bool IsSolvable() const override { - if (m_script_arg) { - if (!m_script_arg->IsSolvable()) { + if (m_subdescriptor_arg) { + if (!m_subdescriptor_arg->IsSolvable()) { return false; } } @@ -447,8 +450,8 @@ return true; } } - if (m_script_arg) { - if (m_script_arg->IsRange()) { + if (m_subdescriptor_arg) { + if (m_subdescriptor_arg->IsRange()) { return true; } } @@ -474,12 +477,12 @@ } ret += std::move(tmp); } - if (m_script_arg) { + if (m_subdescriptor_arg) { if (pos++) { ret += ","; } std::string tmp; - if (!m_script_arg->ToStringHelper(arg, tmp, priv)) { + if (!m_subdescriptor_arg->ToStringHelper(arg, tmp, priv)) { return false; } ret += std::move(tmp); @@ -513,6 +516,8 @@ // producing output in case of failure. for (const auto &p : m_pubkey_args) { entries.emplace_back(); + // If we have a cache, we don't need GetPubKey to compute the public + // key. Pass in nullptr to signify only origin info is desired. if (!p->GetPubKey(pos, arg, cache_read ? nullptr : &entries.back().first, entries.back().second)) { @@ -543,10 +548,11 @@ } } std::vector subscripts; - if (m_script_arg) { + if (m_subdescriptor_arg) { FlatSigningProvider subprovider; - if (!m_script_arg->ExpandHelper(pos, arg, cache_read, subscripts, - subprovider, cache_write)) { + if (!m_subdescriptor_arg->ExpandHelper(pos, arg, cache_read, + subscripts, subprovider, + cache_write)) { return false; } out = Merge(out, subprovider); @@ -561,7 +567,7 @@ std::make_pair( CPubKey(entry.first), std::move(entry.second))); } - if (m_script_arg) { + if (m_subdescriptor_arg) { for (const auto &subscript : subscripts) { out.scripts.emplace(CScriptID(subscript), subscript); std::vector addscripts =