Include api.consts in api.derive methods (#1084)

* Bring back derive changes

* Fix fees tests

* contract fees for v1.0

* Contract fees v1.0 test

* Bring back console.logs

* Uase api.consts instead

* linter fixes

* more linter nits

* Fixed staking & session

* .skip()

* Formatting nits
This commit is contained in:
Stefanie Doll
2019-07-10 16:56:11 +02:00
committed by Jaco Greeff
parent 50a3a40cfd
commit 1393c8c5cf
7 changed files with 195 additions and 63 deletions
+5 -4
View File
@@ -2,6 +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 BN from 'bn.js';
import { combineLatest, of, Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { ApiInterface$Rx } from '@polkadot/api/types';
@@ -32,8 +33,8 @@ function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalan
// offset = balance locked at genesis, perBlock is the unlock amount
const { offset, perBlock } = vesting.unwrapOr(new VestingSchedule());
const vestedNow = perBlock.mul(bestNumber);
const vestedBalance = vestedNow.gt(offset)
const vestedNow: BN = perBlock.mul(bestNumber);
const vestedBalance: BN = vestedNow.gt(offset)
? freeBalance
: freeBalance.sub(offset).add(vestedNow);
@@ -42,7 +43,7 @@ function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalan
// The locked is > the vested and ended up with the locked > free,
// i.e. related to https://github.com/paritytech/polkadot/issues/225
// (most probably due to movements from stash -> controller -> free)
const availableBalance = bnMax(ZERO, vestedBalance.sub(lockedBalance));
const availableBalance: BN = bnMax(ZERO, vestedBalance.sub(lockedBalance));
return {
accountId,
@@ -58,7 +59,7 @@ function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalan
/**
* @name all
* @param {( ccountIndex | AccountId | Address | string )} address - An accounts Id in different formats.
* @param {( AccountIndex | AccountId | Address | string )} address - An accounts Id in different formats.
* @returns An object containing the combined results of the storage queries for
* all relevant fees as declared in the substrate chain spec.
* @example
+13 -9
View File
@@ -11,8 +11,6 @@ import { map } from 'rxjs/operators';
import { drr } from '../util/drr';
const ZERO = new BN(0);
/**
* @name fees
* @returns An object containing the combined results of the storage queries for
@@ -29,19 +27,25 @@ const ZERO = new BN(0);
export function fees (api: ApiInterface$Rx) {
return (): Observable<DerivedFees> => {
return (
// HACK This is a very quick fix to actually get the types in to continue with
// other work - so as of now, the fees are completely broken
api.query.balances.creationFee
? api.queryMulti([
api.consts.balances
? of([
// get values from api.const for substrate versions post spec_version: 101
// https://github.com/paritytech/substrate/pull/2883/files#diff-5e5e1c3aec9ddfde0a9054d062ab3db9R131
api.consts.balances.creationFee,
api.consts.balances.existentialDeposit,
api.consts.balances.transactionBaseFee,
api.consts.balances.transactionByteFee,
api.consts.balances.transferFee
]) as any as Observable<[BN, BN, BN, BN, BN]>
: api.queryMulti([
// Support older versions and get values from storage
api.query.balances.creationFee,
api.query.balances.existentialDeposit,
api.query.balances.transactionBaseFee,
api.query.balances.transactionByteFee,
api.query.balances.transferFee
]) as any as Observable<[BN, BN, BN, BN, BN]>
: of([ZERO, ZERO, ZERO, ZERO, ZERO])
).pipe(
map(([creationFee, existentialDeposit, transactionBaseFee, transactionByteFee, transferFee]) => ({
).pipe(map(([creationFee, existentialDeposit, transactionBaseFee, transactionByteFee, transferFee]) => ({
creationFee,
existentialDeposit,
transactionBaseFee,