From 8a58c40b6b1d8315649a6e0428b228dacf9accb8 Mon Sep 17 00:00:00 2001 From: Alex Yocom-Piatt Date: Wed, 24 Feb 2016 17:16:33 +0000 Subject: [PATCH] Fix reward calculations since voters will return 0 and goof up the calculations --- lib/Rpc.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/Rpc.js b/lib/Rpc.js index 648262c2e..b1406ae22 100644 --- a/lib/Rpc.js +++ b/lib/Rpc.js @@ -112,18 +112,19 @@ Rpc.getBlock = function(hash, cb) { } // Number of voters for the block in question - var voters = info.result.voters; + var votersProportion = info.result.voters == 0 ? 1 : info.result.voters / 5; // Calculate the 3 different portions of block reward - var work = Math.round(base * workProportion / 10 * voters / 5); - var stake = Math.round(base * stakeProportion / 10 * voters / 5); - var tax = Math.round(base * taxProportion / 10 * voters / 5); + + var work = base * workProportion / 10 * votersProportion; + var stake = base * stakeProportion / 10 * votersProportion; + var tax = base * taxProportion / 10 * votersProportion; // If block height is below mainnet voting height, leave out stake if (info.result.height < 4096) { - info.result.reward = (work + tax) / bitcore.util.COIN; + info.result.reward = Math.round(work + tax) / bitcore.util.COIN; } else { - info.result.reward = (work + stake + tax) / bitcore.util.COIN; + info.result.reward = Math.round(work + stake + tax) / bitcore.util.COIN; } } return cb(err,info.result);