diff options
| author | Andrew Chow <[email protected]> | 2019-10-07 14:11:34 -0400 |
|---|---|---|
| committer | Andrew Chow <[email protected]> | 2019-11-01 22:58:05 -0400 |
| commit | 089e17d45c8147bd0303bcbf02dc0f7d6b387f2a (patch) | |
| tree | d0aef56cc5aa8f662f15d4e590611cbd6a6a93ed /src/wallet | |
| parent | Refactor: Move SetupGeneration code out of CWallet (diff) | |
| download | discoin-089e17d45c8147bd0303bcbf02dc0f7d6b387f2a.tar.xz discoin-089e17d45c8147bd0303bcbf02dc0f7d6b387f2a.zip | |
Refactor: Move RewriteDB code out of CWallet
This commit does not change behavior.
Diffstat (limited to 'src/wallet')
| -rw-r--r-- | src/wallet/scriptpubkeyman.cpp | 11 | ||||
| -rw-r--r-- | src/wallet/scriptpubkeyman.h | 5 | ||||
| -rw-r--r-- | src/wallet/wallet.cpp | 28 |
3 files changed, 25 insertions, 19 deletions
diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 14e4163be..8c3a2a831 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -415,6 +415,17 @@ bool LegacyScriptPubKeyMan::HavePrivateKeys() const return !mapKeys.empty() || !mapCryptedKeys.empty(); } +void LegacyScriptPubKeyMan::RewriteDB() +{ + AssertLockHeld(cs_wallet); + setInternalKeyPool.clear(); + setExternalKeyPool.clear(); + m_pool_key_to_index.clear(); + // Note: can't top-up keypool here, because wallet is locked. + // User will be prompted to unlock wallet the next operation + // that requires a new key. +} + static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, WalletBatch& batch) { if (setKeyPool.empty()) { return GetTime(); diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index 0e38cbf65..24b0a2788 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -176,6 +176,9 @@ public: virtual bool HavePrivateKeys() const { return false; } + //! The action to do when the DB needs rewrite + virtual void RewriteDB() {} + virtual int64_t GetOldestKeyPoolTime() { return GetTime(); } virtual size_t KeypoolCountExternalKeys() { return 0; } @@ -288,6 +291,8 @@ public: bool HavePrivateKeys() const override; + void RewriteDB() override; + int64_t GetOldestKeyPoolTime() override; size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1b27077d6..575ae7e04 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2903,12 +2903,9 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet) { if (database->Rewrite("\x04pool")) { - setInternalKeyPool.clear(); - setExternalKeyPool.clear(); - m_spk_man->m_pool_key_to_index.clear(); - // Note: can't top-up keypool here, because wallet is locked. - // User will be prompted to unlock wallet the next operation - // that requires a new key. + if (auto spk_man = m_spk_man.get()) { + spk_man->RewriteDB(); + } } } @@ -2940,12 +2937,9 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256 { if (database->Rewrite("\x04pool")) { - setInternalKeyPool.clear(); - setExternalKeyPool.clear(); - m_spk_man->m_pool_key_to_index.clear(); - // Note: can't top-up keypool here, because wallet is locked. - // User will be prompted to unlock wallet the next operation - // that requires a new key. + if (auto spk_man = m_spk_man.get()) { + spk_man->RewriteDB(); + } } } @@ -2964,13 +2958,9 @@ DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx>& vWtx) { if (database->Rewrite("\x04pool")) { - LOCK(cs_wallet); - setInternalKeyPool.clear(); - setExternalKeyPool.clear(); - m_spk_man->m_pool_key_to_index.clear(); - // Note: can't top-up keypool here, because wallet is locked. - // User will be prompted to unlock wallet the next operation - // that requires a new key. + if (auto spk_man = m_spk_man.get()) { + spk_man->RewriteDB(); + } } } |