diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2016-11-08 16:28:20 -0500 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2017-02-10 15:49:00 -0500 |
commit | a58370e6a2d4dce50eefbcab5bde9f14facef8fc (patch) | |
tree | b5c4fd59bba41e4383f1536d908f0fcedbe176f8 /src/wallet/wallet.cpp | |
parent | 266a8114cbe2a87a6c84d7690a7716a18d782c56 (diff) | |
download | bitcoin-a58370e6a2d4dce50eefbcab5bde9f14facef8fc.tar.xz |
Dedup nTimeFirstKey update logic
Also make nTimeFirstKey member variable private.
This is just a cleanup change, it doesn't change behavior in any significant
way.
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a5e8752fc0..192af22cb8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -113,8 +113,7 @@ CPubKey CWallet::GenerateNewKey() assert(secret.VerifyPubKey(pubkey)); mapKeyMetadata[pubkey.GetID()] = metadata; - if (!nTimeFirstKey || nCreationTime < nTimeFirstKey) - nTimeFirstKey = nCreationTime; + UpdateTimeFirstKey(nCreationTime); if (!AddKeyPubKey(secret, pubkey)) throw std::runtime_error(std::string(__func__) + ": AddKey failed"); @@ -210,9 +209,7 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, bool CWallet::LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &meta) { AssertLockHeld(cs_wallet); // mapKeyMetadata - if (meta.nCreateTime && (!nTimeFirstKey || meta.nCreateTime < nTimeFirstKey)) - nTimeFirstKey = meta.nCreateTime; - + UpdateTimeFirstKey(meta.nCreateTime); mapKeyMetadata[pubkey.GetID()] = meta; return true; } @@ -222,6 +219,18 @@ bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigne return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); } +void CWallet::UpdateTimeFirstKey(int64_t nCreateTime) +{ + AssertLockHeld(cs_wallet); + if (nCreateTime <= 1) { + // Cannot determine birthday information, so set the wallet birthday to + // the beginning of time. + nTimeFirstKey = 1; + } else if (!nTimeFirstKey || nCreateTime < nTimeFirstKey) { + nTimeFirstKey = nCreateTime; + } +} + bool CWallet::AddCScript(const CScript& redeemScript) { if (!CCryptoKeyStore::AddCScript(redeemScript)) |