|
|
@ -186,12 +186,15 @@ bool CWallet::EncryptWallet(const string& strWalletPassphrase) |
|
|
|
pwalletdbEncryption = NULL; |
|
|
|
pwalletdbEncryption = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Lock(); |
|
|
|
|
|
|
|
Unlock(strWalletPassphrase); |
|
|
|
|
|
|
|
NewKeyPool(); |
|
|
|
Lock(); |
|
|
|
Lock(); |
|
|
|
|
|
|
|
|
|
|
|
// Need to completely rewrite the wallet file; if we don't, bdb might keep
|
|
|
|
// 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.
|
|
|
|
// bits of the unencrypted private key in slack space in the database file.
|
|
|
|
setKeyPool.clear(); |
|
|
|
setKeyPool.clear(); |
|
|
|
CDB::Rewrite(strWalletFile, "\x04pool"); |
|
|
|
CDB::Rewrite(strWalletFile); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -1244,6 +1247,34 @@ bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut) |
|
|
|
return true; |
|
|
|
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() |
|
|
|
bool CWallet::TopUpKeyPool() |
|
|
|
{ |
|
|
|
{ |
|
|
|
CRITICAL_BLOCK(cs_wallet) |
|
|
|
CRITICAL_BLOCK(cs_wallet) |
|
|
|