Merge #7816: [Wallet] slighly refactor GetOldestKeyPoolTime()

9f7336b [Wallet] slightly refactor GetOldestKeyPoolTime() (Jonas Schnelli)
This commit is contained in:
Wladimir J. van der Laan 2016-04-22 08:36:22 +02:00
commit 0c95ebce7e
No known key found for this signature in database
GPG key ID: 74810B012346C9A6

View file

@ -2616,12 +2616,19 @@ bool CWallet::GetKeyFromPool(CPubKey& result)
int64_t CWallet::GetOldestKeyPoolTime()
{
int64_t nIndex = 0;
CKeyPool keypool;
ReserveKeyFromKeyPool(nIndex, keypool);
if (nIndex == -1)
LOCK(cs_wallet);
// if the keypool is empty, return <NOW>
if (setKeyPool.empty())
return GetTime();
ReturnKey(nIndex);
// load oldest key from keypool, get time and return
CKeyPool keypool;
CWalletDB walletdb(strWalletFile);
int64_t nIndex = *(setKeyPool.begin());
if (!walletdb.ReadPool(nIndex, keypool))
throw runtime_error("GetOldestKeyPoolTime(): read oldest key in keypool failed");
assert(keypool.vchPubKey.IsValid());
return keypool.nTime;
}