From 4addb2c066e157f479fdbae902b3d568f2432fd0 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 20 Jun 2013 01:13:55 +0200 Subject: Refactor keytime/metadata and wallet encryption bugfix Refactor keytime: * Key metadata is kept in a CWallet::mapKeyMetadata (std::map). * When generating a new key, time is put in that map, and new key is written. * AddKeyPubKey and AddCryptedKey do not take a creation time argument, but instead pull it from that map, if it exists there. Bugfix: * AddKeyPubKey and AddCryptedKey in CWallet didn't override the CKeyStore definition anymore. This is fixed, as they no longed need the nCreationTime argument now. Also a few related other changes: * Metadata can be overwritten. * Only GenerateNewKey calls GetTime(), as it's the only place where we know for sure a key was not constructed earlier. * When the nTimeFirstKey is known to be inaccurate, it is set to the value 1 (instead of 0, which would mean unknown). * Use CPubKey instead of std::vector where possible. --- src/walletdb.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/walletdb.h') diff --git a/src/walletdb.h b/src/walletdb.h index 287361b33d..4dfa35d82a 100644 --- a/src/walletdb.h +++ b/src/walletdb.h @@ -30,7 +30,7 @@ class CKeyMetadata public: static const int CURRENT_VERSION=1; int nVersion; - int64 nCreateTime; + int64 nCreateTime; // 0 means unknown CKeyMetadata() { @@ -52,7 +52,7 @@ public: void SetNull() { nVersion = CKeyMetadata::CURRENT_VERSION; - nCreateTime = GetTime(); + nCreateTime = 0; } }; @@ -84,13 +84,12 @@ public: } bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, - int64 nCreateTime) + const CKeyMetadata &keyMeta) { nWalletDBUpdated++; - CKeyMetadata keyMeta(nCreateTime); if (!Write(std::make_pair(std::string("keymeta"), vchPubKey), - keyMeta, false)) + keyMeta)) return false; return Write(std::make_pair(std::string("key"), vchPubKey), vchPrivKey, false); @@ -98,14 +97,13 @@ public: bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector& vchCryptedSecret, - int64 nCreateTime) + const CKeyMetadata &keyMeta) { const bool fEraseUnencryptedKey = true; nWalletDBUpdated++; - CKeyMetadata keyMeta(nCreateTime); if (!Write(std::make_pair(std::string("keymeta"), vchPubKey), - keyMeta, false)) + keyMeta)) return false; if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false)) -- cgit v1.2.3