From 2290269759ad10cc2e35958c7b0a63f3a7608621 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Wed, 12 Dec 2018 09:45:55 +0100 Subject: scripted-diff: rename DescriptorImpl m_script_arg to m_subdescriptor_arg -BEGIN VERIFY SCRIPT- sed -i -e 's/m_script_arg/m_subdescriptor_arg/g' src/script/descriptor.cpp -END VERIFY SCRIPT- --- src/script/descriptor.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index a702be5b78..5f758ab42d 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -210,7 +210,7 @@ class DescriptorImpl : public Descriptor //! Public key arguments for this descriptor (size 1 for PK, PKH, WPKH; any size of Multisig). const std::vector> m_pubkey_args; //! The sub-descriptor argument (nullptr for everything but SH and WSH). - const std::unique_ptr m_script_arg; + const std::unique_ptr m_subdescriptor_arg; //! The string name of the descriptor function. const std::string m_name; @@ -221,10 +221,10 @@ protected: /** 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 and pubkeys argument to this function are automatically added. * @return A vector with scriptPubKeys for this descriptor. @@ -232,12 +232,12 @@ protected: virtual std::vector MakeScripts(const std::vector& pubkeys, const CScript* script, FlatSigningProvider& out) const = 0; public: - 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) {} + DescriptorImpl(std::vector> pubkeys, std::unique_ptr script, const std::string& 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()) return false; + if (m_subdescriptor_arg) { + if (!m_subdescriptor_arg->IsSolvable()) return false; } return true; } @@ -247,8 +247,8 @@ public: for (const auto& pubkey : m_pubkey_args) { if (pubkey->IsRange()) return true; } - if (m_script_arg) { - if (m_script_arg->IsRange()) return true; + if (m_subdescriptor_arg) { + if (m_subdescriptor_arg->IsRange()) return true; } return false; } @@ -268,10 +268,10 @@ public: } 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)) return false; + if (!m_subdescriptor_arg->ToStringHelper(arg, tmp, priv)) return false; ret += std::move(tmp); } out = std::move(ret) + ")"; @@ -311,9 +311,9 @@ public: } } 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)) return false; + if (!m_subdescriptor_arg->ExpandHelper(pos, arg, cache_read, subscripts, subprovider, cache_write)) return false; out = Merge(out, subprovider); } @@ -324,7 +324,7 @@ public: out.origins.emplace(entry.first.GetID(), std::move(entry.second)); out.pubkeys.emplace(entry.first.GetID(), entry.first); } - if (m_script_arg) { + if (m_subdescriptor_arg) { for (const auto& subscript : subscripts) { out.scripts.emplace(CScriptID(subscript), subscript); std::vector addscripts = MakeScripts(pubkeys, &subscript, out); -- cgit v1.2.3 From 2e68ffaf205866e4cea71f64e79bbfb89e17280a Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Wed, 12 Dec 2018 10:08:08 +0100 Subject: [doc] descriptor: explain GetPubKey() usage with cached public key Plus a few typo fixes. --- src/script/descriptor.cpp | 6 +++++- src/script/descriptor.h | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 5f758ab42d..96cd93df5a 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -207,9 +207,11 @@ public: /** Base class for all Descriptor implementations. */ class DescriptorImpl : public Descriptor { - //! Public key arguments for this descriptor (size 1 for PK, PKH, WPKH; any size of Multisig). + //! Public key arguments for this descriptor (size 1 for PK, PKH, WPKH; any size for Multisig). const std::vector> m_pubkey_args; //! The sub-descriptor argument (nullptr for everything but SH and WSH). + //! In doc/descriptors.m this is referred to as SCRIPT expressions sh(SCRIPT) + //! and wsh(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; @@ -295,6 +297,8 @@ public: // Construct temporary data in `entries` and `subscripts`, to avoid 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)) return false; if (cache_read) { // Cached expanded public key exists, use it. diff --git a/src/script/descriptor.h b/src/script/descriptor.h index 44f0efca03..2be157b861 100644 --- a/src/script/descriptor.h +++ b/src/script/descriptor.h @@ -46,9 +46,9 @@ struct Descriptor { * * pos: the position at which to expand the descriptor. If IsRange() is 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 descriptor at this point without access to private keys. + * cache: vector 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, std::vector& output_scripts, FlatSigningProvider& out, std::vector* cache = nullptr) const = 0; @@ -56,7 +56,7 @@ struct Descriptor { * * 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. + * 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, std::vector& output_scripts, FlatSigningProvider& out) const = 0; -- cgit v1.2.3