|
|
@ -202,129 +202,109 @@ public:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** A parsed addr(A) descriptor. */
|
|
|
|
/** Base class for all Descriptor implementations. */
|
|
|
|
class AddressDescriptor final : public Descriptor
|
|
|
|
class DescriptorImpl : public Descriptor
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CTxDestination m_destination;
|
|
|
|
//! Public key arguments for this descriptor (size 1 for PK, PKH, WPKH; any size of Multisig).
|
|
|
|
|
|
|
|
const std::vector<std::unique_ptr<PubkeyProvider>> m_pubkey_args;
|
|
|
|
|
|
|
|
//! The sub-descriptor argument (nullptr for everything but SH and WSH).
|
|
|
|
|
|
|
|
const std::unique_ptr<Descriptor> m_script_arg;
|
|
|
|
|
|
|
|
//! The string name of the descriptor function.
|
|
|
|
|
|
|
|
const std::string m_name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
//! Return a serialization of anything except pubkey and script arguments, to be prepended to those.
|
|
|
|
|
|
|
|
virtual std::string ToStringExtra() const { return ""; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* @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 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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
virtual std::vector<CScript> MakeScripts(const std::vector<CPubKey>& pubkeys, const CScript* script, FlatSigningProvider& out) const = 0;
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
AddressDescriptor(CTxDestination destination) : m_destination(std::move(destination)) {}
|
|
|
|
DescriptorImpl(std::vector<std::unique_ptr<PubkeyProvider>> pubkeys, std::unique_ptr<Descriptor> script, const std::string& name) : m_pubkey_args(std::move(pubkeys)), m_script_arg(std::move(script)), m_name(name) {}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsRange() const override { return false; }
|
|
|
|
bool IsSolvable() const override
|
|
|
|
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
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
output_scripts = std::vector<CScript>{GetScriptForDestination(m_destination)};
|
|
|
|
if (m_script_arg) {
|
|
|
|
return true;
|
|
|
|
if (!m_script_arg->IsSolvable()) return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** A parsed raw(H) descriptor. */
|
|
|
|
|
|
|
|
class RawDescriptor final : public Descriptor
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CScript m_script;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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<CScript>& output_scripts, FlatSigningProvider& out) const override
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
output_scripts = std::vector<CScript>{m_script};
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** A parsed pk(P), pkh(P), or wpkh(P) descriptor. */
|
|
|
|
bool IsRange() const final
|
|
|
|
class SingleKeyDescriptor final : public Descriptor
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const std::function<CScript(const CPubKey&)> m_script_fn;
|
|
|
|
|
|
|
|
const std::string m_fn_name;
|
|
|
|
|
|
|
|
std::unique_ptr<PubkeyProvider> m_provider;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
for (const auto& pubkey : m_pubkey_args) {
|
|
|
|
if (!m_provider->ToPrivateString(arg, ret)) return false;
|
|
|
|
if (pubkey->IsRange()) return true;
|
|
|
|
out = m_fn_name + "(" + std::move(ret) + ")";
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Expand(int pos, const SigningProvider& arg, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const override
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CPubKey key;
|
|
|
|
|
|
|
|
KeyOriginInfo info;
|
|
|
|
|
|
|
|
if (!m_provider->GetPubKey(pos, arg, key, info)) return false;
|
|
|
|
|
|
|
|
output_scripts = std::vector<CScript>{m_script_fn(key)};
|
|
|
|
|
|
|
|
out.origins.emplace(key.GetID(), std::move(info));
|
|
|
|
|
|
|
|
out.pubkeys.emplace(key.GetID(), key);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (m_script_arg) {
|
|
|
|
|
|
|
|
if (m_script_arg->IsRange()) return true;
|
|
|
|
CScript P2PKHGetScript(const CPubKey& pubkey) { return GetScriptForDestination(pubkey.GetID()); }
|
|
|
|
|
|
|
|
CScript P2PKGetScript(const CPubKey& pubkey) { return GetScriptForRawPubKey(pubkey); }
|
|
|
|
|
|
|
|
CScript P2WPKHGetScript(const CPubKey& pubkey) { return GetScriptForDestination(WitnessV0KeyHash(pubkey.GetID())); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** A parsed multi(...) descriptor. */
|
|
|
|
|
|
|
|
class MultisigDescriptor : public Descriptor
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int m_threshold;
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<PubkeyProvider>> m_providers;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
MultisigDescriptor(int threshold, std::vector<std::unique_ptr<PubkeyProvider>> providers) : m_threshold(threshold), m_providers(std::move(providers)) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool IsRange() const override
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (const auto& p : m_providers) {
|
|
|
|
|
|
|
|
if (p->IsRange()) return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsSolvable() const override { return true; }
|
|
|
|
bool ToPrivateString(const SigningProvider& arg, std::string& out) const final
|
|
|
|
|
|
|
|
|
|
|
|
std::string ToString() const override
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string ret = strprintf("multi(%i", m_threshold);
|
|
|
|
std::string extra = ToStringExtra();
|
|
|
|
for (const auto& p : m_providers) {
|
|
|
|
size_t pos = extra.size() > 0 ? 1 : 0;
|
|
|
|
ret += "," + p->ToString();
|
|
|
|
std::string ret = m_name + "(" + extra;
|
|
|
|
|
|
|
|
for (const auto& pubkey : m_pubkey_args) {
|
|
|
|
|
|
|
|
if (pos++) ret += ",";
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
|
|
|
|
if (!pubkey->ToPrivateString(arg, tmp)) return false;
|
|
|
|
|
|
|
|
ret += std::move(tmp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_script_arg) {
|
|
|
|
|
|
|
|
if (pos++) ret += ",";
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
|
|
|
|
if (!m_script_arg->ToPrivateString(arg, tmp)) return false;
|
|
|
|
|
|
|
|
ret += std::move(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return std::move(ret) + ")";
|
|
|
|
out = std::move(ret) + ")";
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ToPrivateString(const SigningProvider& arg, std::string& out) const override
|
|
|
|
std::string ToString() const final
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string ret = strprintf("multi(%i", m_threshold);
|
|
|
|
std::string extra = ToStringExtra();
|
|
|
|
for (const auto& p : m_providers) {
|
|
|
|
size_t pos = extra.size() > 0 ? 1 : 0;
|
|
|
|
std::string sub;
|
|
|
|
std::string ret = m_name + "(" + extra;
|
|
|
|
if (!p->ToPrivateString(arg, sub)) return false;
|
|
|
|
for (const auto& pubkey : m_pubkey_args) {
|
|
|
|
ret += "," + std::move(sub);
|
|
|
|
if (pos++) ret += ",";
|
|
|
|
|
|
|
|
ret += pubkey->ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out = std::move(ret) + ")";
|
|
|
|
if (m_script_arg) {
|
|
|
|
return true;
|
|
|
|
if (pos++) ret += ",";
|
|
|
|
|
|
|
|
ret += m_script_arg->ToString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(ret) + ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Expand(int pos, const SigningProvider& arg, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const override
|
|
|
|
bool Expand(int pos, const SigningProvider& arg, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const final
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::vector<std::pair<CPubKey, KeyOriginInfo>> entries;
|
|
|
|
std::vector<std::pair<CPubKey, KeyOriginInfo>> entries;
|
|
|
|
entries.reserve(m_providers.size());
|
|
|
|
entries.reserve(m_pubkey_args.size());
|
|
|
|
// Construct temporary data in `entries`, to avoid producing output in case of failure.
|
|
|
|
|
|
|
|
for (const auto& p : m_providers) {
|
|
|
|
// 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();
|
|
|
|
entries.emplace_back();
|
|
|
|
if (!p->GetPubKey(pos, arg, entries.back().first, entries.back().second)) return false;
|
|
|
|
if (!p->GetPubKey(pos, arg, entries.back().first, entries.back().second)) return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<CScript> subscripts;
|
|
|
|
|
|
|
|
if (m_script_arg) {
|
|
|
|
|
|
|
|
FlatSigningProvider subprovider;
|
|
|
|
|
|
|
|
if (!m_script_arg->Expand(pos, arg, subscripts, subprovider)) return false;
|
|
|
|
|
|
|
|
out = Merge(out, subprovider);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<CPubKey> pubkeys;
|
|
|
|
std::vector<CPubKey> pubkeys;
|
|
|
|
pubkeys.reserve(entries.size());
|
|
|
|
pubkeys.reserve(entries.size());
|
|
|
|
for (auto& entry : entries) {
|
|
|
|
for (auto& entry : entries) {
|
|
|
@ -332,89 +312,130 @@ public:
|
|
|
|
out.origins.emplace(entry.first.GetID(), std::move(entry.second));
|
|
|
|
out.origins.emplace(entry.first.GetID(), std::move(entry.second));
|
|
|
|
out.pubkeys.emplace(entry.first.GetID(), entry.first);
|
|
|
|
out.pubkeys.emplace(entry.first.GetID(), entry.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
output_scripts = std::vector<CScript>{GetScriptForMultisig(m_threshold, pubkeys)};
|
|
|
|
if (m_script_arg) {
|
|
|
|
|
|
|
|
for (const auto& subscript : subscripts) {
|
|
|
|
|
|
|
|
out.scripts.emplace(CScriptID(subscript), subscript);
|
|
|
|
|
|
|
|
std::vector<CScript> addscripts = MakeScripts(pubkeys, &subscript, out);
|
|
|
|
|
|
|
|
for (auto& addscript : addscripts) {
|
|
|
|
|
|
|
|
output_scripts.push_back(std::move(addscript));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
output_scripts = MakeScripts(pubkeys, nullptr, out);
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** A parsed sh(S) or wsh(S) descriptor. */
|
|
|
|
/** Construct a vector with one element, which is moved into it. */
|
|
|
|
class ConvertorDescriptor : public Descriptor
|
|
|
|
template<typename T>
|
|
|
|
|
|
|
|
std::vector<T> Singleton(T elem)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const std::function<CScript(const CScript&)> m_convert_fn;
|
|
|
|
std::vector<T> ret;
|
|
|
|
const std::string m_fn_name;
|
|
|
|
ret.emplace_back(std::move(elem));
|
|
|
|
std::unique_ptr<Descriptor> m_descriptor;
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** A parsed addr(A) descriptor. */
|
|
|
|
|
|
|
|
class AddressDescriptor final : public DescriptorImpl
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const CTxDestination m_destination;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
std::string ToStringExtra() const override { return EncodeDestination(m_destination); }
|
|
|
|
|
|
|
|
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript*, FlatSigningProvider&) const override { return Singleton(GetScriptForDestination(m_destination)); }
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
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)) {}
|
|
|
|
AddressDescriptor(CTxDestination destination) : DescriptorImpl({}, {}, "addr"), m_destination(std::move(destination)) {}
|
|
|
|
|
|
|
|
bool IsSolvable() const final { return false; }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool IsRange() const override { return m_descriptor->IsRange(); }
|
|
|
|
/** A parsed raw(H) descriptor. */
|
|
|
|
bool IsSolvable() const override { return m_descriptor->IsSolvable(); }
|
|
|
|
class RawDescriptor final : public DescriptorImpl
|
|
|
|
std::string ToString() const override { return m_fn_name + "(" + m_descriptor->ToString() + ")"; }
|
|
|
|
{
|
|
|
|
bool ToPrivateString(const SigningProvider& arg, std::string& out) const override
|
|
|
|
const CScript m_script;
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
std::string ret;
|
|
|
|
std::string ToStringExtra() const override { return HexStr(m_script.begin(), m_script.end()); }
|
|
|
|
if (!m_descriptor->ToPrivateString(arg, ret)) return false;
|
|
|
|
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript*, FlatSigningProvider&) const override { return Singleton(m_script); }
|
|
|
|
out = m_fn_name + "(" + std::move(ret) + ")";
|
|
|
|
public:
|
|
|
|
return true;
|
|
|
|
RawDescriptor(CScript script) : DescriptorImpl({}, {}, "raw"), m_script(std::move(script)) {}
|
|
|
|
}
|
|
|
|
bool IsSolvable() const final { return false; }
|
|
|
|
bool Expand(int pos, const SigningProvider& arg, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const override
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::vector<CScript> sub;
|
|
|
|
|
|
|
|
if (!m_descriptor->Expand(pos, arg, sub, out)) return false;
|
|
|
|
|
|
|
|
output_scripts.clear();
|
|
|
|
|
|
|
|
for (const auto& script : sub) {
|
|
|
|
|
|
|
|
CScriptID id(script);
|
|
|
|
|
|
|
|
out.scripts.emplace(CScriptID(script), script);
|
|
|
|
|
|
|
|
output_scripts.push_back(m_convert_fn(script));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CScript ConvertP2SH(const CScript& script) { return GetScriptForDestination(CScriptID(script)); }
|
|
|
|
/** A parsed pk(P) descriptor. */
|
|
|
|
CScript ConvertP2WSH(const CScript& script) { return GetScriptForDestination(WitnessV0ScriptHash(script)); }
|
|
|
|
class PKDescriptor final : public DescriptorImpl
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider&) const override { return Singleton(GetScriptForRawPubKey(keys[0])); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
PKDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Singleton(std::move(prov)), {}, "pk") {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** A parsed combo(P) descriptor. */
|
|
|
|
/** A parsed pkh(P) descriptor. */
|
|
|
|
class ComboDescriptor final : public Descriptor
|
|
|
|
class PKHDescriptor final : public DescriptorImpl
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::unique_ptr<PubkeyProvider> m_provider;
|
|
|
|
protected:
|
|
|
|
|
|
|
|
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider&) const override { return Singleton(GetScriptForDestination(keys[0].GetID())); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
PKHDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Singleton(std::move(prov)), {}, "pkh") {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** A parsed wpkh(P) descriptor. */
|
|
|
|
|
|
|
|
class WPKHDescriptor final : public DescriptorImpl
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider&) const override { return Singleton(GetScriptForDestination(WitnessV0KeyHash(keys[0].GetID()))); }
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
ComboDescriptor(std::unique_ptr<PubkeyProvider> provider) : m_provider(std::move(provider)) {}
|
|
|
|
WPKHDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Singleton(std::move(prov)), {}, "wpkh") {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool IsRange() const override { return m_provider->IsRange(); }
|
|
|
|
/** A parsed combo(P) descriptor. */
|
|
|
|
bool IsSolvable() const override { return true; }
|
|
|
|
class ComboDescriptor final : public DescriptorImpl
|
|
|
|
std::string ToString() const override { return "combo(" + m_provider->ToString() + ")"; }
|
|
|
|
{
|
|
|
|
bool ToPrivateString(const SigningProvider& arg, std::string& out) const override
|
|
|
|
protected:
|
|
|
|
{
|
|
|
|
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider& out) const override
|
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
if (!m_provider->ToPrivateString(arg, ret)) return false;
|
|
|
|
|
|
|
|
out = "combo(" + std::move(ret) + ")";
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Expand(int pos, const SigningProvider& arg, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const override
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CPubKey key;
|
|
|
|
|
|
|
|
KeyOriginInfo info;
|
|
|
|
|
|
|
|
if (!m_provider->GetPubKey(pos, arg, key, info)) return false;
|
|
|
|
|
|
|
|
CKeyID keyid = key.GetID();
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CScript p2pk = GetScriptForRawPubKey(key);
|
|
|
|
std::vector<CScript> ret;
|
|
|
|
CScript p2pkh = GetScriptForDestination(keyid);
|
|
|
|
CKeyID id = keys[0].GetID();
|
|
|
|
output_scripts = std::vector<CScript>{std::move(p2pk), std::move(p2pkh)};
|
|
|
|
ret.emplace_back(GetScriptForRawPubKey(keys[0])); // P2PK
|
|
|
|
out.pubkeys.emplace(keyid, key);
|
|
|
|
ret.emplace_back(GetScriptForDestination(id)); // P2PKH
|
|
|
|
out.origins.emplace(keyid, std::move(info));
|
|
|
|
if (keys[0].IsCompressed()) {
|
|
|
|
}
|
|
|
|
CScript p2wpkh = GetScriptForDestination(WitnessV0KeyHash(id));
|
|
|
|
if (key.IsCompressed()) {
|
|
|
|
out.scripts.emplace(CScriptID(p2wpkh), p2wpkh);
|
|
|
|
CScript p2wpkh = GetScriptForDestination(WitnessV0KeyHash(keyid));
|
|
|
|
ret.emplace_back(p2wpkh);
|
|
|
|
CScriptID p2wpkh_id(p2wpkh);
|
|
|
|
ret.emplace_back(GetScriptForDestination(CScriptID(p2wpkh))); // P2SH-P2WPKH
|
|
|
|
CScript p2sh_p2wpkh = GetScriptForDestination(p2wpkh_id);
|
|
|
|
|
|
|
|
out.scripts.emplace(p2wpkh_id, p2wpkh);
|
|
|
|
|
|
|
|
output_scripts.push_back(std::move(p2wpkh));
|
|
|
|
|
|
|
|
output_scripts.push_back(std::move(p2sh_p2wpkh));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ComboDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Singleton(std::move(prov)), {}, "combo") {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** A parsed multi(...) descriptor. */
|
|
|
|
|
|
|
|
class MultisigDescriptor final : public DescriptorImpl
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const int m_threshold;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
std::string ToStringExtra() const override { return strprintf("%i", m_threshold); }
|
|
|
|
|
|
|
|
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider&) const override { return Singleton(GetScriptForMultisig(m_threshold, keys)); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
MultisigDescriptor(int threshold, std::vector<std::unique_ptr<PubkeyProvider>> providers) : DescriptorImpl(std::move(providers), {}, "multi"), m_threshold(threshold) {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** A parsed sh(...) descriptor. */
|
|
|
|
|
|
|
|
class SHDescriptor final : public DescriptorImpl
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Singleton(GetScriptForDestination(CScriptID(*script))); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
SHDescriptor(std::unique_ptr<Descriptor> desc) : DescriptorImpl({}, std::move(desc), "sh") {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** A parsed wsh(...) descriptor. */
|
|
|
|
|
|
|
|
class WSHDescriptor final : public DescriptorImpl
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
std::vector<CScript> MakeScripts(const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Singleton(GetScriptForDestination(WitnessV0ScriptHash(*script))); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
WSHDescriptor(std::unique_ptr<Descriptor> desc) : DescriptorImpl({}, std::move(desc), "wsh") {}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
@ -568,12 +589,12 @@ std::unique_ptr<Descriptor> ParseScript(Span<const char>& sp, ParseScriptContext
|
|
|
|
if (Func("pk", expr)) {
|
|
|
|
if (Func("pk", expr)) {
|
|
|
|
auto pubkey = ParsePubkey(expr, ctx != ParseScriptContext::P2WSH, out);
|
|
|
|
auto pubkey = ParsePubkey(expr, ctx != ParseScriptContext::P2WSH, out);
|
|
|
|
if (!pubkey) return nullptr;
|
|
|
|
if (!pubkey) return nullptr;
|
|
|
|
return MakeUnique<SingleKeyDescriptor>(std::move(pubkey), P2PKGetScript, "pk");
|
|
|
|
return MakeUnique<PKDescriptor>(std::move(pubkey));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Func("pkh", expr)) {
|
|
|
|
if (Func("pkh", expr)) {
|
|
|
|
auto pubkey = ParsePubkey(expr, ctx != ParseScriptContext::P2WSH, out);
|
|
|
|
auto pubkey = ParsePubkey(expr, ctx != ParseScriptContext::P2WSH, out);
|
|
|
|
if (!pubkey) return nullptr;
|
|
|
|
if (!pubkey) return nullptr;
|
|
|
|
return MakeUnique<SingleKeyDescriptor>(std::move(pubkey), P2PKHGetScript, "pkh");
|
|
|
|
return MakeUnique<PKHDescriptor>(std::move(pubkey));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ctx == ParseScriptContext::TOP && Func("combo", expr)) {
|
|
|
|
if (ctx == ParseScriptContext::TOP && Func("combo", expr)) {
|
|
|
|
auto pubkey = ParsePubkey(expr, true, out);
|
|
|
|
auto pubkey = ParsePubkey(expr, true, out);
|
|
|
@ -606,17 +627,17 @@ std::unique_ptr<Descriptor> ParseScript(Span<const char>& sp, ParseScriptContext
|
|
|
|
if (ctx != ParseScriptContext::P2WSH && Func("wpkh", expr)) {
|
|
|
|
if (ctx != ParseScriptContext::P2WSH && Func("wpkh", expr)) {
|
|
|
|
auto pubkey = ParsePubkey(expr, false, out);
|
|
|
|
auto pubkey = ParsePubkey(expr, false, out);
|
|
|
|
if (!pubkey) return nullptr;
|
|
|
|
if (!pubkey) return nullptr;
|
|
|
|
return MakeUnique<SingleKeyDescriptor>(std::move(pubkey), P2WPKHGetScript, "wpkh");
|
|
|
|
return MakeUnique<WPKHDescriptor>(std::move(pubkey));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ctx == ParseScriptContext::TOP && Func("sh", expr)) {
|
|
|
|
if (ctx == ParseScriptContext::TOP && Func("sh", expr)) {
|
|
|
|
auto desc = ParseScript(expr, ParseScriptContext::P2SH, out);
|
|
|
|
auto desc = ParseScript(expr, ParseScriptContext::P2SH, out);
|
|
|
|
if (!desc || expr.size()) return nullptr;
|
|
|
|
if (!desc || expr.size()) return nullptr;
|
|
|
|
return MakeUnique<ConvertorDescriptor>(std::move(desc), ConvertP2SH, "sh");
|
|
|
|
return MakeUnique<SHDescriptor>(std::move(desc));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ctx != ParseScriptContext::P2WSH && Func("wsh", expr)) {
|
|
|
|
if (ctx != ParseScriptContext::P2WSH && Func("wsh", expr)) {
|
|
|
|
auto desc = ParseScript(expr, ParseScriptContext::P2WSH, out);
|
|
|
|
auto desc = ParseScript(expr, ParseScriptContext::P2WSH, out);
|
|
|
|
if (!desc || expr.size()) return nullptr;
|
|
|
|
if (!desc || expr.size()) return nullptr;
|
|
|
|
return MakeUnique<ConvertorDescriptor>(std::move(desc), ConvertP2WSH, "wsh");
|
|
|
|
return MakeUnique<WSHDescriptor>(std::move(desc));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ctx == ParseScriptContext::TOP && Func("addr", expr)) {
|
|
|
|
if (ctx == ParseScriptContext::TOP && Func("addr", expr)) {
|
|
|
|
CTxDestination dest = DecodeDestination(std::string(expr.begin(), expr.end()));
|
|
|
|
CTxDestination dest = DecodeDestination(std::string(expr.begin(), expr.end()));
|
|
|
@ -650,7 +671,7 @@ std::unique_ptr<Descriptor> InferScript(const CScript& script, ParseScriptContex
|
|
|
|
if (txntype == TX_PUBKEY) {
|
|
|
|
if (txntype == TX_PUBKEY) {
|
|
|
|
CPubKey pubkey(data[0].begin(), data[0].end());
|
|
|
|
CPubKey pubkey(data[0].begin(), data[0].end());
|
|
|
|
if (pubkey.IsValid()) {
|
|
|
|
if (pubkey.IsValid()) {
|
|
|
|
return MakeUnique<SingleKeyDescriptor>(InferPubkey(pubkey, ctx, provider), P2PKGetScript, "pk");
|
|
|
|
return MakeUnique<PKDescriptor>(InferPubkey(pubkey, ctx, provider));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (txntype == TX_PUBKEYHASH) {
|
|
|
|
if (txntype == TX_PUBKEYHASH) {
|
|
|
@ -658,7 +679,7 @@ std::unique_ptr<Descriptor> InferScript(const CScript& script, ParseScriptContex
|
|
|
|
CKeyID keyid(hash);
|
|
|
|
CKeyID keyid(hash);
|
|
|
|
CPubKey pubkey;
|
|
|
|
CPubKey pubkey;
|
|
|
|
if (provider.GetPubKey(keyid, pubkey)) {
|
|
|
|
if (provider.GetPubKey(keyid, pubkey)) {
|
|
|
|
return MakeUnique<SingleKeyDescriptor>(InferPubkey(pubkey, ctx, provider), P2PKHGetScript, "pkh");
|
|
|
|
return MakeUnique<PKHDescriptor>(InferPubkey(pubkey, ctx, provider));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (txntype == TX_WITNESS_V0_KEYHASH && ctx != ParseScriptContext::P2WSH) {
|
|
|
|
if (txntype == TX_WITNESS_V0_KEYHASH && ctx != ParseScriptContext::P2WSH) {
|
|
|
@ -666,7 +687,7 @@ std::unique_ptr<Descriptor> InferScript(const CScript& script, ParseScriptContex
|
|
|
|
CKeyID keyid(hash);
|
|
|
|
CKeyID keyid(hash);
|
|
|
|
CPubKey pubkey;
|
|
|
|
CPubKey pubkey;
|
|
|
|
if (provider.GetPubKey(keyid, pubkey)) {
|
|
|
|
if (provider.GetPubKey(keyid, pubkey)) {
|
|
|
|
return MakeUnique<SingleKeyDescriptor>(InferPubkey(pubkey, ctx, provider), P2WPKHGetScript, "wpkh");
|
|
|
|
return MakeUnique<WPKHDescriptor>(InferPubkey(pubkey, ctx, provider));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (txntype == TX_MULTISIG) {
|
|
|
|
if (txntype == TX_MULTISIG) {
|
|
|
@ -683,7 +704,7 @@ std::unique_ptr<Descriptor> InferScript(const CScript& script, ParseScriptContex
|
|
|
|
CScript subscript;
|
|
|
|
CScript subscript;
|
|
|
|
if (provider.GetCScript(scriptid, subscript)) {
|
|
|
|
if (provider.GetCScript(scriptid, subscript)) {
|
|
|
|
auto sub = InferScript(subscript, ParseScriptContext::P2SH, provider);
|
|
|
|
auto sub = InferScript(subscript, ParseScriptContext::P2SH, provider);
|
|
|
|
if (sub) return MakeUnique<ConvertorDescriptor>(std::move(sub), ConvertP2SH, "sh");
|
|
|
|
if (sub) return MakeUnique<SHDescriptor>(std::move(sub));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (txntype == TX_WITNESS_V0_SCRIPTHASH && ctx != ParseScriptContext::P2WSH) {
|
|
|
|
if (txntype == TX_WITNESS_V0_SCRIPTHASH && ctx != ParseScriptContext::P2WSH) {
|
|
|
@ -692,7 +713,7 @@ std::unique_ptr<Descriptor> InferScript(const CScript& script, ParseScriptContex
|
|
|
|
CScript subscript;
|
|
|
|
CScript subscript;
|
|
|
|
if (provider.GetCScript(scriptid, subscript)) {
|
|
|
|
if (provider.GetCScript(scriptid, subscript)) {
|
|
|
|
auto sub = InferScript(subscript, ParseScriptContext::P2WSH, provider);
|
|
|
|
auto sub = InferScript(subscript, ParseScriptContext::P2WSH, provider);
|
|
|
|
if (sub) return MakeUnique<ConvertorDescriptor>(std::move(sub), ConvertP2WSH, "wsh");
|
|
|
|
if (sub) return MakeUnique<WSHDescriptor>(std::move(sub));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|