Skip to content

Commit

Permalink
Merge e84c59c into dd51e5a
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejBaj committed Mar 2, 2017
2 parents dd51e5a + e84c59c commit 4c9b038
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 2,091 deletions.
31 changes: 31 additions & 0 deletions helpers/RoundChanges.js
@@ -0,0 +1,31 @@
'use strict';

var bignum = require('./bignum');
var slots = require('./slots');

// Constructor
function RoundChanges (scope) {
if (scope.backwards) {
this.roundFees = Math.floor(scope.__private.unFeesByRound[scope.round]) || 0;
this.roundRewards = (scope.__private.unRewardsByRound[scope.round] || []);
} else {
this.roundFees = Math.floor(scope.__private.feesByRound[scope.round]) || 0;
this.roundRewards = (scope.__private.rewardsByRound[scope.round] || []);
}
}

// Public methods
RoundChanges.prototype.at = function (index) {
var fees = new bignum(this.roundFees.toPrecision(15)).dividedBy(slots.delegates).floor();
var feesRemaining = new bignum(this.roundFees.toPrecision(15)).minus(fees.times(slots.delegates));
var rewards = new bignum(this.roundRewards[index].toPrecision(15)).floor() || 0;

return {
fees: Number(fees.toFixed()),
feesRemaining: Number(feesRemaining.toFixed()),
rewards: Number(rewards.toFixed()),
balance: Number(fees.add(rewards).toFixed())
};
};

module.exports = RoundChanges;

0 comments on commit 4c9b038

Please sign in to comment.