Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. void GetAddressBalances(unsigned int cutoffTime, BalanceMap& mapBalance)
  2. {
  3.     CBlockIndex* pblk0 = pindexGenesisBlock, *pblk1 = pindexBest;
  4.     if (!pblk0) throw runtime_error("No genesis block.");
  5.     if (!pblk1) throw runtime_error("No best block chain.");
  6.  
  7.     if (cutoffTime>pblk1->nTime)
  8.         throw runtime_error("Cutoff date later than most recent block.");
  9.  
  10.     BalanceMap mapRunningBalance = mapBalance;
  11.     CTxDB txdb("r");
  12.     int nBlks = 0;
  13.     int nBlockSpan = 0;
  14.     while (pblk0 != pblk1)
  15.     {
  16.         if (pblk0->nTime >= cutoffTime)
  17.         {
  18.             if (nBlockSpan == 0) {
  19.                 nBlockSpan = pblk1->nHeight - pblk0->nHeight + 1;
  20.             }
  21.             for (BalanceMap::iterator it = mapRunningBalance.begin(); it != mapRunningBalance.end(); it++) {
  22.                 mapBalance[it->first] += it->second / nBlockSpan;
  23.             }
  24.         }
  25.  
  26.         CBlock block;
  27.         block.ReadFromDisk(pblk0, true);
  28.  
  29.         BOOST_FOREACH(const CTransaction& tx, block.vtx)
  30.         {
  31.             ScanTransactionInputs(txdb, tx, mapRunningBalance);
  32.             ScanTransactionOutputs(tx, mapRunningBalance);
  33.         }
  34.  
  35.         pblk0 = pblk0->pnext;
  36.         nBlks++;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement