aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
authorJonas Schnelli <dev@jonasschnelli.ch>2016-04-05 10:45:11 +0200
committerJonas Schnelli <dev@jonasschnelli.ch>2016-04-06 11:06:25 +0200
commit9f7336b4575b15193151dbf08b09562529a24363 (patch)
tree40bfe918695c7b9e4addd658763c31c958b18e7c /src/wallet/wallet.cpp
parenta9149688f87cb790a600400abd9af72c3ee0c312 (diff)
downloadbitcoin-9f7336b4575b15193151dbf08b09562529a24363.tar.xz
[Wallet] slightly refactor GetOldestKeyPoolTime()
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index e8c9466710..15b9af852b 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2611,12 +2611,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;
}