mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-25 13:51:05 +02:00
wallet: Be able to retrieve single key from descriptors
Adds CWallet::GetKey which retrieves a single key from the descriptors stored in the wallet.
This commit is contained in:
@@ -4507,4 +4507,19 @@ std::set<CExtPubKey> CWallet::GetActiveHDPubKeys() const
|
||||
}
|
||||
return active_xpubs;
|
||||
}
|
||||
|
||||
std::optional<CKey> CWallet::GetKey(const CKeyID& keyid) const
|
||||
{
|
||||
Assert(IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
|
||||
|
||||
for (const auto& spkm : GetAllScriptPubKeyMans()) {
|
||||
const DescriptorScriptPubKeyMan* desc_spkm = dynamic_cast<DescriptorScriptPubKeyMan*>(spkm);
|
||||
assert(desc_spkm);
|
||||
LOCK(desc_spkm->cs_desc_man);
|
||||
if (std::optional<CKey> key = desc_spkm->GetKey(keyid)) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace wallet
|
||||
|
@@ -1059,6 +1059,10 @@ public:
|
||||
|
||||
//! Retrieve the xpubs in use by the active descriptors
|
||||
std::set<CExtPubKey> GetActiveHDPubKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
|
||||
//! Find the private key for the given key id from the wallet's descriptors, if available
|
||||
//! Returns nullopt when no descriptor has the key or if the wallet is locked.
|
||||
std::optional<CKey> GetKey(const CKeyID& keyid) const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user