Advertisement
Guest User

Untitled

a guest
Jan 12th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. CBlockIndex* gdBlockPointer = NULL;
  2. std::map<std::string,int64> balances;
  3.  
  4. void processNextBlockIntoGrantDatabase(){
  5.  
  6. //printf("processNextBlockIntoGrantDatabase %d\n",grantDatabaseBlockHeight+1);
  7.  
  8. CBlock block;
  9.  
  10. //If it's the first block, we'll start with the Genesis Block
  11. if(gdBlockPointer==NULL){
  12. gdBlockPointer=pindexGenesisBlock;
  13. }else{
  14. gdBlockPointer=gdBlockPointer->pnext;
  15. }
  16. block.ReadFromDisk(gdBlockPointer);
  17. //ReadBlockFromDisk(block, gdBlockPointer);
  18. //block.ReadFromDisk(gdBlockPointer,true); //Litecoin codebase method
  19.  
  20.  
  21. //Look at all transactions in the block to update balances and see if they contain voting preferences
  22. for (int i = 0; i <block.vtx.size(); i++){
  23. //Deal with outputs first - increase balances and note what the votes are
  24. for (int j = 0; j <block.vtx[i].vout.size(); j++){
  25. CTxDestination address;
  26. ExtractDestination(block.vtx[i].vout[j].scriptPubKey,address);
  27.  
  28. string receiveAddress=CBitcoinAddress(address).ToString().c_str();
  29. int64 theAmount=block.vtx[i].vout[j].nValue;
  30.  
  31. //Update balance - if no previous balance, should start at 0
  32. balances[receiveAddress]=balances[receiveAddress]+theAmount;
  33.  
  34. }
  35.  
  36. //Deal with the inputs - reduce balances and apply voting preferences noted in the outputs
  37. for (int j = 0; j <block.vtx[i].vin.size(); j++){
  38. if(block.vtx[i].IsCoinBase()){
  39. //This is a coinbase transaction, there is no input to reduce
  40. }else{
  41. CTransaction txPrev;
  42. uint256 hashBlock;
  43. GetTransaction(block.vtx[i].vin[j].prevout.hash,txPrev,hashBlock);
  44. CTxDestination source;
  45. ExtractDestination(txPrev.vout[block.vtx[i].vin[j].prevout.n].scriptPubKey,source);
  46. string spendAddress=CBitcoinAddress(source).ToString().c_str();
  47. int64 theAmount=txPrev.vout[block.vtx[i].vin[j].prevout.n].nValue;
  48.  
  49. //Reduce balance
  50. balances[spendAddress]=balances[spendAddress]-theAmount;
  51. }
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement