Wallet: store key creation time. Calculate whole-wallet birthday.

This also encapsulate wallet-read state information into CWalletScanState.
This commit is contained in:
Jeff Garzik
2013-06-10 09:36:29 -04:00
parent f59530ce6e
commit 3869fb89b6
4 changed files with 135 additions and 38 deletions

View File

@@ -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)