src/main.cpp
// ppcoin: total coin age spent in transaction, in the unit of coin-days.
// Only those coins meeting minimum age requirement counts. As those
// transactions not in main chain are not currently indexed so we
// might not find out about their coin age. Older transactions are
// guaranteed to be in main chain by sync-checkpoint. This rule is
// introduced to help nodes establish a consistent view of the coin
// age (trust score) of competing branches.
total coin age spent in transaction, in the unit of coin-days.
Only those coins meeting minimum age requirement counts. As those
transactions not in main chain are not currently indexed so we
might not find out about their coin age. Older transactions are
guaranteed to be in main chain by sync-checkpoint. This rule is
introduced to help nodes establish a consistent view of the coin
age (trust score) of competing branches.
total coin age spent in transaction in the unit of coin - days . Only those coins meeting minimum age requirement counts . As those transactions not in main chain are not currently indexed so we might not find out about their coin age . Older transactions are guaranteed to be in main chain by sync - checkpoint . This rule is introduced to help nodes establish a consistent view of the coin age ( trust score ) of competing branches .
bool CTransaction::GetCoinAge(CTxDB& txdb, uint64_t& nCoinAge) const
{
    CBigNum bnCentSecond = 0;  
    nCoinAge = 0;
    if (IsCoinBase())
        return true;
    BOOST_FOREACH(const CTxIn& txin, vin)
    {
        CTransaction txPrev;
        CTxIndex txindex;
        if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex))
            continue;  
        if (nTime < txPrev.nTime)
            return false;  
        CBlock block;
        if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
            return false; 
        if (block.GetBlockTime() + nStakeMinAge > nTime)
            continue; 
        int64_t nValueIn = txPrev.vout[txin.prevout.n].nValue;
        bnCentSecond += CBigNum(nValueIn) * (nTime-txPrev.nTime) / CENT;
        if (fDebug && GetBoolArg("-printcoinage"))
        {
            LogPrintf("coin age nValueIn=%d nTimeDiff=%d bnCentSecond=%s\n",
                      nValueIn, nTime - txPrev.nTime, bnCentSecond.ToString().c_str());
        }
    }
    CBigNum bnCoinDay = bnCentSecond * CENT / COIN / (24 * 60 * 60);
    if (fDebug && GetBoolArg("-printcoinage"))
        LogPrintf("coin age bnCoinDay=%s\n", bnCoinDay.ToString().c_str());
    nCoinAge = bnCoinDay.getuint64();
    return true;
}
bool CTransaction :: GetCoinAge ( CTxDB & txdb , uint64_t & nCoinAge ) const { CBigNum bnCentSecond = 0 ; nCoinAge = 0 ; if ( IsCoinBase ( ) ) return true ; BOOST_FOREACH ( const CTxIn & txin , vin ) { CTransaction txPrev ; CTxIndex txindex ; if ( ! txPrev . ReadFromDisk ( txdb , txin . prevout , txindex ) ) continue ; if ( nTime < txPrev . nTime ) return false ; CBlock block ; if ( ! block . ReadFromDisk ( txindex . pos . nFile , txindex . pos . nBlockPos , false ) ) return false ; if ( block . GetBlockTime ( ) + nStakeMinAge > nTime ) continue ; int64_t nValueIn = txPrev . vout [ txin . prevout . n ] . nValue ; bnCentSecond += CBigNum ( nValueIn ) * ( nTime - txPrev . nTime ) / CENT ; if ( fDebug && GetBoolArg ( " " ) ) { LogPrintf ( " \n " , nValueIn , nTime - txPrev . nTime , bnCentSecond . ToString ( ) . c_str ( ) ) ; } } CBigNum bnCoinDay = bnCentSecond * CENT / COIN / ( 24 * 60 * 60 ) ; if ( fDebug && GetBoolArg ( " " ) ) LogPrintf ( " \n " , bnCoinDay . ToString ( ) . c_str ( ) ) ; nCoinAge = bnCoinDay . getuint64 ( ) ; return true ; }
ppcoin: total coin age spent in transaction, in the unit of coin-days.
ppcoin : total coin age spent in transaction in the unit of coin - days .
// coin age in the unit of cent-seconds // First try finding the previous transaction in database // Previous transaction not in main chain // Transaction timestamp violation // Read block header // unable to read block of previous transaction // only count coins meeting min age requirement