Skip to content

Commit c822d8a

Browse files
committed
Fixed donations payments and added detailed payments logs
1 parent 175470f commit c822d8a

1 file changed

Lines changed: 8 additions & 22 deletions

File tree

lib/blockUnlocker.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,8 @@ var apiInterfaces = require('./apiInterfaces.js')(config.daemon, config.wallet,
55
var logSystem = 'unlocker';
66
require('./exceptionWriter.js')(logSystem);
77

8-
98
log('info', logSystem, 'Started');
109

11-
12-
//Use this in payment processing to get block info once batch RPC is supported
13-
/*
14-
var batchArray = [
15-
['getblockheaderbyheight', {height: 21}],
16-
['getblockheaderbyheight', {height: 22}],
17-
['getblockheaderbyheight', {height: 23
18-
}]
19-
];
20-
21-
apiInterfaces.batchRpcDaemon(batchArray, function(error, response){
22-
23-
});
24-
*/
25-
26-
2710
function runInterval(){
2811
async.waterfall([
2912

@@ -96,7 +79,6 @@ function runInterval(){
9679
//Get worker shares for each unlocked block
9780
function(blocks, callback){
9881

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

182164
if (Object.keys(donations).length) {
183165
for(var wallet in donations) {
184-
var percent = donations[wallet];
166+
var percent = donations[wallet] / 100;
185167
feePercent += percent;
186-
payments[wallet] = block.reward * (percent / 100);
168+
payments[wallet] = Math.round(block.reward * percent);
169+
log('info', logSystem, 'Block %d donation to %s as %d percent of reward: %d', [block.height, wallet, percent, payments[wallet]]);
187170
}
188171
}
189172

190-
var reward = block.reward - (block.reward * feePercent);
173+
var reward = Math.round(block.reward - (block.reward * feePercent));
174+
175+
log('info', logSystem, 'Unlocked %d block with reward %d and donation fee %d. Miners reward: %d', [block.height, block.reward, feePercent, reward]);
191176

192177
if (block.workerShares) {
193178
var totalShares = parseInt(block.shares);
194179
Object.keys(block.workerShares).forEach(function (worker) {
195180
var percent = block.workerShares[worker] / totalShares;
196-
var workerReward = reward * percent;
181+
var workerReward = Math.round(reward * percent);
197182
payments[worker] = (payments[worker] || 0) + workerReward;
183+
log('info', logSystem, 'Block %d payment to %s for %d shares: %d', [block.height, worker, totalShares, payments[worker]]);
198184
});
199185
}
200186
});

0 commit comments

Comments
 (0)