BlockNumber, Nonce -> u32 (#1284)

* BlockNumber -> u32

* Interface types extend, not re-use

* Merge master, rebuild

* Merge typo

* Lazy create struct types (extended definitions)

* Cleanup tests for Nonce u32

* Remove polkadot u64 BlockNumber (substrate default)

* Warn on type dup & still clear

* Allow type overrides to work at any point
This commit is contained in:
Jaco Greeff
2019-08-11 15:07:00 +02:00
committed by GitHub
parent 1aa7899a7a
commit e5cc6836eb
17 changed files with 126 additions and 84 deletions
+4 -7
View File
@@ -18,11 +18,8 @@ import { drr } from '../util/drr';
type Result = [AccountId | undefined, BlockNumber | undefined, [Balance?, Balance?, BalanceLock[]?, Option<VestingSchedule>?, Index?]];
const EMPTY_ACCOUNT = createType('AccountId');
const ZERO = createType('Balance', 0);
function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalance = ZERO, reservedBalance = ZERO, locks = [], vesting = new Option<VestingSchedule>(ClassOf('VestingSchedule'), null), accountNonce = ZERO]]: Result): DerivedBalances {
let lockedBalance = ZERO;
function calcBalances ([accountId = createType('AccountId'), bestNumber = createType('Balance'), [freeBalance = createType('Balance'), reservedBalance = createType('Balance'), locks = [], vesting = new Option<VestingSchedule>(ClassOf('VestingSchedule'), null), accountNonce = createType('Balance')]]: Result): DerivedBalances {
let lockedBalance = createType('Balance');
if (Array.isArray(locks)) {
// only get the locks that are valid until passed the current block
@@ -30,7 +27,7 @@ function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalan
// get the maximum of the locks according to https://github.com/paritytech/substrate/blob/master/srml/balances/src/lib.rs#L699
lockedBalance = totals[0]
? bnMax(...totals.map(({ amount }): Balance => amount)) as Balance
: ZERO;
: createType('Balance');
}
// offset = balance locked at genesis, perBlock is the unlock amount
@@ -45,7 +42,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: BN = bnMax(ZERO, vestedBalance.sub(lockedBalance));
const availableBalance: BN = bnMax(createType('Balance'), vestedBalance.sub(lockedBalance));
return {
accountId,
@@ -5,11 +5,11 @@
import { AccountId, Header } from '@polkadot/types/interfaces';
import { AnyJsonObject, Constructor } from '@polkadot/types/types';
import { ClassOf } from '@polkadot/types';
import runtimeTypes from '@polkadot/types/interfaces/runtime/definitions';
import { Struct } from '@polkadot/types';
// This is a bit hacky, but is exactly what it resolves to when compiled -
// and as a bonus is gets the typing right
const _Header: Constructor<Header> = ClassOf('Header');
// @ts-ignore
const _Header: Constructor<Header> = Struct.with(runtimeTypes.types.Header);
/**
* @name HeaderExtended
@@ -6,11 +6,11 @@ import { ReferendumIndex, ReferendumInfo } from '@polkadot/types/interfaces/demo
import { AnyJsonObject, Constructor } from '@polkadot/types/types';
import BN from 'bn.js';
import { ClassOf, createType } from '@polkadot/types';
import democracyTypes from '@polkadot/types/interfaces/democracy/definitions';
import { Struct, createType } from '@polkadot/types';
// This is a bit hacky, but is exactly what it resolves to when compiled -
// and as a bonus is gets the typing right
const _ReferendumInfo: Constructor<ReferendumInfo> = ClassOf('ReferendumInfo');
// @ts-ignore
const _ReferendumInfo: Constructor<ReferendumInfo> = Struct.with(democracyTypes.types.ReferendumInfo);
/**
* @name ReferendumInfoExtended