mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
descriptors: Add DescriptorImpl::Clone
This commit is contained in:
parent
7e86541f72
commit
0d55deae15
1 changed files with 81 additions and 0 deletions
|
@ -786,6 +786,8 @@ public:
|
||||||
arg->GetPubKeys(pubkeys, ext_pubs);
|
arg->GetPubKeys(pubkeys, ext_pubs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::unique_ptr<DescriptorImpl> Clone() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed addr(A) descriptor. */
|
/** A parsed addr(A) descriptor. */
|
||||||
|
@ -807,6 +809,10 @@ public:
|
||||||
bool ToPrivateString(const SigningProvider& arg, std::string& out) const final { return false; }
|
bool ToPrivateString(const SigningProvider& arg, std::string& out) const final { return false; }
|
||||||
|
|
||||||
std::optional<int64_t> ScriptSize() const override { return GetScriptForDestination(m_destination).size(); }
|
std::optional<int64_t> ScriptSize() const override { return GetScriptForDestination(m_destination).size(); }
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
return std::make_unique<AddressDescriptor>(m_destination);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed raw(H) descriptor. */
|
/** A parsed raw(H) descriptor. */
|
||||||
|
@ -830,6 +836,11 @@ public:
|
||||||
bool ToPrivateString(const SigningProvider& arg, std::string& out) const final { return false; }
|
bool ToPrivateString(const SigningProvider& arg, std::string& out) const final { return false; }
|
||||||
|
|
||||||
std::optional<int64_t> ScriptSize() const override { return m_script.size(); }
|
std::optional<int64_t> ScriptSize() const override { return m_script.size(); }
|
||||||
|
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
return std::make_unique<RawDescriptor>(m_script);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed pk(P) descriptor. */
|
/** A parsed pk(P) descriptor. */
|
||||||
|
@ -865,6 +876,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<int64_t> MaxSatisfactionElems() const override { return 1; }
|
std::optional<int64_t> MaxSatisfactionElems() const override { return 1; }
|
||||||
|
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
return std::make_unique<PKDescriptor>(m_pubkey_args.at(0)->Clone(), m_xonly);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed pkh(P) descriptor. */
|
/** A parsed pkh(P) descriptor. */
|
||||||
|
@ -894,6 +910,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<int64_t> MaxSatisfactionElems() const override { return 2; }
|
std::optional<int64_t> MaxSatisfactionElems() const override { return 2; }
|
||||||
|
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
return std::make_unique<PKHDescriptor>(m_pubkey_args.at(0)->Clone());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed wpkh(P) descriptor. */
|
/** A parsed wpkh(P) descriptor. */
|
||||||
|
@ -923,6 +944,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<int64_t> MaxSatisfactionElems() const override { return 2; }
|
std::optional<int64_t> MaxSatisfactionElems() const override { return 2; }
|
||||||
|
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
return std::make_unique<WPKHDescriptor>(m_pubkey_args.at(0)->Clone());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed combo(P) descriptor. */
|
/** A parsed combo(P) descriptor. */
|
||||||
|
@ -947,6 +973,10 @@ protected:
|
||||||
public:
|
public:
|
||||||
ComboDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), "combo") {}
|
ComboDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector(std::move(prov)), "combo") {}
|
||||||
bool IsSingleType() const final { return false; }
|
bool IsSingleType() const final { return false; }
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
return std::make_unique<ComboDescriptor>(m_pubkey_args.at(0)->Clone());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed multi(...) or sortedmulti(...) descriptor */
|
/** A parsed multi(...) or sortedmulti(...) descriptor */
|
||||||
|
@ -985,6 +1015,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<int64_t> MaxSatisfactionElems() const override { return 1 + m_threshold; }
|
std::optional<int64_t> MaxSatisfactionElems() const override { return 1 + m_threshold; }
|
||||||
|
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
std::vector<std::unique_ptr<PubkeyProvider>> providers;
|
||||||
|
providers.reserve(m_pubkey_args.size());
|
||||||
|
std::transform(m_pubkey_args.begin(), m_pubkey_args.end(), providers.begin(), [](const std::unique_ptr<PubkeyProvider>& p) { return p->Clone(); });
|
||||||
|
return std::make_unique<MultisigDescriptor>(m_threshold, std::move(providers), m_sorted);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed (sorted)multi_a(...) descriptor. Always uses x-only pubkeys. */
|
/** A parsed (sorted)multi_a(...) descriptor. Always uses x-only pubkeys. */
|
||||||
|
@ -1021,6 +1059,16 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<int64_t> MaxSatisfactionElems() const override { return m_pubkey_args.size(); }
|
std::optional<int64_t> MaxSatisfactionElems() const override { return m_pubkey_args.size(); }
|
||||||
|
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
std::vector<std::unique_ptr<PubkeyProvider>> providers;
|
||||||
|
providers.reserve(m_pubkey_args.size());
|
||||||
|
for (const auto& arg : m_pubkey_args) {
|
||||||
|
providers.push_back(arg->Clone());
|
||||||
|
}
|
||||||
|
return std::make_unique<MultiADescriptor>(m_threshold, std::move(providers), m_sorted);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed sh(...) descriptor. */
|
/** A parsed sh(...) descriptor. */
|
||||||
|
@ -1066,6 +1114,11 @@ public:
|
||||||
if (const auto sub_elems = m_subdescriptor_args[0]->MaxSatisfactionElems()) return 1 + *sub_elems;
|
if (const auto sub_elems = m_subdescriptor_args[0]->MaxSatisfactionElems()) return 1 + *sub_elems;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
return std::make_unique<SHDescriptor>(m_subdescriptor_args.at(0)->Clone());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed wsh(...) descriptor. */
|
/** A parsed wsh(...) descriptor. */
|
||||||
|
@ -1102,6 +1155,11 @@ public:
|
||||||
if (const auto sub_elems = m_subdescriptor_args[0]->MaxSatisfactionElems()) return 1 + *sub_elems;
|
if (const auto sub_elems = m_subdescriptor_args[0]->MaxSatisfactionElems()) return 1 + *sub_elems;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
return std::make_unique<WSHDescriptor>(m_subdescriptor_args.at(0)->Clone());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed tr(...) descriptor. */
|
/** A parsed tr(...) descriptor. */
|
||||||
|
@ -1167,6 +1225,14 @@ public:
|
||||||
// FIXME: See above, we assume keypath spend.
|
// FIXME: See above, we assume keypath spend.
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
std::vector<std::unique_ptr<DescriptorImpl>> subdescs;
|
||||||
|
subdescs.reserve(m_subdescriptor_args.size());
|
||||||
|
std::transform(m_subdescriptor_args.begin(), m_subdescriptor_args.end(), subdescs.begin(), [](const std::unique_ptr<DescriptorImpl>& d) { return d->Clone(); });
|
||||||
|
return std::make_unique<TRDescriptor>(m_pubkey_args.at(0)->Clone(), std::move(subdescs), m_depths);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* We instantiate Miniscript here with a simple integer as key type.
|
/* We instantiate Miniscript here with a simple integer as key type.
|
||||||
|
@ -1285,6 +1351,16 @@ public:
|
||||||
std::optional<int64_t> MaxSatisfactionElems() const override {
|
std::optional<int64_t> MaxSatisfactionElems() const override {
|
||||||
return m_node->GetStackSize();
|
return m_node->GetStackSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
std::vector<std::unique_ptr<PubkeyProvider>> providers;
|
||||||
|
providers.reserve(m_pubkey_args.size());
|
||||||
|
for (const auto& arg : m_pubkey_args) {
|
||||||
|
providers.push_back(arg->Clone());
|
||||||
|
}
|
||||||
|
return std::make_unique<MiniscriptDescriptor>(std::move(providers), miniscript::MakeNodeRef<uint32_t>(*m_node));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed rawtr(...) descriptor. */
|
/** A parsed rawtr(...) descriptor. */
|
||||||
|
@ -1315,6 +1391,11 @@ public:
|
||||||
// See above, we assume keypath spend.
|
// See above, we assume keypath spend.
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<DescriptorImpl> Clone() const override
|
||||||
|
{
|
||||||
|
return std::make_unique<RawTRDescriptor>(m_pubkey_args.at(0)->Clone());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Reference in a new issue