Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/wallet/scriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,13 @@ bool LegacyScriptPubKeyMan::CanGetAddresses(bool internal)
return keypool_has_keys;
}

static int64_t GetOldestKeyInPool(const std::set<int64_t>& setKeyPool, WalletBatch& batch) {
static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, WalletBatch& batch)
{
if (setKeyPool.empty()) {
// if the keypool is empty, return <NOW>
return GetTime();
}

CKeyPool keypool;
int64_t nIndex = *(setKeyPool.begin());
if (!batch.ReadPool(nIndex, keypool)) {
Expand All @@ -629,19 +635,10 @@ int64_t LegacyScriptPubKeyMan::GetOldestKeyPoolTime()
{
LOCK(cs_wallet);

// if the keypool is empty, return <NOW>
if (setExternalKeyPool.empty() && setInternalKeyPool.empty())
return GetTime();

WalletBatch batch(m_storage.GetDatabase());
int64_t oldestKey = -1;

// load oldest key from keypool, get time and return
if (!setInternalKeyPool.empty()) {
oldestKey = std::max(GetOldestKeyInPool(setInternalKeyPool, batch), oldestKey);
}
if (!setExternalKeyPool.empty()) {
oldestKey = std::max(GetOldestKeyInPool(setExternalKeyPool, batch), oldestKey);
int64_t oldestKey = GetOldestKeyTimeInPool(setExternalKeyPool, batch);
if (IsHDEnabled()) {
oldestKey = std::max(GetOldestKeyTimeInPool(setInternalKeyPool, batch), oldestKey);
}
return oldestKey;
}
Expand Down