mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-21 09:32:39 +02:00
descriptor: Be able to get the pubkeys involved in a descriptor
This commit is contained in:
parent
ef6745879d
commit
fe67841464
@ -212,6 +212,11 @@ public:
|
|||||||
|
|
||||||
/** Derive a private key, if private data is available in arg. */
|
/** Derive a private key, if private data is available in arg. */
|
||||||
virtual bool GetPrivKey(int pos, const SigningProvider& arg, CKey& key) const = 0;
|
virtual bool GetPrivKey(int pos, const SigningProvider& arg, CKey& key) const = 0;
|
||||||
|
|
||||||
|
/** Return the non-extended public key for this PubkeyProvider, if it has one. */
|
||||||
|
virtual std::optional<CPubKey> GetRootPubKey() const = 0;
|
||||||
|
/** Return the extended public key for this PubkeyProvider, if it has one. */
|
||||||
|
virtual std::optional<CExtPubKey> GetRootExtPubKey() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OriginPubkeyProvider final : public PubkeyProvider
|
class OriginPubkeyProvider final : public PubkeyProvider
|
||||||
@ -265,6 +270,14 @@ public:
|
|||||||
{
|
{
|
||||||
return m_provider->GetPrivKey(pos, arg, key);
|
return m_provider->GetPrivKey(pos, arg, key);
|
||||||
}
|
}
|
||||||
|
std::optional<CPubKey> GetRootPubKey() const override
|
||||||
|
{
|
||||||
|
return m_provider->GetRootPubKey();
|
||||||
|
}
|
||||||
|
std::optional<CExtPubKey> GetRootExtPubKey() const override
|
||||||
|
{
|
||||||
|
return m_provider->GetRootExtPubKey();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** An object representing a parsed constant public key in a descriptor. */
|
/** An object representing a parsed constant public key in a descriptor. */
|
||||||
@ -310,6 +323,14 @@ public:
|
|||||||
{
|
{
|
||||||
return arg.GetKey(m_pubkey.GetID(), key);
|
return arg.GetKey(m_pubkey.GetID(), key);
|
||||||
}
|
}
|
||||||
|
std::optional<CPubKey> GetRootPubKey() const override
|
||||||
|
{
|
||||||
|
return m_pubkey;
|
||||||
|
}
|
||||||
|
std::optional<CExtPubKey> GetRootExtPubKey() const override
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class DeriveType {
|
enum class DeriveType {
|
||||||
@ -525,6 +546,14 @@ public:
|
|||||||
key = extkey.key;
|
key = extkey.key;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
std::optional<CPubKey> GetRootPubKey() const override
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
std::optional<CExtPubKey> GetRootExtPubKey() const override
|
||||||
|
{
|
||||||
|
return m_root_extkey;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Base class for all Descriptor implementations. */
|
/** Base class for all Descriptor implementations. */
|
||||||
@ -720,6 +749,19 @@ public:
|
|||||||
std::optional<int64_t> MaxSatisfactionWeight(bool) const override { return {}; }
|
std::optional<int64_t> MaxSatisfactionWeight(bool) const override { return {}; }
|
||||||
|
|
||||||
std::optional<int64_t> MaxSatisfactionElems() const override { return {}; }
|
std::optional<int64_t> MaxSatisfactionElems() const override { return {}; }
|
||||||
|
|
||||||
|
void GetPubKeys(std::set<CPubKey>& pubkeys, std::set<CExtPubKey>& ext_pubs) const override
|
||||||
|
{
|
||||||
|
for (const auto& p : m_pubkey_args) {
|
||||||
|
std::optional<CPubKey> pub = p->GetRootPubKey();
|
||||||
|
if (pub) pubkeys.insert(*pub);
|
||||||
|
std::optional<CExtPubKey> ext_pub = p->GetRootExtPubKey();
|
||||||
|
if (ext_pub) ext_pubs.insert(*ext_pub);
|
||||||
|
}
|
||||||
|
for (const auto& arg : m_subdescriptor_args) {
|
||||||
|
arg->GetPubKeys(pubkeys, ext_pubs);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A parsed addr(A) descriptor. */
|
/** A parsed addr(A) descriptor. */
|
||||||
|
@ -158,6 +158,13 @@ struct Descriptor {
|
|||||||
|
|
||||||
/** Get the maximum size number of stack elements for satisfying this descriptor. */
|
/** Get the maximum size number of stack elements for satisfying this descriptor. */
|
||||||
virtual std::optional<int64_t> MaxSatisfactionElems() const = 0;
|
virtual std::optional<int64_t> MaxSatisfactionElems() const = 0;
|
||||||
|
|
||||||
|
/** Return all (extended) public keys for this descriptor, including any from subdescriptors.
|
||||||
|
*
|
||||||
|
* @param[out] pubkeys Any public keys
|
||||||
|
* @param[out] ext_pubs Any extended public keys
|
||||||
|
*/
|
||||||
|
virtual void GetPubKeys(std::set<CPubKey>& pubkeys, std::set<CExtPubKey>& ext_pubs) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Parse a `descriptor` string. Included private keys are put in `out`.
|
/** Parse a `descriptor` string. Included private keys are put in `out`.
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
std::optional<int64_t> ScriptSize() const override { return {}; }
|
std::optional<int64_t> ScriptSize() const override { return {}; }
|
||||||
std::optional<int64_t> MaxSatisfactionWeight(bool) const override { return {}; }
|
std::optional<int64_t> MaxSatisfactionWeight(bool) const override { return {}; }
|
||||||
std::optional<int64_t> MaxSatisfactionElems() const override { return {}; }
|
std::optional<int64_t> MaxSatisfactionElems() const override { return {}; }
|
||||||
|
void GetPubKeys(std::set<CPubKey>& pubkeys, std::set<CExtPubKey>& ext_pubs) const override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(wallet_load_descriptors, TestingSetup)
|
BOOST_FIXTURE_TEST_CASE(wallet_load_descriptors, TestingSetup)
|
||||||
|
Loading…
Reference in New Issue
Block a user