Skip to content

Commit

Permalink
fix: calculate balance from the right lock types
Browse files Browse the repository at this point in the history
  • Loading branch information
liorfrenkel committed Oct 1, 2020
1 parent b7cf935 commit de98fe1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions worker/jobs/blocks/BlocksAdder.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const assetsDAL = require('../../../server/components/api/assets/assetsDAL');
const calcRewardByHeight = require('../../../server/lib/calcRewardByHeight');

const Op = db.Sequelize.Op;
const LOCK_TYPES_FOR_BALANCE = ['Coinbase', 'PK', 'Contract', 'Destroy'];

class BlocksAdder {
constructor(networkHelper, blockchainParser, genesisTotalZp) {
Expand Down Expand Up @@ -447,8 +448,10 @@ class BlocksAdder {
}

// add to outputSum for the asset
const addressObj = addresses.get(address);
addressObj[asset].outputSum = addressObj[asset].outputSum.plus(output.amount);
if (LOCK_TYPES_FOR_BALANCE.includes(output.lockType)) {
const addressObj = addresses.get(address);
addressObj[asset].outputSum = addressObj[asset].outputSum.plus(output.amount);
}
}

// asset
Expand Down Expand Up @@ -476,8 +479,10 @@ class BlocksAdder {
}

// add to inputSum for the asset
const addressObj = addresses.get(address);
addressObj[asset].inputSum = addressObj[asset].inputSum.plus(input.amount);
if (LOCK_TYPES_FOR_BALANCE.includes(input.lockType)) {
const addressObj = addresses.get(address);
addressObj[asset].inputSum = addressObj[asset].inputSum.plus(input.amount);
}
}

// asset
Expand Down

0 comments on commit de98fe1

Please sign in to comment.