]> Git Repo - VerusCoin.git/commitdiff
Create new keypool for newly encrypted wallets.
authorGavin Andresen <[email protected]>
Thu, 17 Nov 2011 19:01:25 +0000 (14:01 -0500)
committerGavin Andresen <[email protected]>
Thu, 17 Nov 2011 19:01:25 +0000 (14:01 -0500)
src/wallet.cpp
src/wallet.h

index e3ca7d297d908c0d37205fcef3fbed0392ab41b5..24a592689ead56e8c129b5b4680dda343c7366c3 100644 (file)
@@ -186,12 +186,15 @@ bool CWallet::EncryptWallet(const string& strWalletPassphrase)
             pwalletdbEncryption = NULL;
         }
 
+        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)
index 03c4703fc0ef0f29f196334ee4f631819336f8ef..19de803390ae1cdc344b12368f488457cdc6bb4c 100644 (file)
@@ -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);
This page took 0.035329 seconds and 4 git commands to generate.