Refactor: Move GetKeypoolSize code out of CWallet

This commit does not change behavior.
This commit is contained in:
Andrew Chow 2019-10-07 14:11:34 -04:00
parent 089e17d45c
commit 7ef47b88e6
4 changed files with 20 additions and 7 deletions

View File

@ -464,6 +464,12 @@ size_t LegacyScriptPubKeyMan::KeypoolCountExternalKeys()
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);

View File

@ -182,6 +182,7 @@ public:
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; }
};
@ -295,6 +296,7 @@ public:
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;

View File

@ -3027,6 +3027,17 @@ size_t CWallet::KeypoolCountExternalKeys()
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;

View File

@ -992,11 +992,7 @@ public:
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
void SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr, bool fExplicit = false) override;
@ -1131,8 +1127,6 @@ public:
LegacyScriptPubKeyMan::WatchOnlySet& setWatchOnly GUARDED_BY(cs_KeyStore) = m_spk_man->setWatchOnly;
LegacyScriptPubKeyMan::WatchKeyMap& mapWatchKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapWatchKeys;
WalletBatch*& encrypted_batch GUARDED_BY(cs_wallet) = m_spk_man->encrypted_batch;
std::set<int64_t>& setInternalKeyPool GUARDED_BY(cs_wallet) = m_spk_man->setInternalKeyPool;
std::set<int64_t>& setExternalKeyPool GUARDED_BY(cs_wallet) = m_spk_man->setExternalKeyPool;
int64_t& nTimeFirstKey GUARDED_BY(cs_wallet) = m_spk_man->nTimeFirstKey;
using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap;
};