From c822d8a53d6aecec207722d9a460948536476010 Mon Sep 17 00:00:00 2001 From: fancoder Date: Tue, 26 Aug 2014 18:32:05 +0400 Subject: [PATCH] Fixed donations payments and added detailed payments logs --- lib/blockUnlocker.js | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/lib/blockUnlocker.js b/lib/blockUnlocker.js index d41074ff8..106fe9312 100644 --- a/lib/blockUnlocker.js +++ b/lib/blockUnlocker.js @@ -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([ @@ -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]; }); @@ -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]]); }); } });