@@ -113,8 +113,7 @@ CPubKey CWallet::GenerateNewKey()
113113 assert (secret.VerifyPubKey (pubkey));
114114
115115 mapKeyMetadata[pubkey.GetID ()] = metadata;
116- if (!nTimeFirstKey || nCreationTime < nTimeFirstKey)
117- nTimeFirstKey = nCreationTime;
116+ UpdateTimeFirstKey (nCreationTime);
118117
119118 if (!AddKeyPubKey (secret, pubkey))
120119 throw std::runtime_error (std::string (__func__) + " : AddKey failed" );
@@ -210,9 +209,7 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey,
210209bool CWallet::LoadKeyMetadata (const CPubKey &pubkey, const CKeyMetadata &meta)
211210{
212211 AssertLockHeld (cs_wallet); // mapKeyMetadata
213- if (meta.nCreateTime && (!nTimeFirstKey || meta.nCreateTime < nTimeFirstKey))
214- nTimeFirstKey = meta.nCreateTime ;
215-
212+ UpdateTimeFirstKey (meta.nCreateTime );
216213 mapKeyMetadata[pubkey.GetID ()] = meta;
217214 return true ;
218215}
@@ -222,6 +219,18 @@ bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigne
222219 return CCryptoKeyStore::AddCryptedKey (vchPubKey, vchCryptedSecret);
223220}
224221
222+ void CWallet::UpdateTimeFirstKey (int64_t nCreateTime)
223+ {
224+ AssertLockHeld (cs_wallet);
225+ if (nCreateTime <= 1 ) {
226+ // Cannot determine birthday information, so set the wallet birthday to
227+ // the beginning of time.
228+ nTimeFirstKey = 1 ;
229+ } else if (!nTimeFirstKey || nCreateTime < nTimeFirstKey) {
230+ nTimeFirstKey = nCreateTime;
231+ }
232+ }
233+
225234bool CWallet::AddCScript (const CScript& redeemScript)
226235{
227236 if (!CCryptoKeyStore::AddCScript (redeemScript))
0 commit comments