Skip to content

Commit

Permalink
[backport#17304 17/18] Refactor: Move GetKeypoolSize code out of CWallet
Browse files Browse the repository at this point in the history
Summary:
This commit does not change behavior.

bitcoin/bitcoin@7ef47b8

---

Depends on D7163

Partial backport of Core [[bitcoin/bitcoin#17304 | PR17304]]

Test Plan:
  ninja check

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D7164
  • Loading branch information
achow101 authored and majcosta committed Aug 8, 2020
1 parent f3e3433 commit be3af3b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/wallet/scriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ 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);
auto it = mapKeyMetadata.find(CKeyID(id));
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/scriptpubkeyman.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class ScriptPubKeyMan {
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;
Expand Down Expand Up @@ -334,6 +335,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan,
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;

Expand Down
10 changes: 10 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3386,6 +3386,16 @@ 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;
if (auto spk_man = m_spk_man.get()) {
Expand Down
9 changes: 1 addition & 8 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1169,10 +1169,7 @@ class CWallet final : public WalletStorage,

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
Expand Down Expand Up @@ -1365,10 +1362,6 @@ class CWallet final : public WalletStorage,
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;
};
Expand Down

0 comments on commit be3af3b

Please sign in to comment.