mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-21 06:12:30 +02:00
Refactor: Move RewriteDB code out of CWallet
This commit does not change behavior.
This commit is contained in:
parent
0eac7088ab
commit
089e17d45c
@ -415,6 +415,17 @@ bool LegacyScriptPubKeyMan::HavePrivateKeys() const
|
|||||||
return !mapKeys.empty() || !mapCryptedKeys.empty();
|
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) {
|
static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, WalletBatch& batch) {
|
||||||
if (setKeyPool.empty()) {
|
if (setKeyPool.empty()) {
|
||||||
return GetTime();
|
return GetTime();
|
||||||
|
@ -176,6 +176,9 @@ public:
|
|||||||
|
|
||||||
virtual bool HavePrivateKeys() const { return false; }
|
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 int64_t GetOldestKeyPoolTime() { return GetTime(); }
|
||||||
|
|
||||||
virtual size_t KeypoolCountExternalKeys() { return 0; }
|
virtual size_t KeypoolCountExternalKeys() { return 0; }
|
||||||
@ -288,6 +291,8 @@ public:
|
|||||||
|
|
||||||
bool HavePrivateKeys() const override;
|
bool HavePrivateKeys() const override;
|
||||||
|
|
||||||
|
void RewriteDB() override;
|
||||||
|
|
||||||
int64_t GetOldestKeyPoolTime() override;
|
int64_t GetOldestKeyPoolTime() override;
|
||||||
size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
|
|
||||||
|
@ -2903,12 +2903,9 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
|
|||||||
{
|
{
|
||||||
if (database->Rewrite("\x04pool"))
|
if (database->Rewrite("\x04pool"))
|
||||||
{
|
{
|
||||||
setInternalKeyPool.clear();
|
if (auto spk_man = m_spk_man.get()) {
|
||||||
setExternalKeyPool.clear();
|
spk_man->RewriteDB();
|
||||||
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.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2940,12 +2937,9 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
|
|||||||
{
|
{
|
||||||
if (database->Rewrite("\x04pool"))
|
if (database->Rewrite("\x04pool"))
|
||||||
{
|
{
|
||||||
setInternalKeyPool.clear();
|
if (auto spk_man = m_spk_man.get()) {
|
||||||
setExternalKeyPool.clear();
|
spk_man->RewriteDB();
|
||||||
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.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2964,13 +2958,9 @@ DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx>& vWtx)
|
|||||||
{
|
{
|
||||||
if (database->Rewrite("\x04pool"))
|
if (database->Rewrite("\x04pool"))
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
if (auto spk_man = m_spk_man.get()) {
|
||||||
setInternalKeyPool.clear();
|
spk_man->RewriteDB();
|
||||||
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.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user