Skip to content

Commit 225bf3e

Browse files
committed
Add Descriptor::IsSolvable() to distinguish addr/raw from others
1 parent 4d78bd9 commit 225bf3e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/script/descriptor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class AddressDescriptor final : public Descriptor
211211
AddressDescriptor(CTxDestination destination) : m_destination(std::move(destination)) {}
212212

213213
bool IsRange() const override { return false; }
214+
bool IsSolvable() const override { return false; }
214215
std::string ToString() const override { return "addr(" + EncodeDestination(m_destination) + ")"; }
215216
bool ToPrivateString(const SigningProvider& arg, std::string& out) const override { out = ToString(); return true; }
216217
bool Expand(int pos, const SigningProvider& arg, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const override
@@ -229,6 +230,7 @@ class RawDescriptor final : public Descriptor
229230
RawDescriptor(CScript script) : m_script(std::move(script)) {}
230231

231232
bool IsRange() const override { return false; }
233+
bool IsSolvable() const override { return false; }
232234
std::string ToString() const override { return "raw(" + HexStr(m_script.begin(), m_script.end()) + ")"; }
233235
bool ToPrivateString(const SigningProvider& arg, std::string& out) const override { out = ToString(); return true; }
234236
bool Expand(int pos, const SigningProvider& arg, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const override
@@ -249,6 +251,7 @@ class SingleKeyDescriptor final : public Descriptor
249251
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)) {}
250252

251253
bool IsRange() const override { return m_provider->IsRange(); }
254+
bool IsSolvable() const override { return true; }
252255
std::string ToString() const override { return m_fn_name + "(" + m_provider->ToString() + ")"; }
253256
bool ToPrivateString(const SigningProvider& arg, std::string& out) const override
254257
{
@@ -290,6 +293,8 @@ class MultisigDescriptor : public Descriptor
290293
return false;
291294
}
292295

296+
bool IsSolvable() const override { return true; }
297+
293298
std::string ToString() const override
294299
{
295300
std::string ret = strprintf("multi(%i", m_threshold);
@@ -343,6 +348,7 @@ class ConvertorDescriptor : public Descriptor
343348
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)) {}
344349

345350
bool IsRange() const override { return m_descriptor->IsRange(); }
351+
bool IsSolvable() const override { return m_descriptor->IsSolvable(); }
346352
std::string ToString() const override { return m_fn_name + "(" + m_descriptor->ToString() + ")"; }
347353
bool ToPrivateString(const SigningProvider& arg, std::string& out) const override
348354
{
@@ -377,6 +383,7 @@ class ComboDescriptor final : public Descriptor
377383
ComboDescriptor(std::unique_ptr<PubkeyProvider> provider) : m_provider(std::move(provider)) {}
378384

379385
bool IsRange() const override { return m_provider->IsRange(); }
386+
bool IsSolvable() const override { return true; }
380387
std::string ToString() const override { return "combo(" + m_provider->ToString() + ")"; }
381388
bool ToPrivateString(const SigningProvider& arg, std::string& out) const override
382389
{

src/script/descriptor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ struct Descriptor {
3232
/** Whether the expansion of this descriptor depends on the position. */
3333
virtual bool IsRange() const = 0;
3434

35+
/** Whether this descriptor has all information about signing ignoring lack of private keys.
36+
* This is true for all descriptors except ones that use `raw` or `addr` constructions. */
37+
virtual bool IsSolvable() const = 0;
38+
3539
/** Convert the descriptor back to a string, undoing parsing. */
3640
virtual std::string ToString() const = 0;
3741

0 commit comments

Comments
 (0)