diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c060127854..0dc3da1738 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4486,4 +4486,25 @@ void CWallet::TopUpCallback(const std::set& spks, ScriptPubKeyMan* spkm // Update scriptPubKey cache CacheNewScriptPubKeys(spks, spkm); } + +std::set CWallet::GetActiveHDPubKeys() const +{ + AssertLockHeld(cs_wallet); + + Assert(IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)); + + std::set active_xpubs; + for (const auto& spkm : GetActiveScriptPubKeyMans()) { + const DescriptorScriptPubKeyMan* desc_spkm = dynamic_cast(spkm); + assert(desc_spkm); + LOCK(desc_spkm->cs_desc_man); + WalletDescriptor w_desc = desc_spkm->GetWalletDescriptor(); + + std::set desc_pubkeys; + std::set desc_xpubs; + w_desc.descriptor->GetPubKeys(desc_pubkeys, desc_xpubs); + active_xpubs.merge(std::move(desc_xpubs)); + } + return active_xpubs; +} } // namespace wallet diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 8586c09b59..83425fca6b 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1056,6 +1056,9 @@ public: void CacheNewScriptPubKeys(const std::set& spks, ScriptPubKeyMan* spkm); void TopUpCallback(const std::set& spks, ScriptPubKeyMan* spkm) override; + + //! Retrieve the xpubs in use by the active descriptors + std::set GetActiveHDPubKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); }; /**