aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorPieter Wuille <[email protected]>2013-06-10 13:38:19 -0700
committerPieter Wuille <[email protected]>2013-06-10 13:38:19 -0700
commit61983b3d1626359705b300ac82d9cfb6b77eb746 (patch)
tree1a806448a68156f8ddaceda25b12320ec3c17612 /src/wallet.cpp
parentMerge pull request #2728 from runeksvendsen/master (diff)
parentWallet: optimize rescan to skip blocks prior to birthday (diff)
downloaddiscoin-61983b3d1626359705b300ac82d9cfb6b77eb746.tar.xz
discoin-61983b3d1626359705b300ac82d9cfb6b77eb746.zip
Merge pull request #1863 from jgarzik/keytime
"Wallet birthdays": store key create time; calc whole-wallet birthday
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 7041d49da..9a4a92cd5 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -45,20 +45,33 @@ CPubKey CWallet::GenerateNewKey()
return pubkey;
}
-bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey)
+bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey,
+ int64 nCreateTime)
{
+ if (!nCreateTime)
+ nCreateTime = GetTime();
+ if (!nTimeFirstKey || (nCreateTime < nTimeFirstKey))
+ nTimeFirstKey = nCreateTime;
if (!CCryptoKeyStore::AddKeyPubKey(secret, pubkey))
return false;
if (!fFileBacked)
return true;
if (!IsCrypted()) {
- return CWalletDB(strWalletFile).WriteKey(pubkey, secret.GetPrivKey());
+ return CWalletDB(strWalletFile).WriteKey(pubkey,
+ secret.GetPrivKey(),
+ nCreateTime);
}
return true;
}
-bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, const vector<unsigned char> &vchCryptedSecret)
+bool CWallet::AddCryptedKey(const CPubKey &vchPubKey,
+ const vector<unsigned char> &vchCryptedSecret,
+ int64 nCreateTime)
{
+ if (!nCreateTime)
+ nCreateTime = GetTime();
+ if (!nTimeFirstKey || (nCreateTime < nTimeFirstKey))
+ nTimeFirstKey = nCreateTime;
if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret))
return false;
if (!fFileBacked)
@@ -66,9 +79,13 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, const vector<unsigned char
{
LOCK(cs_wallet);
if (pwalletdbEncryption)
- return pwalletdbEncryption->WriteCryptedKey(vchPubKey, vchCryptedSecret);
+ return pwalletdbEncryption->WriteCryptedKey(vchPubKey,
+ vchCryptedSecret,
+ nCreateTime);
else
- return CWalletDB(strWalletFile).WriteCryptedKey(vchPubKey, vchCryptedSecret);
+ return CWalletDB(strWalletFile).WriteCryptedKey(vchPubKey,
+ vchCryptedSecret,
+ nCreateTime);
}
return false;
}
@@ -773,6 +790,13 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
LOCK(cs_wallet);
while (pindex)
{
+ // no need to read and scan block, if block was created before
+ // our wallet birthday (as adjusted for block time variability)
+ if (nTimeFirstKey && (pindex->nTime < (nTimeFirstKey - 7200))) {
+ pindex = pindex->GetNextInMainChain();
+ continue;
+ }
+
CBlock block;
block.ReadFromDisk(pindex);
BOOST_FOREACH(CTransaction& tx, block.vtx)