diff options
author | Jonas Schnelli <dev@jonasschnelli.ch> | 2017-01-17 09:43:12 +0100 |
---|---|---|
committer | Jonas Schnelli <dev@jonasschnelli.ch> | 2017-03-24 10:28:39 +0100 |
commit | add38d9b83fe570a16ccda8e3c2642cb3b0b1f2f (patch) | |
tree | 59949eeb48f6e7361bf74ecf17aeb4c7fb1196d8 /src | |
parent | dd526c2a2d2f0f7427047891a5e94b4e6c18b190 (diff) |
GetOldestKeyPoolTime: if HD & HD Chain Split is enabled, response max(oldest-internal-key, oldest-external-key)
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/wallet.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7687810794..7da45587bf 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3056,9 +3056,27 @@ int64_t CWallet::GetOldestKeyPoolTime() if (setKeyPool.empty()) return GetTime(); - // load oldest key from keypool, get time and return CKeyPool keypool; CWalletDB walletdb(strWalletFile); + + if (IsHDEnabled() && CanSupportFeature(FEATURE_HD_SPLIT)) + { + // if HD & HD Chain Split is enabled, response max(oldest-internal-key, oldest-external-key) + int64_t now = GetTime(); + int64_t oldest_external = now, oldest_internal = now; + + for(const int64_t& id : setKeyPool) + { + if (!walletdb.ReadPool(id, keypool)) + throw std::runtime_error(std::string(__func__) + ": read failed"); + if (keypool.fInternal && keypool.nTime < oldest_internal) + oldest_internal = keypool.nTime; + else if (!keypool.fInternal && keypool.nTime < oldest_external) + oldest_external = keypool.nTime; + } + return std::max(oldest_internal, oldest_external); + } + // load oldest key from keypool, get time and return int64_t nIndex = *(setKeyPool.begin()); if (!walletdb.ReadPool(nIndex, keypool)) throw std::runtime_error(std::string(__func__) + ": read oldest key in keypool failed"); |