From: Sunny King Date: Wed, 5 Sep 2012 14:27:34 +0000 (+0100) Subject: PPCoin: Fix checkwallet/repairwallet since 7237fa0 and c9d6552 X-Git-Tag: v0.4.0-unstable~72 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=0815e9ac6304c4f1bb98e37558aa438f45dc64dc PPCoin: Fix checkwallet/repairwallet since 7237fa0 and c9d6552 Impact: display false mismatch, no impact on wallet integrity --- 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);