Convert RPC classes to primitive classes or /srml types (#1192)
* Convert RPC classes to primitive classes or /srml types * Lint passes... lokking at tests next. * Tests pass. * Types with basic docs (lots of work here) * Update StorageKey.spec.ts * Add injector to metadata doc generation * Fix import
This commit is contained in:
@@ -6,7 +6,7 @@ import { Observable } from 'rxjs';
|
||||
import { map, startWith } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/primitive/AccountIndex';
|
||||
import { AccountId, AccountIndex, Vector } from '@polkadot/types';
|
||||
import { AccountId, AccountIndex, Vec } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
@@ -30,7 +30,7 @@ export function indexToId (api: ApiInterfaceRx): (accountIndex: AccountIndex | s
|
||||
? _accountIndex
|
||||
: new AccountIndex(_accountIndex);
|
||||
|
||||
return (querySection.enumSet<Vector<AccountId>>(accountIndex.div(ENUMSET_SIZE)))
|
||||
return (querySection.enumSet<Vec<AccountId>>(accountIndex.div(ENUMSET_SIZE)))
|
||||
.pipe(
|
||||
startWith([]),
|
||||
map((accounts): AccountId | undefined =>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, AccountIndex, Address, Vector } from '@polkadot/types';
|
||||
import { AccountId, AccountIndex, Address, Vec } from '@polkadot/types';
|
||||
|
||||
import { idAndIndex } from '../accounts/idAndIndex';
|
||||
import { DerivedBalances } from '../types';
|
||||
@@ -17,7 +17,7 @@ export function votingBalancesNominatorsFor (api: ApiInterfaceRx): (address: Acc
|
||||
return idAndIndex(api)(address).pipe(
|
||||
switchMap(([accountId]): Observable<AccountId[]> =>
|
||||
accountId
|
||||
? (api.query.staking.nominatorsFor<Vector<AccountId>>(accountId))
|
||||
? (api.query.staking.nominatorsFor<Vec<AccountId>>(accountId))
|
||||
: of([] as AccountId[])
|
||||
),
|
||||
switchMap(votingBalances(api)),
|
||||
|
||||
@@ -8,7 +8,7 @@ import BN from 'bn.js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Option, Vector } from '@polkadot/types';
|
||||
import { Option, Vec } from '@polkadot/types';
|
||||
|
||||
import { ReferendumInfoExtended } from '../type';
|
||||
import { drr } from '../util/drr';
|
||||
@@ -19,7 +19,7 @@ export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) =
|
||||
return (
|
||||
!ids || !ids.length
|
||||
? of([] as Option<ReferendumInfo>[])
|
||||
: api.query.democracy.referendumInfoOf.multi(ids) as Observable<Vector<Option<ReferendumInfo>>>
|
||||
: api.query.democracy.referendumInfoOf.multi(ids) as Observable<Vec<Option<ReferendumInfo>>>
|
||||
).pipe(
|
||||
map((infos): Option<ReferendumInfoExtended>[] =>
|
||||
ids.map((id, index): Option<ReferendumInfoExtended> =>
|
||||
|
||||
@@ -8,7 +8,7 @@ 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, Vector, Vote, createType } from '@polkadot/types';
|
||||
import { AccountId, Vec, Vote, createType } from '@polkadot/types';
|
||||
|
||||
import { DerivedBalances, DerivedReferendumVote } from '../types';
|
||||
import { drr } from '../util/drr';
|
||||
@@ -17,8 +17,8 @@ import { votingBalances } from '../balances/votingBalances';
|
||||
|
||||
export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | number) => Observable<DerivedReferendumVote[]> {
|
||||
return (referendumId: BN | number): Observable<DerivedReferendumVote[]> =>
|
||||
(api.query.democracy.votersFor<Vector<AccountId>>(referendumId)).pipe(
|
||||
switchMap((votersFor): Observable<[Vector<AccountId>, Vote[], DerivedBalances[]]> =>
|
||||
(api.query.democracy.votersFor<Vec<AccountId>>(referendumId)).pipe(
|
||||
switchMap((votersFor): Observable<[Vec<AccountId>, Vote[], DerivedBalances[]]> =>
|
||||
combineLatest([
|
||||
of(votersFor),
|
||||
votes(api)(referendumId as BN, votersFor),
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import BN from 'bn.js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Vector, Vote } from '@polkadot/types';
|
||||
import { AccountId, Vec, Vote } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
@@ -19,6 +19,6 @@ export function votes (api: ApiInterfaceRx): (referendumId: BN, accountIds?: Acc
|
||||
[referendumId, accountId]
|
||||
)
|
||||
)
|
||||
) as Observable<Vector<Vote>>).pipe(drr());
|
||||
) as Observable<Vec<Vote>>).pipe(drr());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ApprovalFlag, SetIndex } from '@polkadot/types/srml/elections/types';
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AccountId, Vector } from '@polkadot/types';
|
||||
import { AccountId, Vec } from '@polkadot/types';
|
||||
import { switchMap, map } from 'rxjs/operators';
|
||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
||||
import { drr } from '../util/drr';
|
||||
@@ -27,11 +27,11 @@ export function approvalsOf (api: ApiInterfaceRx): (who: AccountId) => Observabl
|
||||
return (who: AccountId): Observable<boolean[][]> =>
|
||||
(api.query.elections.nextVoterSet<SetIndex>())
|
||||
.pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<Vector<ApprovalFlag>[]> =>
|
||||
api.query.elections.approvalsOf.multi([...Array(nextVoterSet.toNumber() + 1).keys()].map((i): [string, number] => [who.toString(), i])) as any as Observable<Vector<ApprovalFlag>[]>
|
||||
switchMap((nextVoterSet: SetIndex): Observable<Vec<ApprovalFlag>[]> =>
|
||||
api.query.elections.approvalsOf.multi([...Array(nextVoterSet.toNumber() + 1).keys()].map((i): [string, number] => [who.toString(), i])) as any as Observable<Vec<ApprovalFlag>[]>
|
||||
),
|
||||
map((votes: Vector<ApprovalFlag>[]): boolean[][] =>
|
||||
votes.map((flags: Vector<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags))
|
||||
map((votes: Vec<ApprovalFlag>[]): boolean[][] =>
|
||||
votes.map((flags: Vec<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags))
|
||||
),
|
||||
drr()
|
||||
);
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ApprovalFlag, SetIndex } from '@polkadot/types/srml/elections/types';
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AccountId, Vector } from '@polkadot/types';
|
||||
import { AccountId, Vec } from '@polkadot/types';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
||||
import { drr } from '../util/drr';
|
||||
@@ -25,9 +25,9 @@ import { drr } from '../util/drr';
|
||||
*/
|
||||
export function approvalsOfAt (api: ApiInterfaceRx): (who: AccountId, at: SetIndex) => Observable<boolean[]> {
|
||||
return (who: AccountId, at: SetIndex): Observable<boolean[]> =>
|
||||
(api.query.elections.approvalsOf<Vector<ApprovalFlag>>([who.toString(), at]))
|
||||
(api.query.elections.approvalsOf<Vec<ApprovalFlag>>([who.toString(), at]))
|
||||
.pipe(
|
||||
map((flags: Vector<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags)),
|
||||
map((flags: Vec<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags)),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { SetIndex } from '@polkadot/types/srml/elections/types';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Vector, Option, createType } from '@polkadot/types';
|
||||
import { AccountId, Vec, Option, createType } from '@polkadot/types';
|
||||
import { DerivedVoterPositions } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@@ -28,11 +28,11 @@ import { drr } from '../util/drr';
|
||||
export function voterPositions (api: ApiInterfaceRx): () => Observable<DerivedVoterPositions> {
|
||||
return (): Observable<DerivedVoterPositions> =>
|
||||
api.query.elections.nextVoterSet<SetIndex>().pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<[BN, Vector<Option<AccountId>>[]]> => combineLatest(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<[BN, Vec<Option<AccountId>>[]]> => combineLatest(
|
||||
of(api.consts.elections.voterSetSize) as any as Observable<BN>,
|
||||
api.query.elections.voters.multi([...Array(+nextVoterSet + 1).keys()].map((_, i): [number] => [i])) as any as Observable<Vector<Option<AccountId>>[]>
|
||||
api.query.elections.voters.multi([...Array(+nextVoterSet + 1).keys()].map((_, i): [number] => [i])) as any as Observable<Vec<Option<AccountId>>[]>
|
||||
)),
|
||||
map((result: [BN, Vector<Option<AccountId>>[]]): DerivedVoterPositions => {
|
||||
map((result: [BN, Vec<Option<AccountId>>[]]): DerivedVoterPositions => {
|
||||
const [setSize, voters] = result;
|
||||
return voters.reduce((result: DerivedVoterPositions, vec, setIndex): DerivedVoterPositions => {
|
||||
vec.forEach((e, index): void => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Vector } from '@polkadot/types';
|
||||
import { AccountId, Vec } from '@polkadot/types';
|
||||
import { DerivedVoterPositions } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -23,12 +23,12 @@ import { voterPositions } from './voterPositions';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function voters (api: ApiInterfaceRx): () => Observable<Vector<AccountId>> {
|
||||
return (): Observable<Vector<AccountId>> =>
|
||||
export function voters (api: ApiInterfaceRx): () => Observable<Vec<AccountId>> {
|
||||
return (): Observable<Vec<AccountId>> =>
|
||||
voterPositions(api)().pipe(
|
||||
map(
|
||||
(voterPositions: DerivedVoterPositions): Vector<AccountId> =>
|
||||
new Vector(
|
||||
(voterPositions: DerivedVoterPositions): Vec<AccountId> =>
|
||||
new Vec(
|
||||
AccountId,
|
||||
Object.entries(voterPositions)
|
||||
.sort((a, b): 0 | 1 | -1 => a[1].globalIndex.cmp(b[1].globalIndex))
|
||||
|
||||
@@ -12,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 { createType, AccountId, Option, Tuple, Vector } from '@polkadot/types';
|
||||
import { createType, AccountId, Option, Tuple, Vec } from '@polkadot/types';
|
||||
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
|
||||
@@ -74,7 +74,7 @@ function redeemableSum (stakingLedger: StakingLedger | undefined, eraLength: BN,
|
||||
.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 } {
|
||||
function unwrapSessionIds (stashId: AccountId, validatorIds: AccountId[], auraIds: AccountId[], nextKeys: Option<AccountId> | Vec<Tuple>): { nextSessionId?: AccountId; sessionId?: AccountId } {
|
||||
// for 2.x we have a Vec<(ValidatorId,Keys)> of the keys
|
||||
if (Array.isArray(nextKeys)) {
|
||||
const validatorIdx = validatorIds.indexOf(stashId);
|
||||
@@ -111,7 +111,7 @@ function withStashController (api: ApiInterfaceRx, accountId: AccountId, control
|
||||
// FIXME while we have 2.x and 1.x support, don't add this to .multi -
|
||||
// should be added when only 2.x
|
||||
api.query.aura && api.query.aura.authorities
|
||||
? api.query.aura.authorities<Vector<AccountId>>()
|
||||
? api.query.aura.authorities<Vec<AccountId>>()
|
||||
: of([] as AccountId[]),
|
||||
api.queryMulti([
|
||||
api.query.session.queuedKeys
|
||||
@@ -124,7 +124,7 @@ function withStashController (api: ApiInterfaceRx, accountId: AccountId, control
|
||||
[api.query.staking.stakers, stashId],
|
||||
[api.query.staking.validators, stashId]
|
||||
])
|
||||
]) as Observable<[BN, BlockNumber, AccountId[], [Option<AccountId> | Vector<Tuple>, AccountId[], Option<StakingLedger>, [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]>
|
||||
]) as Observable<[BN, BlockNumber, AccountId[], [Option<AccountId> | Vec<Tuple>, AccountId[], Option<StakingLedger>, [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]>
|
||||
).pipe(
|
||||
map(([eraLength, bestNumber, auraIds, [nextKeys, validatorIds, _stakingLedger, [nominators], rewardDestination, stakers, [validatorPrefs]]]): DerivedStaking => {
|
||||
const stakingLedger = _stakingLedger.unwrapOr(null) || undefined;
|
||||
@@ -159,7 +159,7 @@ function withControllerLedger (api: ApiInterfaceRx, accountId: AccountId, stakin
|
||||
// FIXME while we have 2.x and 1.x support, don't add this to .multi -
|
||||
// should be added when only 2.x
|
||||
api.query.aura && api.query.aura.authorities
|
||||
? api.query.aura.authorities<Vector<AccountId>>()
|
||||
? api.query.aura.authorities<Vec<AccountId>>()
|
||||
: of([] as AccountId[]),
|
||||
api.queryMulti([
|
||||
api.query.session.queuedKeys
|
||||
@@ -171,7 +171,7 @@ function withControllerLedger (api: ApiInterfaceRx, accountId: AccountId, stakin
|
||||
[api.query.staking.stakers, stashId],
|
||||
[api.query.staking.validators, stashId]
|
||||
])
|
||||
]) as Observable<[AccountId[], [Option<AccountId> | Vector<Tuple>, AccountId[], [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]>
|
||||
]) as Observable<[AccountId[], [Option<AccountId> | Vec<Tuple>, AccountId[], [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]>
|
||||
).pipe(
|
||||
map(([auraIds, [nextKeys, validatorIds, [nominators], rewardDestination, stakers, [validatorPrefs]]]): DerivedStaking => {
|
||||
const { nextSessionId, sessionId } = unwrapSessionIds(stashId, validatorIds, auraIds, nextKeys);
|
||||
|
||||
@@ -25,27 +25,27 @@ export default class HeaderExtended extends Header {
|
||||
|
||||
// extract from the substrate 2.0 PreRuntime digest
|
||||
if (pitem) {
|
||||
const preRuntime = pitem.asPreRuntime;
|
||||
const [engine, data] = pitem.asPreRuntime;
|
||||
|
||||
if (preRuntime.engine.isAura) {
|
||||
slot = preRuntime.slot;
|
||||
if (engine.isAura) {
|
||||
slot = engine.extractSlot(data);
|
||||
}
|
||||
} else {
|
||||
const [citem] = header.digest.logsWith('Consensus');
|
||||
|
||||
// extract author from the consensus (substrate 1.0, digest)
|
||||
if (citem) {
|
||||
const consensus = citem.asConsensus;
|
||||
const [engine, data] = citem.asConsensus;
|
||||
|
||||
if (consensus.engine.isAura) {
|
||||
slot = consensus.slot;
|
||||
if (engine.isAura) {
|
||||
slot = engine.extractSlot(data);
|
||||
}
|
||||
} else {
|
||||
const [sitem] = header.digest.logsWith('SealV0');
|
||||
|
||||
// extract author from the seal (pre substrate 1.0, backwards compat)
|
||||
if (sitem) {
|
||||
slot = sitem.asSealV0.slot;
|
||||
slot = sitem.asSealV0[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
import { ApprovalFlag } from '@polkadot/types/srml/elections/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Vector } from '@polkadot/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
export function approvalFlagToBool (flags: Vector<ApprovalFlag>): boolean[] {
|
||||
export function approvalFlagToBool (flags: Vec<ApprovalFlag>): boolean[] {
|
||||
const bools: boolean[] = [];
|
||||
for (const flag of flags) {
|
||||
for (const bit of [...Array(flag.bitLength())].map((_, i): number => i)) {
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
import { ApprovalFlag } from '@polkadot/types/srml/elections/types';
|
||||
|
||||
import { Vector } from '@polkadot/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
export function approvalFlagsToBools (flags: Vector<ApprovalFlag>): boolean[] {
|
||||
export function approvalFlagsToBools (flags: Vec<ApprovalFlag>): boolean[] {
|
||||
const bools: boolean[] = [];
|
||||
|
||||
flags.forEach((flag: ApprovalFlag): void => {
|
||||
|
||||
Reference in New Issue
Block a user