Skip to content

Commit 85b1fb1

Browse files
committed
wallet: Add GetActiveHDPubKeys to retrieve xpubs from active descriptors
1 parent 73926f2 commit 85b1fb1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/wallet/wallet.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4486,4 +4486,25 @@ void CWallet::TopUpCallback(const std::set<CScript>& spks, ScriptPubKeyMan* spkm
44864486
// Update scriptPubKey cache
44874487
CacheNewScriptPubKeys(spks, spkm);
44884488
}
4489+
4490+
std::set<CExtPubKey> CWallet::GetActiveHDPubKeys() const
4491+
{
4492+
AssertLockHeld(cs_wallet);
4493+
4494+
Assert(IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
4495+
4496+
std::set<CExtPubKey> active_xpubs;
4497+
for (const auto& spkm : GetActiveScriptPubKeyMans()) {
4498+
const DescriptorScriptPubKeyMan* desc_spkm = dynamic_cast<DescriptorScriptPubKeyMan*>(spkm);
4499+
assert(desc_spkm);
4500+
LOCK(desc_spkm->cs_desc_man);
4501+
WalletDescriptor w_desc = desc_spkm->GetWalletDescriptor();
4502+
4503+
std::set<CPubKey> desc_pubkeys;
4504+
std::set<CExtPubKey> desc_xpubs;
4505+
w_desc.descriptor->GetPubKeys(desc_pubkeys, desc_xpubs);
4506+
active_xpubs.merge(std::move(desc_xpubs));
4507+
}
4508+
return active_xpubs;
4509+
}
44894510
} // namespace wallet

src/wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,9 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
10561056
void CacheNewScriptPubKeys(const std::set<CScript>& spks, ScriptPubKeyMan* spkm);
10571057

10581058
void TopUpCallback(const std::set<CScript>& spks, ScriptPubKeyMan* spkm) override;
1059+
1060+
//! Retrieve the xpubs in use by the active descriptors
1061+
std::set<CExtPubKey> GetActiveHDPubKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
10591062
};
10601063

10611064
/**

0 commit comments

Comments
 (0)