diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -202,6 +202,7 @@ virtual int64_t GetOldestKeyPoolTime() { return GetTime(); } virtual size_t KeypoolCountExternalKeys() { return 0; } + virtual unsigned int GetKeyPoolSize() const { return 0; } virtual const CKeyMetadata *GetMetadata(uint160 id) const { return nullptr; @@ -334,6 +335,7 @@ int64_t GetOldestKeyPoolTime() override; size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + unsigned int GetKeyPoolSize() const override; const CKeyMetadata *GetMetadata(uint160 id) const override; diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -419,6 +419,11 @@ return setExternalKeyPool.size() + set_pre_split_keypool.size(); } +unsigned int LegacyScriptPubKeyMan::GetKeyPoolSize() const { + AssertLockHeld(cs_wallet); + return setInternalKeyPool.size() + setExternalKeyPool.size(); +} + const CKeyMetadata *LegacyScriptPubKeyMan::GetMetadata(uint160 id) const { AssertLockHeld(cs_wallet); auto it = mapKeyMetadata.find(CKeyID(id)); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1169,10 +1169,7 @@ bool DelAddressBook(const CTxDestination &address); - unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { - AssertLockHeld(cs_wallet); - return setInternalKeyPool.size() + setExternalKeyPool.size(); - } + unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); //! signify that a particular wallet feature is now used. this may change //! nWalletVersion and nWalletMaxVersion if those are lower @@ -1365,10 +1362,6 @@ mapWatchKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapWatchKeys; WalletBatch *& encrypted_batch GUARDED_BY(cs_wallet) = m_spk_man->encrypted_batch; - std::set &setInternalKeyPool GUARDED_BY(cs_wallet) = - m_spk_man->setInternalKeyPool; - std::set &setExternalKeyPool GUARDED_BY(cs_wallet) = - m_spk_man->setExternalKeyPool; int64_t &nTimeFirstKey GUARDED_BY(cs_wallet) = m_spk_man->nTimeFirstKey; using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap; }; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3386,6 +3386,16 @@ return count; } +unsigned int CWallet::GetKeyPoolSize() const { + AssertLockHeld(cs_wallet); + + unsigned int count = 0; + if (auto spk_man = m_spk_man.get()) { + count += spk_man->GetKeyPoolSize(); + } + return count; +} + bool CWallet::TopUpKeyPool(unsigned int kpSize) { bool res = true; if (auto spk_man = m_spk_man.get()) {