Skip to content

Commit

Permalink
Fixed donations payments and added detailed payments logs
Browse files Browse the repository at this point in the history
  • Loading branch information
fancoder committed Aug 26, 2014
1 parent 175470f commit c822d8a
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions lib/blockUnlocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,8 @@ var apiInterfaces = require('./apiInterfaces.js')(config.daemon, config.wallet,
var logSystem = 'unlocker';
require('./exceptionWriter.js')(logSystem);


log('info', logSystem, 'Started');


//Use this in payment processing to get block info once batch RPC is supported
/*
var batchArray = [
['getblockheaderbyheight', {height: 21}],
['getblockheaderbyheight', {height: 22}],
['getblockheaderbyheight', {height: 23
}]
];
apiInterfaces.batchRpcDaemon(batchArray, function(error, response){
});
*/


function runInterval(){
async.waterfall([

Expand Down Expand Up @@ -96,7 +79,6 @@ function runInterval(){
//Get worker shares for each unlocked block
function(blocks, callback){


var redisCommands = blocks.map(function(block){
return ['hgetall', config.coin + ':shares:round' + block.height];
});
Expand Down Expand Up @@ -181,20 +163,24 @@ function runInterval(){

if (Object.keys(donations).length) {
for(var wallet in donations) {
var percent = donations[wallet];
var percent = donations[wallet] / 100;
feePercent += percent;
payments[wallet] = block.reward * (percent / 100);
payments[wallet] = Math.round(block.reward * percent);
log('info', logSystem, 'Block %d donation to %s as %d percent of reward: %d', [block.height, wallet, percent, payments[wallet]]);
}
}

var reward = block.reward - (block.reward * feePercent);
var reward = Math.round(block.reward - (block.reward * feePercent));

log('info', logSystem, 'Unlocked %d block with reward %d and donation fee %d. Miners reward: %d', [block.height, block.reward, feePercent, reward]);

if (block.workerShares) {
var totalShares = parseInt(block.shares);
Object.keys(block.workerShares).forEach(function (worker) {
var percent = block.workerShares[worker] / totalShares;
var workerReward = reward * percent;
var workerReward = Math.round(reward * percent);
payments[worker] = (payments[worker] || 0) + workerReward;
log('info', logSystem, 'Block %d payment to %s for %d shares: %d', [block.height, worker, totalShares, payments[worker]]);
});
}
});
Expand Down

0 comments on commit c822d8a

Please sign in to comment.