diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-11-17 14:01:25 -0500 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2011-11-17 14:29:12 -0500 |
commit | 90de05e88ecc879b75315eebacb488b44353f5d9 (patch) | |
tree | ca50981d39fb395b1da70c7bdb22a588cde129f3 /src/wallet.cpp | |
parent | 2bf36b4e7dd06d44ee3c81391338ccb708edbbaa (diff) | |
download | bitcoin-90de05e88ecc879b75315eebacb488b44353f5d9.tar.xz |
Create new keypool for newly encrypted wallets.
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r-- | src/wallet.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp index c004d18360..9b9586face 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -188,11 +188,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; @@ -1224,6 +1227,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) |