Convert all type/* (and some primitives) to srml/* (#1189)
* Convert (almost-all) non-primitives (and some primitives) to srml/* * Move Vote to primitives, remove type folder * Move Balance :-o * Fixup tests, override Balance.toRaw()
This commit is contained in:
@@ -3,12 +3,13 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BalanceLock, VestingSchedule } from '@polkadot/types/srml/balances/types';
|
||||
import { Balance, BlockNumber, Index } from '@polkadot/types/srml/runtime/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { combineLatest, of, Observable } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, AccountIndex, Address, Balance, BlockNumber, ClassOf, Index, Option, createType } from '@polkadot/types';
|
||||
import { AccountId, AccountIndex, Address, ClassOf, Option, createType } from '@polkadot/types';
|
||||
import { bnMax } from '@polkadot/util';
|
||||
|
||||
import { idAndIndex } from '../accounts/idAndIndex';
|
||||
@@ -19,7 +20,7 @@ import { drr } from '../util/drr';
|
||||
type Result = [AccountId | undefined, BlockNumber | undefined, [Balance?, Balance?, BalanceLock[]?, Option<VestingSchedule>?, Index?]];
|
||||
|
||||
const EMPTY_ACCOUNT = new AccountId();
|
||||
const ZERO = new Balance(0);
|
||||
const ZERO = createType<Balance>('Balance', 0);
|
||||
|
||||
function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalance = ZERO, reservedBalance = ZERO, locks = [], vesting = new Option<VestingSchedule>(ClassOf<VestingSchedule>('VestingSchedule'), null), accountNonce = ZERO]]: Result): DerivedBalances {
|
||||
let lockedBalance = ZERO;
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BlockNumber } from '@polkadot/types/srml/types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { BlockNumber, Header } from '@polkadot/types';
|
||||
import { Header } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BlockNumber } from '@polkadot/types/srml/types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { BlockNumber, Header } from '@polkadot/types';
|
||||
import { Header } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BlockNumber } from '@polkadot/types/srml/types';
|
||||
|
||||
import { Observable, combineLatest } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { BlockNumber } from '@polkadot/types';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
import { bestNumber } from './bestNumber';
|
||||
@@ -31,7 +33,7 @@ export function bestNumberLag (api: ApiInterfaceRx): () => Observable<BlockNumbe
|
||||
bestNumberFinalized(api)()
|
||||
]).pipe(
|
||||
map(([bestNumber, bestNumberFinalized]): BlockNumber =>
|
||||
new BlockNumber(bestNumber.sub(bestNumberFinalized))
|
||||
createType('BlockNumber', bestNumber.sub(bestNumberFinalized))
|
||||
),
|
||||
drr()
|
||||
);
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Balance } from '@polkadot/types/srml/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { combineLatest, Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Balance, Vector, Vote } from '@polkadot/types';
|
||||
import { AccountId, Vector, Vote, createType } from '@polkadot/types';
|
||||
|
||||
import { DerivedBalances, DerivedReferendumVote } from '../types';
|
||||
import { drr } from '../util/drr';
|
||||
@@ -26,7 +28,7 @@ export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | nu
|
||||
map(([votersFor, votes, balances]): DerivedReferendumVote[] =>
|
||||
votersFor.map((accountId, index): DerivedReferendumVote => ({
|
||||
accountId,
|
||||
balance: balances[index].votingBalance || new Balance(0),
|
||||
balance: balances[index].votingBalance || createType<Balance>('Balance', 0),
|
||||
vote: votes[index] || new Vote(0)
|
||||
} as unknown as DerivedReferendumVote))
|
||||
),
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SetIndex, VoteIndex } from '@polkadot/types/srml/elections/types';
|
||||
import { BlockNumber } from '@polkadot/types/srml/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, BlockNumber } from '@polkadot/types';
|
||||
import { AccountId } from '@polkadot/types';
|
||||
|
||||
import { DerivedElectionsInfo } from '../types';
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BlockNumber } from '@polkadot/types/srml/types';
|
||||
import { DerivedSessionInfo } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { BlockNumber, Option } from '@polkadot/types';
|
||||
import { Option } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
import { bestNumber } from '../chain';
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BlockNumber } from '@polkadot/types/srml/runtime/types';
|
||||
import { Keys } from '@polkadot/types/srml/session/types';
|
||||
import { Exposure, RewardDestination, ValidatorPrefs } from '@polkadot/types/srml/staking/types';
|
||||
import { Exposure, RewardDestination, StakingLedger, UnlockChunk, ValidatorPrefs } from '@polkadot/types/srml/staking/types';
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { DerivedStaking, DerivedUnlocking } from '../types';
|
||||
@@ -11,7 +12,7 @@ import { DerivedStaking, DerivedUnlocking } from '../types';
|
||||
import BN from 'bn.js';
|
||||
import { combineLatest, Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { AccountId, BlockNumber, Option, StakingLedger, Tuple, Vector, UnlockChunk } from '@polkadot/types';
|
||||
import { createType, AccountId, Option, Tuple, Vector } from '@polkadot/types';
|
||||
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
|
||||
@@ -24,9 +25,9 @@ function groupByEra (list: UnlockChunk[]): Record<string, BN> {
|
||||
const key = era.toString();
|
||||
|
||||
if (!map[key]) {
|
||||
map[key] = value;
|
||||
map[key] = value.unwrap();
|
||||
} else {
|
||||
map[key] = map[key].add(value);
|
||||
map[key] = map[key].add(value.unwrap());
|
||||
}
|
||||
|
||||
return map;
|
||||
@@ -46,7 +47,7 @@ function calculateUnlocking (stakingLedger: StakingLedger | undefined, eraLength
|
||||
|
||||
// select the Unlockchunks that can't be redeemed yet.
|
||||
const unlockingChunks = stakingLedger.unlocking.filter((chunk): boolean =>
|
||||
remainingBlocks(chunk.era, eraLength, bestNumber).gtn(0)
|
||||
remainingBlocks(chunk.era.unwrap(), eraLength, bestNumber).gtn(0)
|
||||
);
|
||||
|
||||
if (!unlockingChunks.length) {
|
||||
@@ -57,7 +58,7 @@ function calculateUnlocking (stakingLedger: StakingLedger | undefined, eraLength
|
||||
const groupedResult = groupByEra(unlockingChunks);
|
||||
const results = Object.entries(groupedResult).map(([eraString, value]): { value: BN; remainingBlocks: BN } => ({
|
||||
value,
|
||||
remainingBlocks: remainingBlocks(new BlockNumber(eraString), eraLength, bestNumber)
|
||||
remainingBlocks: remainingBlocks(createType<BlockNumber>('BlockNumber', eraString), eraLength, bestNumber)
|
||||
}));
|
||||
|
||||
return results.length ? results : undefined;
|
||||
@@ -69,10 +70,8 @@ function redeemableSum (stakingLedger: StakingLedger | undefined, eraLength: BN,
|
||||
}
|
||||
|
||||
return stakingLedger.unlocking
|
||||
.filter((chunk): boolean => remainingBlocks(chunk.era, eraLength, bestNumber).eqn(0))
|
||||
.reduce((curr, prev): BN => {
|
||||
return curr.add(prev.value);
|
||||
}, new BN(0));
|
||||
.filter((chunk): boolean => remainingBlocks(chunk.era.unwrap(), eraLength, bestNumber).eqn(0))
|
||||
.reduce((curr, prev): BN => curr.add(prev.value.unwrap()), new BN(0));
|
||||
}
|
||||
|
||||
function unwrapSessionIds (stashId: AccountId, validatorIds: AccountId[], auraIds: AccountId[], nextKeys: Option<AccountId> | Vector<Tuple>): { nextSessionId?: AccountId; sessionId?: AccountId } {
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SetIndex, VoteIndex } from '@polkadot/types/srml/elections/types';
|
||||
import { Exposure, RewardDestination, ValidatorPrefs } from '@polkadot/types/srml/staking/types';
|
||||
import { Balance, BlockNumber, Index } from '@polkadot/types/srml/runtime/types';
|
||||
import { Exposure, RewardDestination, StakingLedger, ValidatorPrefs } from '@polkadot/types/srml/staking/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { AccountId, Balance, BlockNumber, Index, StakingLedger, Vote } from '@polkadot/types';
|
||||
import { AccountId, Vote } from '@polkadot/types';
|
||||
|
||||
export interface DerivedBalances {
|
||||
accountId: AccountId;
|
||||
|
||||
Reference in New Issue
Block a user