aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-11-17 14:01:25 -0500
committerGavin Andresen <gavinandresen@gmail.com>2011-11-17 14:01:25 -0500
commit37971fcc76b867681b1df5ee962f3d2a7f12a86e (patch)
tree73d81703d5eda6bcf079e2fb4cacd99b164a7c69
parent1b93ea0e31c82bd23f2ddc0b5a98707fcbddce27 (diff)
downloadbitcoin-37971fcc76b867681b1df5ee962f3d2a7f12a86e.tar.xz
Create new keypool for newly encrypted wallets.
-rw-r--r--src/wallet.cpp33
-rw-r--r--src/wallet.h1
2 files changed, 33 insertions, 1 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index e3ca7d297d..24a592689e 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -187,11 +187,14 @@ bool CWallet::EncryptWallet(const string& strWalletPassphrase)
}
Lock();
+ Unlock(strWalletPassphrase);
+ NewKeyPool();
+ Lock();
// Need to completely rewrite the wallet file; if we don't, bdb might keep
// bits of the unencrypted private key in slack space in the database file.
setKeyPool.clear();
- CDB::Rewrite(strWalletFile, "\x04pool");
+ CDB::Rewrite(strWalletFile);
}
return true;
@@ -1244,6 +1247,34 @@ bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut)
return true;
}
+//
+// Mark old keypool keys as used,
+// and generate all new keys
+//
+bool CWallet::NewKeyPool()
+{
+ CRITICAL_BLOCK(cs_wallet)
+ {
+ CWalletDB walletdb(strWalletFile);
+ BOOST_FOREACH(int64 nIndex, setKeyPool)
+ walletdb.ErasePool(nIndex);
+ setKeyPool.clear();
+
+ if (IsLocked())
+ return false;
+
+ int64 nKeys = max(GetArg("-keypool", 100), (int64)0);
+ for (int i = 0; i < nKeys; i++)
+ {
+ int64 nIndex = i+1;
+ walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey()));
+ setKeyPool.insert(nIndex);
+ }
+ printf("CWallet::NewKeyPool wrote %"PRI64d" new keys\n", nKeys);
+ }
+ return true;
+}
+
bool CWallet::TopUpKeyPool()
{
CRITICAL_BLOCK(cs_wallet)
diff --git a/src/wallet.h b/src/wallet.h
index 03c4703fc0..19de803390 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -90,6 +90,7 @@ public:
std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
std::string SendMoneyToBitcoinAddress(const CBitcoinAddress& address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
+ bool NewKeyPool();
bool TopUpKeyPool();
void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
void KeepKey(int64 nIndex);