Merge branch 'master' of github.com:novacoin-project/novacoin
[novacoin.git] / src / walletdb.cpp
index e44885d..3880a93 100644 (file)
@@ -85,7 +85,7 @@ void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountin
     if (!pcursor)
         throw runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor");
     unsigned int fFlags = DB_SET_RANGE;
-    while (true)
+    for ( ; ; )
     {
         // Read next record
         CDataStream ssKey(SER_DISK, CLIENT_VERSION);
@@ -311,9 +311,9 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
             ssValue >> vchSecret;
 
             CMalleableKeyView keyView(strKeyView);
-            if (!pwallet->LoadMalleableKey(keyView, vchSecret))
+            if (!pwallet->LoadKey(keyView, vchSecret))
             {
-                strErr = "Error reading wallet database: LoadMalleableKey failed";
+                strErr = "Error reading wallet database: LoadKey failed";
                 return false;
             }
         }
@@ -326,23 +326,22 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
             ssValue >> vchCryptedSecret;
 
             CMalleableKeyView keyView(strKeyView);
-            if (!pwallet->LoadCryptedMalleableKey(keyView, vchCryptedSecret))
+            if (!pwallet->LoadCryptedKey(keyView, vchCryptedSecret))
             {
-                strErr = "Error reading wallet database: LoadCryptedMalleableKey failed";
+                strErr = "Error reading wallet database: LoadCryptedKey failed";
                 return false;
             }
         }
         else if (strType == "key" || strType == "wkey")
         {
-            vector<unsigned char> vchPubKey;
-            ssKey >> vchPubKey;
             CKey key;
+            CPubKey vchPubKey;
+            ssKey >> vchPubKey;
             if (strType == "key")
             {
                 wss.nKeys++;
                 CPrivKey pkey;
                 ssValue >> pkey;
-                key.SetPubKey(vchPubKey);
                 if (!key.SetPrivKey(pkey))
                 {
                     strErr = "Error reading wallet database: CPrivKey corrupt";
@@ -353,6 +352,9 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
                     strErr = "Error reading wallet database: CPrivKey pubkey inconsistency";
                     return false;
                 }
+                if (vchPubKey.size() == 33) {
+                    key.SetCompressedPubKey();
+                }
                 if (!key.IsValid())
                 {
                     strErr = "Error reading wallet database: invalid CPrivKey";
@@ -363,7 +365,6 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
             {
                 CWalletKey wkey;
                 ssValue >> wkey;
-                key.SetPubKey(vchPubKey);
                 if (!key.SetPrivKey(wkey.vchPrivKey))
                 {
                     strErr = "Error reading wallet database: CPrivKey corrupt";
@@ -374,6 +375,9 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
                     strErr = "Error reading wallet database: CWalletKey pubkey inconsistency";
                     return false;
                 }
+                if (vchPubKey.size() == 33) {
+                    key.SetCompressedPubKey();
+                }
                 if (!key.IsValid())
                 {
                     strErr = "Error reading wallet database: invalid CWalletKey";
@@ -405,7 +409,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
         else if (strType == "ckey")
         {
             wss.nCKeys++;
-            vector<unsigned char> vchPubKey;
+            CPubKey vchPubKey;
             ssKey >> vchPubKey;
             vector<unsigned char> vchPrivKey;
             ssValue >> vchPrivKey;
@@ -525,7 +529,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
             return DB_CORRUPT;
         }
 
-        while (true)
+        for ( ; ; )
         {
             // Read next record
             CDataStream ssKey(SER_DISK, CLIENT_VERSION);
@@ -625,7 +629,7 @@ DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, vector<uint256>& vTxHash)
             return DB_CORRUPT;
         }
 
-        while (true)
+        for ( ; ; )
         {
             // Read next record
             CDataStream ssKey(SER_DISK, CLIENT_VERSION);
@@ -650,7 +654,7 @@ DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, vector<uint256>& vTxHash)
         }
         pcursor->close();
     }
-    catch (boost::thread_interrupted) {
+    catch (const boost::thread_interrupted&) {
         throw;
     }
     catch (...) {
@@ -940,7 +944,7 @@ bool ImportWallet(CWallet *pwallet, const string& strLocation)
            }
 
            printf("Importing %s...\n", addr.ToString().c_str());
-           if (!pwallet->AddMalleableKey(mKey)) {
+           if (!pwallet->AddKey(mKey)) {
                fGood = false;
                continue;
            }