diff --git a/packages/api-derive/src/elections/info.ts b/packages/api-derive/src/elections/info.ts index 84f69c7d46..a826c46b7d 100644 --- a/packages/api-derive/src/elections/info.ts +++ b/packages/api-derive/src/elections/info.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { AccountId, Balance, BlockNumber, SetIndex, VoteIndex } from '@polkadot/types/interfaces'; -import { Codec } from '@polkadot/types/types'; +import { ITuple } from '@polkadot/types/types'; import { Observable, combineLatest } from 'rxjs'; import { map } from 'rxjs/operators'; @@ -13,7 +13,7 @@ import { createType, Vec, u32 } from '@polkadot/types'; import { DerivedElectionsInfo } from '../types'; import { memo } from '../util'; -type ResultElectionsInner = [u32, u32, Vec<[AccountId, BlockNumber] & Codec>, SetIndex, BlockNumber, VoteIndex, SetIndex]; +type ResultElectionsInner = [u32, u32, Vec>, SetIndex, BlockNumber, VoteIndex, SetIndex]; type ResultElections = [Vec, ResultElectionsInner]; function deriveElections ([candidates, [candidateCount, desiredSeats, members, nextVoterSet, termDuration, voteCount, voterCount]]: ResultElections): DerivedElectionsInfo { @@ -53,7 +53,8 @@ function derivePhragmen (candidates: AccountId[], members: [AccountId, Balance][ candidacyBond, desiredSeats, members, - runnersUp, + // place in most-likely-to-be-in order + runnersUp: runnersUp.reverse(), termDuration, votingBond }; @@ -64,8 +65,8 @@ function queryPhragmen (api: ApiInterfaceRx): Observable { // we are not using multi queries here, so empty array is empty (instead of space-filled) return combineLatest([ api.query.electionsPhragmen.candidates>(), - api.query.electionsPhragmen.members>(), - api.query.electionsPhragmen.runnersUp>() + api.query.electionsPhragmen.members>>(), + api.query.electionsPhragmen.runnersUp>>() ]).pipe( map(([candidates, members, runnersUp]): DerivedElectionsInfo => derivePhragmen( candidates, diff --git a/packages/api-derive/src/staking/controllers.ts b/packages/api-derive/src/staking/controllers.ts index 63bb63f1c2..8e731e121c 100644 --- a/packages/api-derive/src/staking/controllers.ts +++ b/packages/api-derive/src/staking/controllers.ts @@ -3,22 +3,24 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ApiInterfaceRx } from '@polkadot/api/types'; -import { AccountId } from '@polkadot/types/interfaces'; -import { Codec } from '@polkadot/types/types'; +import { AccountId, ValidatorPrefs } from '@polkadot/types/interfaces'; +import { ITuple } from '@polkadot/types/types'; import { Observable, combineLatest, of } from 'rxjs'; import { switchMap } from 'rxjs/operators'; -import { Option } from '@polkadot/types'; +import { Option, Vec } from '@polkadot/types'; import { memo } from '../util'; +type DeriveControllers = [AccountId[], Option[]]; + /** * @description From the list of stash accounts, retrieve the list of controllers */ -export function controllers (api: ApiInterfaceRx): () => Observable<[AccountId[], Option[]]> { +export function controllers (api: ApiInterfaceRx): () => Observable { return memo((): Observable<[AccountId[], Option[]]> => - api.query.staking.validators<[AccountId[]] & Codec>().pipe( - switchMap(([stashIds]): Observable<[AccountId[], Option[]]> => + api.query.staking.validators, Vec]>>().pipe( + switchMap(([stashIds]): Observable => combineLatest([ of(stashIds), // for V2, don't return all the controllers, we call bonded at a later point diff --git a/packages/api-derive/src/staking/recentlyOffline.ts b/packages/api-derive/src/staking/recentlyOffline.ts index 73ae32433c..1931f9347b 100644 --- a/packages/api-derive/src/staking/recentlyOffline.ts +++ b/packages/api-derive/src/staking/recentlyOffline.ts @@ -2,18 +2,18 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { ApiInterfaceRx } from '@polkadot/api/types'; import { AccountId, BlockNumber } from '@polkadot/types/interfaces'; -import { Codec } from '@polkadot/types/types'; +import { ITuple } from '@polkadot/types/types'; +import { DerivedRecentlyOffline } from '../types'; -import BN from 'bn.js'; import { Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; -import { ApiInterfaceRx } from '@polkadot/api/types'; -import { DerivedRecentlyOffline } from '../types'; +import { Vec, u32 } from '@polkadot/types'; import { memo } from '../util'; -type OfflineResult = [AccountId, BlockNumber, BN][] & Codec; +type OfflineResult = Vec>; function expandDerived (recentlyOffline: OfflineResult): DerivedRecentlyOffline { return recentlyOffline.reduce((result: DerivedRecentlyOffline, [accountId, blockNumber, count]): DerivedRecentlyOffline => {