}
// ppcoin: check 'spent' consistency between wallet and txindex
-bool CWallet::CheckSpentCoins(int& nMismatchFound, int64& nBalanceInQuestion)
-{
- nMismatchFound = 0;
- nBalanceInQuestion = 0;
-
- LOCK(cs_wallet);
- vector<const CWalletTx*> vCoins;
- vCoins.reserve(mapWallet.size());
- for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
- vCoins.push_back(&(*it).second);
-
- CTxDB txdb("r");
- BOOST_FOREACH(const CWalletTx* pcoin, vCoins)
- {
- // Find the corresponding transaction index
- CTxIndex txindex;
- if (!txdb.ReadTxIndex(pcoin->GetHash(), txindex))
- continue;
- for (int n=0; n < pcoin->vout.size(); n++)
- {
- 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->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n);
- nMismatchFound++;
- nBalanceInQuestion += pcoin->vout[n].nValue;
- }
- 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->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n);
- nMismatchFound++;
- nBalanceInQuestion += pcoin->vout[n].nValue;
- }
- }
- }
- return (nMismatchFound == 0);
-}
-
// ppcoin: fix wallet spent state according to txindex
-void CWallet::FixSpentCoins(int& nMismatchFound, int64& nBalanceInQuestion)
+void CWallet::FixSpentCoins(int& nMismatchFound, int64& nBalanceInQuestion, bool fCheckOnly)
{
nMismatchFound = 0;
nBalanceInQuestion = 0;
{
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->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n);
+ printf("FixSpentCoins found lost coin %sppc %s[%d], %s\n",
+ FormatMoney(pcoin->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n, fCheckOnly? "repair not attempted" : "repairing");
nMismatchFound++;
nBalanceInQuestion += pcoin->vout[n].nValue;
- pcoin->MarkUnspent(n);
- pcoin->WriteToDisk();
+ if (!fCheckOnly)
+ {
+ pcoin->MarkUnspent(n);
+ pcoin->WriteToDisk();
+ }
}
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->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n);
+ printf("FixSpentCoins found spent coin %sppc %s[%d], %s\n",
+ FormatMoney(pcoin->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n, fCheckOnly? "repair not attempted" : "repairing");
nMismatchFound++;
nBalanceInQuestion += pcoin->vout[n].nValue;
- pcoin->MarkSpent(n);
- pcoin->WriteToDisk();
+ if (!fCheckOnly)
+ {
+ pcoin->MarkSpent(n);
+ pcoin->WriteToDisk();
+ }
}
}
}
// get the current wallet format (the oldest client version guaranteed to understand this wallet)
int GetVersion() { return nWalletVersion; }
- bool CheckSpentCoins(int& nMismatchSpent, int64& nBalanceInQuestion);
- void FixSpentCoins(int& nMismatchSpent, int64& nBalanceInQuestion);
+ void FixSpentCoins(int& nMismatchSpent, int64& nBalanceInQuestion, bool fCheckOnly = false);
void DisableTransaction(const CTransaction &tx);
};