From 0815e9ac6304c4f1bb98e37558aa438f45dc64dc Mon Sep 17 00:00:00 2001 From: Sunny King Date: Wed, 5 Sep 2012 15:27:34 +0100 Subject: [PATCH] PPCoin: Fix checkwallet/repairwallet since 7237fa0 and c9d6552 Impact: display false mismatch, no impact on wallet integrity --- src/bitcoinrpc.cpp | 11 +++++------ src/wallet.cpp | 16 ++++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 50299cc..e469e4e 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -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)); diff --git a/src/wallet.cpp b/src/wallet.cpp index 47ef64f..f070d65 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -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); -- 1.7.1