Skip to content

Commit

Permalink
Add IsSingleType to Descriptors
Browse files Browse the repository at this point in the history
IsSingleType will return whether the descriptor will give one or multiple scriptPubKeys
  • Loading branch information
achow101 committed Apr 23, 2020
1 parent 953feb3 commit d1ec3e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/script/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ class AddressDescriptor final : public DescriptorImpl
default: return nullopt;
}
}
bool IsSingleType() const final { return true; }
};

/** A parsed raw(H) descriptor. */
Expand Down Expand Up @@ -602,6 +603,7 @@ class RawDescriptor final : public DescriptorImpl
default: return nullopt;
}
}
bool IsSingleType() const final { return true; }
};

/** A parsed pk(P) descriptor. */
Expand All @@ -611,6 +613,7 @@ class PKDescriptor final : public DescriptorImpl
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider&) const override { return Vector(GetScriptForRawPubKey(keys[0])); }
public:
PKDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), {}, "pk") {}
bool IsSingleType() const final { return true; }
};

/** A parsed pkh(P) descriptor. */
Expand All @@ -626,6 +629,7 @@ class PKHDescriptor final : public DescriptorImpl
public:
PKHDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), {}, "pkh") {}
Optional<OutputType> GetOutputType() const override { return OutputType::LEGACY; }
bool IsSingleType() const final { return true; }
};

/** A parsed wpkh(P) descriptor. */
Expand All @@ -641,6 +645,7 @@ class WPKHDescriptor final : public DescriptorImpl
public:
WPKHDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), {}, "wpkh") {}
Optional<OutputType> GetOutputType() const override { return OutputType::BECH32; }
bool IsSingleType() const final { return true; }
};

/** A parsed combo(P) descriptor. */
Expand All @@ -664,6 +669,7 @@ class ComboDescriptor final : public DescriptorImpl
}
public:
ComboDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), {}, "combo") {}
bool IsSingleType() const final { return false; }
};

/** A parsed multi(...) or sortedmulti(...) descriptor */
Expand All @@ -683,6 +689,7 @@ class MultisigDescriptor final : public DescriptorImpl
}
public:
MultisigDescriptor(int threshold, std::vector<std::unique_ptr<PubkeyProvider>> providers, bool sorted = false) : DescriptorImpl(std::move(providers), {}, sorted ? "sortedmulti" : "multi"), m_threshold(threshold), m_sorted(sorted) {}
bool IsSingleType() const final { return true; }
};

/** A parsed sh(...) descriptor. */
Expand All @@ -699,6 +706,7 @@ class SHDescriptor final : public DescriptorImpl
if (m_subdescriptor_arg->GetOutputType() == OutputType::BECH32) return OutputType::P2SH_SEGWIT;
return OutputType::LEGACY;
}
bool IsSingleType() const final { return true; }
};

/** A parsed wsh(...) descriptor. */
Expand All @@ -709,6 +717,7 @@ class WSHDescriptor final : public DescriptorImpl
public:
WSHDescriptor(std::unique_ptr<DescriptorImpl> desc) : DescriptorImpl({}, std::move(desc), "wsh") {}
Optional<OutputType> GetOutputType() const override { return OutputType::BECH32; }
bool IsSingleType() const final { return true; }
};

////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions src/script/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ struct Descriptor {
/** Convert the descriptor back to a string, undoing parsing. */
virtual std::string ToString() const = 0;

/** Whether this descriptor will return one scriptPubKey or multiple (aka is or is not combo) */
virtual bool IsSingleType() const = 0;

/** Convert the descriptor to a private string. This fails if the provided provider does not have the relevant private keys. */
virtual bool ToPrivateString(const SigningProvider& provider, std::string& out) const = 0;

Expand Down

0 comments on commit d1ec3e4

Please sign in to comment.