aboutsummaryrefslogtreecommitdiff
path: root/src/walletdb.h
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@bitpay.com>2013-06-10 09:36:29 -0400
committerJeff Garzik <jgarzik@bitpay.com>2013-06-10 09:36:29 -0400
commit3869fb89b60091281b43a35921057ba3f43c18f0 (patch)
tree3510aec7ccc74db41f25393f929db896f087cfea /src/walletdb.h
parentf59530ce6eb5a889e6eb750024ddb20e7b0df9d7 (diff)
Wallet: store key creation time. Calculate whole-wallet birthday.
This also encapsulate wallet-read state information into CWalletScanState.
Diffstat (limited to 'src/walletdb.h')
-rw-r--r--src/walletdb.h51
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)