descriptors: Add PubkeyProvider::Clone

This commit is contained in:
Ava Chow 2024-08-07 16:28:57 -04:00
parent 79b8472040
commit 7e86541f72

View File

@ -219,6 +219,9 @@ public:
virtual std::optional<CPubKey> GetRootPubKey() const = 0; virtual std::optional<CPubKey> GetRootPubKey() const = 0;
/** Return the extended public key for this PubkeyProvider, if it has one. */ /** Return the extended public key for this PubkeyProvider, if it has one. */
virtual std::optional<CExtPubKey> GetRootExtPubKey() const = 0; virtual std::optional<CExtPubKey> GetRootExtPubKey() const = 0;
/** Make a deep copy of this PubkeyProvider */
virtual std::unique_ptr<PubkeyProvider> Clone() const = 0;
}; };
class OriginPubkeyProvider final : public PubkeyProvider class OriginPubkeyProvider final : public PubkeyProvider
@ -280,6 +283,10 @@ public:
{ {
return m_provider->GetRootExtPubKey(); return m_provider->GetRootExtPubKey();
} }
std::unique_ptr<PubkeyProvider> Clone() const override
{
return std::make_unique<OriginPubkeyProvider>(m_expr_index, m_origin, m_provider->Clone(), m_apostrophe);
}
}; };
/** An object representing a parsed constant public key in a descriptor. */ /** An object representing a parsed constant public key in a descriptor. */
@ -333,6 +340,10 @@ public:
{ {
return std::nullopt; return std::nullopt;
} }
std::unique_ptr<PubkeyProvider> Clone() const override
{
return std::make_unique<ConstPubkeyProvider>(m_expr_index, m_pubkey, m_xonly);
}
}; };
enum class DeriveType { enum class DeriveType {
@ -556,6 +567,10 @@ public:
{ {
return m_root_extkey; return m_root_extkey;
} }
std::unique_ptr<PubkeyProvider> Clone() const override
{
return std::make_unique<BIP32PubkeyProvider>(m_expr_index, m_root_extkey, m_path, m_derive, m_apostrophe);
}
}; };
/** Base class for all Descriptor implementations. */ /** Base class for all Descriptor implementations. */