Skip to content

Commit

Permalink
Add Descriptor::IsSolvable() to distinguish addr/raw from others
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Oct 26, 2018
1 parent 4d78bd9 commit 225bf3e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/script/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class AddressDescriptor final : public Descriptor
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<CScript>& output_scripts, FlatSigningProvider& out) const override
Expand All @@ -229,6 +230,7 @@ class RawDescriptor final : public Descriptor
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<CScript>& output_scripts, FlatSigningProvider& out) const override
Expand All @@ -249,6 +251,7 @@ class SingleKeyDescriptor final : public Descriptor
SingleKeyDescriptor(std::unique_ptr<PubkeyProvider> prov, const std::function<CScript(const CPubKey&)>& 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
{
Expand Down Expand Up @@ -290,6 +293,8 @@ class MultisigDescriptor : public Descriptor
return false;
}

bool IsSolvable() const override { return true; }

std::string ToString() const override
{
std::string ret = strprintf("multi(%i", m_threshold);
Expand Down Expand Up @@ -343,6 +348,7 @@ class ConvertorDescriptor : public Descriptor
ConvertorDescriptor(std::unique_ptr<Descriptor> descriptor, const std::function<CScript(const CScript&)>& 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
{
Expand Down Expand Up @@ -377,6 +383,7 @@ class ComboDescriptor final : public Descriptor
ComboDescriptor(std::unique_ptr<PubkeyProvider> 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
{
Expand Down
4 changes: 4 additions & 0 deletions src/script/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 225bf3e

Please sign in to comment.