thought it might be a good idea to check if the displayed coin supply was valid with the following code:
std::string Test()
{
printf("Checking total coin supply");
int height = 1;
int64_t value = 0;
int64_t fee = 0;
for (height; height < nBestHeight; height++)
{
CBlockIndex* pblockindex = FindBlockByHeight(height);
CBlock block;
block.ReadFromDisk(pblockindex, true);
BOOST_FOREACH(CTransaction& tx, block.vtx)
{
if (tx.IsCoinBase())
{
// generated POW
BOOST_FOREACH(CTxOut txOut, tx.vout)
value += txOut.nValue;
}
else
{
int64_t valueIn = 0;
int64_t valueOut = 0;
BOOST_FOREACH(CTxIn txIn, tx.vin)
{
CTransaction txPrev;
txPrev.ReadFromDisk(txIn.prevout);
CTxOut txOut = txPrev.vout[txIn.prevout.n];
valueIn += txOut.nValue;
}
BOOST_FOREACH(CTxOut txOut, tx.vout)
valueOut += txOut.nValue;
if (valueOut < valueIn)
fee += valueIn - valueOut;
else
value += valueOut - valueIn;
}
}
}
float fvalue = value / (float) COIN;
float ffee = fee / (float) COIN;
std::string result;
result += (boost::format("blocks scanned: %1%\n") % height).str();
result += (boost::format("total supply: %11.8f\n") % fvalue).str();
result += (boost::format("total fee: %11.8f\n") % ffee).str();
return result;
}
output:
blocks scanned: 105658
total supply: 3711873.00000000
total fee: 43.62789917
everything seems to be in order, the calculated total supply matches the total supply displayed in the block.