src/wallet.cpp
// ppcoin: check 'spent' consistency between wallet and txindex
// ppcoin: fix wallet spent state according to txindex
check 'spent' consistency between wallet and txindex
ppcoin: fix wallet spent state according to txindex
check ' spent ' consistency between wallet and txindex ppcoin : fix wallet spent state according to txindex
void CWallet::FixSpentCoins(int& nMismatchFound, int64_t& nBalanceInQuestion, bool fCheckOnly)
{
    nMismatchFound = 0;
    nBalanceInQuestion = 0;
    LOCK(cs_wallet);
    vector<CWalletTx*> vCoins;
    vCoins.reserve(mapWallet.size());
    for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it)
        vCoins.push_back(&(*it).second);
    CTxDB txdb("r");
    BOOST_FOREACH(CWalletTx* pcoin, vCoins)
    {
        CTxIndex txindex;
        if (!txdb.ReadTxIndex(pcoin->GetHash(), txindex))
            continue;
        for (unsigned int n=0; n < pcoin->vout.size(); n++)
        {
            if (IsMine(pcoin->vout[n]) && pcoin->IsSpent(n) && (txindex.vSpent.size() <= n || txindex.vSpent[n].IsNull()))
            {
                LogPrintf("FixSpentCoins found lost coin %s TC %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;
                if (!fCheckOnly)
                {
                    pcoin->MarkUnspent(n);
                    pcoin->WriteToDisk();
                }
            }
            else if (IsMine(pcoin->vout[n]) && !pcoin->IsSpent(n) && (txindex.vSpent.size() > n && !txindex.vSpent[n].IsNull()))
            {
                LogPrintf("FixSpentCoins found spent coin %s TC %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;
                if (!fCheckOnly)
                {
                    pcoin->MarkSpent(n);
                    pcoin->WriteToDisk();
                }
            }
        }
    }
}
void CWallet :: FixSpentCoins ( int & nMismatchFound , int64_t & nBalanceInQuestion , bool fCheckOnly ) { nMismatchFound = 0 ; nBalanceInQuestion = 0 ; LOCK ( cs_wallet ) ; vector < CWalletTx * > vCoins ; vCoins . reserve ( mapWallet . size ( ) ) ; for ( auto it = mapWallet . begin ( ) ; it != mapWallet . end ( ) ; ++ it ) vCoins . push_back ( & ( * it ) . second ) ; CTxDB txdb ( " " ) ; BOOST_FOREACH ( CWalletTx * pcoin , vCoins ) { CTxIndex txindex ; if ( ! txdb . ReadTxIndex ( pcoin -> GetHash ( ) , txindex ) ) continue ; for ( unsigned int n = 0 ; n < pcoin -> vout . size ( ) ; n ++ ) { if ( IsMine ( pcoin -> vout [ n ] ) && pcoin -> IsSpent ( n ) && ( txindex . vSpent . size ( ) <= n || txindex . vSpent [ n ] . IsNull ( ) ) ) { LogPrintf ( " \n " , FormatMoney ( pcoin -> vout [ n ] . nValue ) . c_str ( ) , pcoin -> GetHash ( ) . ToString ( ) . c_str ( ) , n , fCheckOnly ? " " : " " ) ; nMismatchFound ++ ; nBalanceInQuestion += pcoin -> vout [ n ] . nValue ; if ( ! fCheckOnly ) { pcoin -> MarkUnspent ( n ) ; pcoin -> WriteToDisk ( ) ; } } else if ( IsMine ( pcoin -> vout [ n ] ) && ! pcoin -> IsSpent ( n ) && ( txindex . vSpent . size ( ) > n && ! txindex . vSpent [ n ] . IsNull ( ) ) ) { LogPrintf ( " \n " , FormatMoney ( pcoin -> vout [ n ] . nValue ) . c_str ( ) , pcoin -> GetHash ( ) . ToString ( ) . c_str ( ) , n , fCheckOnly ? " " : " " ) ; nMismatchFound ++ ; nBalanceInQuestion += pcoin -> vout [ n ] . nValue ; if ( ! fCheckOnly ) { pcoin -> MarkSpent ( n ) ; pcoin -> WriteToDisk ( ) ; } } } } }
ppcoin: check 'spent' consistency between wallet and txindex
ppcoin: fix wallet spent state according to txindex
ppcoin : check ' spent ' consistency between wallet and txindex ppcoin : fix wallet spent state according to txindex
// Find the corresponding transaction index