From 225bf3e3b0a89a285da451cd589be148324039ab Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 12 Oct 2018 18:27:00 -0700 Subject: Add Descriptor::IsSolvable() to distinguish addr/raw from others --- src/script/descriptor.cpp | 7 +++++++ src/script/descriptor.h | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index c498024092..e3f9381da0 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -211,6 +211,7 @@ public: AddressDescriptor(CTxDestination destination) : m_destination(std::move(destination)) {} bool IsRange() const override { return false; } + bool IsSolvable() const override { return false; } std::string ToString() const override { return "addr(" + EncodeDestination(m_destination) + ")"; } bool ToPrivateString(const SigningProvider& arg, std::string& out) const override { out = ToString(); return true; } bool Expand(int pos, const SigningProvider& arg, std::vector& output_scripts, FlatSigningProvider& out) const override @@ -229,6 +230,7 @@ public: RawDescriptor(CScript script) : m_script(std::move(script)) {} bool IsRange() const override { return false; } + bool IsSolvable() const override { return false; } std::string ToString() const override { return "raw(" + HexStr(m_script.begin(), m_script.end()) + ")"; } bool ToPrivateString(const SigningProvider& arg, std::string& out) const override { out = ToString(); return true; } bool Expand(int pos, const SigningProvider& arg, std::vector& output_scripts, FlatSigningProvider& out) const override @@ -249,6 +251,7 @@ public: SingleKeyDescriptor(std::unique_ptr prov, const std::function& fn, const std::string& name) : m_script_fn(fn), m_fn_name(name), m_provider(std::move(prov)) {} bool IsRange() const override { return m_provider->IsRange(); } + bool IsSolvable() const override { return true; } std::string ToString() const override { return m_fn_name + "(" + m_provider->ToString() + ")"; } bool ToPrivateString(const SigningProvider& arg, std::string& out) const override { @@ -290,6 +293,8 @@ public: return false; } + bool IsSolvable() const override { return true; } + std::string ToString() const override { std::string ret = strprintf("multi(%i", m_threshold); @@ -343,6 +348,7 @@ public: ConvertorDescriptor(std::unique_ptr descriptor, const std::function& fn, const std::string& name) : m_convert_fn(fn), m_fn_name(name), m_descriptor(std::move(descriptor)) {} bool IsRange() const override { return m_descriptor->IsRange(); } + bool IsSolvable() const override { return m_descriptor->IsSolvable(); } std::string ToString() const override { return m_fn_name + "(" + m_descriptor->ToString() + ")"; } bool ToPrivateString(const SigningProvider& arg, std::string& out) const override { @@ -377,6 +383,7 @@ public: ComboDescriptor(std::unique_ptr provider) : m_provider(std::move(provider)) {} bool IsRange() const override { return m_provider->IsRange(); } + bool IsSolvable() const override { return true; } std::string ToString() const override { return "combo(" + m_provider->ToString() + ")"; } bool ToPrivateString(const SigningProvider& arg, std::string& out) const override { diff --git a/src/script/descriptor.h b/src/script/descriptor.h index e44a6ef3c3..0111972f85 100644 --- a/src/script/descriptor.h +++ b/src/script/descriptor.h @@ -32,6 +32,10 @@ struct Descriptor { /** Whether the expansion of this descriptor depends on the position. */ virtual bool IsRange() const = 0; + /** Whether this descriptor has all information about signing ignoring lack of private keys. + * This is true for all descriptors except ones that use `raw` or `addr` constructions. */ + virtual bool IsSolvable() const = 0; + /** Convert the descriptor back to a string, undoing parsing. */ virtual std::string ToString() const = 0; -- cgit v1.2.3