Skip to content

Instantly share code, notes, and snippets.

@kvhnuke
Created December 5, 2016 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kvhnuke/3fbec05312e93cb92b940bda0be3592f to your computer and use it in GitHub Desktop.
Save kvhnuke/3fbec05312e93cb92b940bda0be3592f to your computer and use it in GitHub Desktop.
ethRewardCalc
var Web3 = require('web3');
var BigNumber = require('bignumber.js');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://:8545'));
//console.log(web3.eth.getBlock('0xea1d5ef2791197b10d05ee07ea16226a8f14251c9cc5e3ee8d348be4e114f561'));
var LATEST_BLOCK = web3.eth.getBlock('latest').number;
var STARTING_BLOCK = 2751491;//LATEST_BLOCK - 6008; //60*24*(60/14.38)=6008 (1 day)
console.log("LATEST BLOCK", LATEST_BLOCK);
console.log("STARTING BLOCK", STARTING_BLOCK);
var uncleReward = new BigNumber(0);
var txReward = new BigNumber(0);
var blockReward = new BigNumber(0);
for(var i=STARTING_BLOCK;i<STARTING_BLOCK+10;i++){
var blockInfo = web3.eth.getBlock(i);
console.log("PROCESSING BLOCK", blockInfo.number);
var uncleHashes = blockInfo.uncles;
var tBlockReward = new BigNumber(5+(5*0.03125*uncleHashes.length));
blockReward = blockReward.plus(tBlockReward);
var tUncleReward = new BigNumber(0);
for(var j=0;j<uncleHashes.length; j++){
var uncleInfo = web3.eth.getBlock(uncleHashes[j]);
tUncleReward = tUncleReward.plus((uncleInfo.number + 8 - blockInfo.number) * 5 / 8);
}
uncleReward = uncleReward.plus(tUncleReward);
var txHashes = blockInfo.transactions;
var tTxReward = new BigNumber(0);
for(j=0;j<txHashes.length;j++){
var txInfo = web3.eth.getTransaction(txHashes[j]);
var gasPrice = txInfo.gasPrice;
txInfo = web3.eth.getTransactionReceipt(txHashes[j]);
tTxReward = tTxReward.plus(gasPrice.mul(txInfo.gasUsed));
}
txReward = txReward.plus(tTxReward);
console.log("BLOCK REWARD",tBlockReward.toNumber(),"NUMBER OF UNCLES", uncleHashes.length, "UNCLE REWARD", tUncleReward.toNumber(), "TX REWARD", web3.fromWei(tTxReward,'ether').toNumber());
}
var totalUncleRewards = uncleReward.toNumber();
var totalTxRewards = web3.fromWei(txReward,'ether').toNumber();
var totalBlockRewards = blockReward.toNumber();
console.log("UNCLE REWARDS", totalUncleRewards);
console.log("TX REWARDS", totalTxRewards);
console.log("BLOCK REWARDS", totalBlockRewards);
console.log("RATIO", totalTxRewards/(totalUncleRewards+totalTxRewards+totalBlockRewards));
//var balance = web3.eth.getBalance('0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8');
//console.log(balance.toNumber());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment