Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CBlockIndex* gdBlockPointer = NULL;
- std::map<std::string,int64> balances;
- void processNextBlockIntoGrantDatabase(){
- //printf("processNextBlockIntoGrantDatabase %d\n",grantDatabaseBlockHeight+1);
- CBlock block;
- //If it's the first block, we'll start with the Genesis Block
- if(gdBlockPointer==NULL){
- gdBlockPointer=pindexGenesisBlock;
- }else{
- gdBlockPointer=gdBlockPointer->pnext;
- }
- block.ReadFromDisk(gdBlockPointer);
- //ReadBlockFromDisk(block, gdBlockPointer);
- //block.ReadFromDisk(gdBlockPointer,true); //Litecoin codebase method
- //Look at all transactions in the block to update balances and see if they contain voting preferences
- for (int i = 0; i <block.vtx.size(); i++){
- //Deal with outputs first - increase balances and note what the votes are
- for (int j = 0; j <block.vtx[i].vout.size(); j++){
- CTxDestination address;
- ExtractDestination(block.vtx[i].vout[j].scriptPubKey,address);
- string receiveAddress=CBitcoinAddress(address).ToString().c_str();
- int64 theAmount=block.vtx[i].vout[j].nValue;
- //Update balance - if no previous balance, should start at 0
- balances[receiveAddress]=balances[receiveAddress]+theAmount;
- }
- //Deal with the inputs - reduce balances and apply voting preferences noted in the outputs
- for (int j = 0; j <block.vtx[i].vin.size(); j++){
- if(block.vtx[i].IsCoinBase()){
- //This is a coinbase transaction, there is no input to reduce
- }else{
- CTransaction txPrev;
- uint256 hashBlock;
- GetTransaction(block.vtx[i].vin[j].prevout.hash,txPrev,hashBlock);
- CTxDestination source;
- ExtractDestination(txPrev.vout[block.vtx[i].vin[j].prevout.n].scriptPubKey,source);
- string spendAddress=CBitcoinAddress(source).ToString().c_str();
- int64 theAmount=txPrev.vout[block.vtx[i].vin[j].prevout.n].nValue;
- //Reduce balance
- balances[spendAddress]=balances[spendAddress]-theAmount;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement