Don't re-create locks empty type, return breakdown (#1524)

* Don't re-create locks empty type

* Return the actual inv. lock information
This commit is contained in:
Jaco Greeff
2019-11-01 16:42:19 +01:00
committed by GitHub
parent 6aff7db89a
commit d41f6ec3ef
2 changed files with 8 additions and 5 deletions
+6 -4
View File
@@ -21,15 +21,16 @@ type Result = [AccountId, BlockNumber, ResultBalance, Index];
function calcBalances ([accountId, bestNumber, [freeBalance, reservedBalance, locks, vesting], accountNonce]: Result): DerivedBalances {
let lockedBalance = createType('Balance');
let lockedBreakdown: BalanceLock[] = [];
if (Array.isArray(locks)) {
// only get the locks that are valid until passed the current block
const totals = locks.filter((value): boolean => bestNumber && value.until.gt(bestNumber));
lockedBreakdown = locks.filter(({ until }): boolean => bestNumber && until.gt(bestNumber));
// get the maximum of the locks according to https://github.com/paritytech/substrate/blob/master/srml/balances/src/lib.rs#L699
lockedBalance = totals[0]
? createType('Balance', bnMax(...totals.map(({ amount }): Balance => amount)))
: createType('Balance');
if (lockedBreakdown.length) {
lockedBalance = createType('Balance', bnMax(...lockedBreakdown.map(({ amount }): Balance => amount)));
}
}
// offset = balance locked at genesis, perBlock is the unlock amount
@@ -52,6 +53,7 @@ function calcBalances ([accountId, bestNumber, [freeBalance, reservedBalance, lo
availableBalance,
freeBalance,
lockedBalance,
lockedBreakdown,
reservedBalance,
vestedBalance,
votingBalance: createType('Balance', freeBalance.add(reservedBalance))
+2 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, AccountIndex, Balance, BlockNumber, EraIndex, Exposure, Index, RewardDestination, SessionIndex, SetIndex, StakingLedger, ValidatorPrefs, Vote, VoteIndex } from '@polkadot/types/interfaces';
import { AccountId, AccountIndex, Balance, BalanceLock, BlockNumber, EraIndex, Exposure, Index, RewardDestination, SessionIndex, SetIndex, StakingLedger, ValidatorPrefs, Vote, VoteIndex } from '@polkadot/types/interfaces';
import BN from 'bn.js';
import { u32 } from '@polkadot/types';
@@ -18,6 +18,7 @@ export interface DerivedBalances {
accountNonce: Index;
freeBalance: Balance;
lockedBalance: Balance;
lockedBreakdown: BalanceLock[];
availableBalance: Balance;
reservedBalance: Balance;
votingBalance: Balance;