mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 05:32:22 +02:00
wallet: add GetExtKey helper
Reconstruct a descriptor's extended private key from its xpub by looking up the corresponding private key. This is the extended-key analog of GetKey() and is used by the derivehdkey RPC in the following commit.
This commit is contained in:
@@ -4572,6 +4572,14 @@ std::optional<CKey> CWallet::GetKey(const CKeyID& keyid) const
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<CExtKey> CWallet::GetExtKey(const CExtPubKey& xpub) const
|
||||
{
|
||||
if (std::optional<CKey> key = GetKey(xpub.pubkey.GetID())) {
|
||||
return CExtKey{xpub, *key};
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void CWallet::WriteBestBlock() const
|
||||
{
|
||||
AssertLockHeld(cs_wallet);
|
||||
|
||||
@@ -1091,6 +1091,10 @@ public:
|
||||
//! Returns nullopt when no descriptor has the key or if the wallet is locked.
|
||||
std::optional<CKey> GetKey(const CKeyID& keyid) const;
|
||||
|
||||
//! Reconstruct the extended private key for an HD xpub. Returns nullopt when
|
||||
//! no descriptor has the private key, or the wallet is locked.
|
||||
std::optional<CExtKey> GetExtKey(const CExtPubKey& xpub) const;
|
||||
|
||||
//! Disconnect chain notifications and wait for all notifications to be processed
|
||||
void DisconnectChainNotifications();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user