PPCoin: Fix checkwallet/repairwallet since 7237fa0 and c9d6552
authorSunny King <sunnyking9999@gmail.com>
Wed, 5 Sep 2012 14:27:34 +0000 (15:27 +0100)
committerSunny King <sunnyking9999@gmail.com>
Wed, 5 Sep 2012 14:33:52 +0000 (15:33 +0100)
        Impact: display false mismatch, no impact on wallet integrity

src/bitcoinrpc.cpp
src/wallet.cpp

index 50299cc..e469e4e 100644 (file)
@@ -2105,14 +2105,15 @@ Value checkwallet(const Array& params, bool fHelp)
 
     int nMismatchSpent;
     int64 nBalanceInQuestion;
-    if (!pwalletMain->CheckSpentCoins(nMismatchSpent, nBalanceInQuestion))
+    Object result;
+    if (pwalletMain->CheckSpentCoins(nMismatchSpent, nBalanceInQuestion))
+        result.push_back(Pair("wallet check passed", true));
+    else
     {
-        Object result;
         result.push_back(Pair("mismatched spent coins", nMismatchSpent));
         result.push_back(Pair("amount in question", ValueFromAmount(nBalanceInQuestion)));
-        return result;
     }
-    return Value::null;
+    return result;
 }
 
 
@@ -2129,9 +2130,7 @@ Value repairwallet(const Array& params, bool fHelp)
     pwalletMain->FixSpentCoins(nMismatchSpent, nBalanceInQuestion);
     Object result;
     if (nMismatchSpent == 0)
-    {
         result.push_back(Pair("wallet check passed", true));
-    }
     else
     {
         result.push_back(Pair("mismatched spent coins", nMismatchSpent));
index 47ef64f..f070d65 100644 (file)
@@ -1762,15 +1762,15 @@ bool CWallet::CheckSpentCoins(int& nMismatchFound, int64& nBalanceInQuestion)
             continue;
         for (int n=0; n < pcoin->vout.size(); n++)
         {
-            if (pcoin->IsSpent(n) && (txindex.vSpent.size() <= n || txindex.vSpent[n].IsNull()))
+            if (IsMine(pcoin->vout[n]) && pcoin->IsSpent(n) && (txindex.vSpent.size() <= n || txindex.vSpent[n].IsNull()))
             {
-                printf("CheckSpentCoins found lost coin %sppc %s[%d]\n", FormatMoney(pcoin->GetCredit()).c_str(), pcoin->GetHash().ToString().c_str(), n);
+                printf("CheckSpentCoins found lost coin %sppc %s[%d]\n", FormatMoney(pcoin->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n);
                 nMismatchFound++;
                 nBalanceInQuestion += pcoin->vout[n].nValue;
             }
-            else if (!pcoin->IsSpent(n) && (txindex.vSpent.size() > n && !txindex.vSpent[n].IsNull()))
+            else if (IsMine(pcoin->vout[n]) && !pcoin->IsSpent(n) && (txindex.vSpent.size() > n && !txindex.vSpent[n].IsNull()))
             {
-                printf("CheckSpentCoins found spent coin %sppc %s[%d]\n", FormatMoney(pcoin->GetCredit()).c_str(), pcoin->GetHash().ToString().c_str(), n);
+                printf("CheckSpentCoins found spent coin %sppc %s[%d]\n", FormatMoney(pcoin->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n);
                 nMismatchFound++;
                 nBalanceInQuestion += pcoin->vout[n].nValue;
             }
@@ -1800,17 +1800,17 @@ void CWallet::FixSpentCoins(int& nMismatchFound, int64& nBalanceInQuestion)
             continue;
         for (int n=0; n < pcoin->vout.size(); n++)
         {
-            if (pcoin->IsSpent(n) && (txindex.vSpent.size() <= n || txindex.vSpent[n].IsNull()))
+            if (IsMine(pcoin->vout[n]) && pcoin->IsSpent(n) && (txindex.vSpent.size() <= n || txindex.vSpent[n].IsNull()))
             {
-                printf("FixSpentCoins found lost coin %sppc %s[%d]\n", FormatMoney(pcoin->GetCredit()).c_str(), pcoin->GetHash().ToString().c_str(), n);
+                printf("FixSpentCoins found lost coin %sppc %s[%d]\n", FormatMoney(pcoin->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n);
                 nMismatchFound++;
                 nBalanceInQuestion += pcoin->vout[n].nValue;
                 pcoin->MarkUnspent(n);
                 pcoin->WriteToDisk();
             }
-            else if (!pcoin->IsSpent(n) && (txindex.vSpent.size() > n && !txindex.vSpent[n].IsNull()))
+            else if (IsMine(pcoin->vout[n]) && !pcoin->IsSpent(n) && (txindex.vSpent.size() > n && !txindex.vSpent[n].IsNull()))
             {
-                printf("FixSpentCoins found spent coin %sppc %s[%d]\n", FormatMoney(pcoin->GetCredit()).c_str(), pcoin->GetHash().ToString().c_str(), n);
+                printf("FixSpentCoins found spent coin %sppc %s[%d]\n", FormatMoney(pcoin->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n);
                 nMismatchFound++;
                 nBalanceInQuestion += pcoin->vout[n].nValue;
                 pcoin->MarkSpent(n);