Skip to content

Commit 7ef47b8

Browse files
committed
Refactor: Move GetKeypoolSize code out of CWallet
This commit does not change behavior.
1 parent 089e17d commit 7ef47b8

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,12 @@ size_t LegacyScriptPubKeyMan::KeypoolCountExternalKeys()
464464
return setExternalKeyPool.size() + set_pre_split_keypool.size();
465465
}
466466

467+
unsigned int LegacyScriptPubKeyMan::GetKeyPoolSize() const
468+
{
469+
AssertLockHeld(cs_wallet);
470+
return setInternalKeyPool.size() + setExternalKeyPool.size();
471+
}
472+
467473
const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(uint160 id) const
468474
{
469475
AssertLockHeld(cs_wallet);

src/wallet/scriptpubkeyman.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class ScriptPubKeyMan
182182
virtual int64_t GetOldestKeyPoolTime() { return GetTime(); }
183183

184184
virtual size_t KeypoolCountExternalKeys() { return 0; }
185+
virtual unsigned int GetKeyPoolSize() const { return 0; }
185186

186187
virtual const CKeyMetadata* GetMetadata(uint160 id) const { return nullptr; }
187188
};
@@ -295,6 +296,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
295296

296297
int64_t GetOldestKeyPoolTime() override;
297298
size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
299+
unsigned int GetKeyPoolSize() const override;
298300

299301
const CKeyMetadata* GetMetadata(uint160 id) const override;
300302

src/wallet/wallet.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,17 @@ size_t CWallet::KeypoolCountExternalKeys()
30273027
return count;
30283028
}
30293029

3030+
unsigned int CWallet::GetKeyPoolSize() const
3031+
{
3032+
AssertLockHeld(cs_wallet);
3033+
3034+
unsigned int count = 0;
3035+
if (auto spk_man = m_spk_man.get()) {
3036+
count += spk_man->GetKeyPoolSize();
3037+
}
3038+
return count;
3039+
}
3040+
30303041
bool CWallet::TopUpKeyPool(unsigned int kpSize)
30313042
{
30323043
bool res = true;

src/wallet/wallet.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -992,11 +992,7 @@ class CWallet final : public WalletStorage, private interfaces::Chain::Notificat
992992

993993
bool DelAddressBook(const CTxDestination& address);
994994

995-
unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
996-
{
997-
AssertLockHeld(cs_wallet);
998-
return setInternalKeyPool.size() + setExternalKeyPool.size();
999-
}
995+
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
1000996

1001997
//! signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower
1002998
void SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr, bool fExplicit = false) override;
@@ -1131,8 +1127,6 @@ class CWallet final : public WalletStorage, private interfaces::Chain::Notificat
11311127
LegacyScriptPubKeyMan::WatchOnlySet& setWatchOnly GUARDED_BY(cs_KeyStore) = m_spk_man->setWatchOnly;
11321128
LegacyScriptPubKeyMan::WatchKeyMap& mapWatchKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapWatchKeys;
11331129
WalletBatch*& encrypted_batch GUARDED_BY(cs_wallet) = m_spk_man->encrypted_batch;
1134-
std::set<int64_t>& setInternalKeyPool GUARDED_BY(cs_wallet) = m_spk_man->setInternalKeyPool;
1135-
std::set<int64_t>& setExternalKeyPool GUARDED_BY(cs_wallet) = m_spk_man->setExternalKeyPool;
11361130
int64_t& nTimeFirstKey GUARDED_BY(cs_wallet) = m_spk_man->nTimeFirstKey;
11371131
using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap;
11381132
};

0 commit comments

Comments
 (0)