Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void GetAddressBalances(unsigned int cutoffTime, BalanceMap& mapBalance)
- {
- CBlockIndex* pblk0 = pindexGenesisBlock, *pblk1 = pindexBest;
- if (!pblk0) throw runtime_error("No genesis block.");
- if (!pblk1) throw runtime_error("No best block chain.");
- if (cutoffTime>pblk1->nTime)
- throw runtime_error("Cutoff date later than most recent block.");
- BalanceMap mapRunningBalance = mapBalance;
- CTxDB txdb("r");
- int nBlks = 0;
- int nBlockSpan = 0;
- while (pblk0 != pblk1)
- {
- if (pblk0->nTime >= cutoffTime)
- {
- if (nBlockSpan == 0) {
- nBlockSpan = pblk1->nHeight - pblk0->nHeight + 1;
- }
- for (BalanceMap::iterator it = mapRunningBalance.begin(); it != mapRunningBalance.end(); it++) {
- mapBalance[it->first] += it->second / nBlockSpan;
- }
- }
- CBlock block;
- block.ReadFromDisk(pblk0, true);
- BOOST_FOREACH(const CTransaction& tx, block.vtx)
- {
- ScanTransactionInputs(txdb, tx, mapRunningBalance);
- ScanTransactionOutputs(tx, mapRunningBalance);
- }
- pblk0 = pblk0->pnext;
- nBlks++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement