diff options
Diffstat (limited to 'src/walletdb.h')
-rw-r--r-- | src/walletdb.h | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/walletdb.h b/src/walletdb.h index 9732eb29e4..287361b33d 100644 --- a/src/walletdb.h +++ b/src/walletdb.h @@ -25,6 +25,37 @@ enum DBErrors DB_NEED_REWRITE }; +class CKeyMetadata +{ +public: + static const int CURRENT_VERSION=1; + int nVersion; + int64 nCreateTime; + + CKeyMetadata() + { + SetNull(); + } + CKeyMetadata(int64 nCreateTime_) + { + nVersion = CKeyMetadata::CURRENT_VERSION; + nCreateTime = nCreateTime_; + } + + IMPLEMENT_SERIALIZE + ( + READWRITE(this->nVersion); + nVersion = this->nVersion; + READWRITE(nCreateTime); + ) + + void SetNull() + { + nVersion = CKeyMetadata::CURRENT_VERSION; + nCreateTime = GetTime(); + } +}; + /** Access to the wallet database (wallet.dat) */ class CWalletDB : public CDB { @@ -52,15 +83,31 @@ public: return Erase(std::make_pair(std::string("tx"), hash)); } - bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey) + bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, + int64 nCreateTime) { nWalletDBUpdated++; + + CKeyMetadata keyMeta(nCreateTime); + if (!Write(std::make_pair(std::string("keymeta"), vchPubKey), + keyMeta, false)) + return false; + return Write(std::make_pair(std::string("key"), vchPubKey), vchPrivKey, false); } - bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, bool fEraseUnencryptedKey = true) + bool WriteCryptedKey(const CPubKey& vchPubKey, + const std::vector<unsigned char>& vchCryptedSecret, + int64 nCreateTime) { + const bool fEraseUnencryptedKey = true; nWalletDBUpdated++; + + CKeyMetadata keyMeta(nCreateTime); + if (!Write(std::make_pair(std::string("keymeta"), vchPubKey), + keyMeta, false)) + return false; + if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false)) return false; if (fEraseUnencryptedKey) |