diff --git a/packages/api-derive/src/accounts/info.ts b/packages/api-derive/src/accounts/info.ts index 8f16136695..85b1da5e5a 100644 --- a/packages/api-derive/src/accounts/info.ts +++ b/packages/api-derive/src/accounts/info.ts @@ -7,8 +7,8 @@ import { AccountId, AccountIndex, Address, Balance, Registration } from '@polkad import { ITuple } from '@polkadot/types/types'; import { DeriveAccountInfo, DeriveAccountRegistration } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { Bytes, Data, Option, u32 } from '@polkadot/types'; import { u8aToString } from '@polkadot/util'; @@ -86,7 +86,6 @@ function retrieveIdentity (api: ApiInterfaceRx, accountId?: AccountId): Observab ]) : of([undefined, undefined]) ) as Observable<[Option | undefined, Option> | undefined]>).pipe( - observeOn(asyncScheduler), switchMap(([identityOfOpt, superOfOpt]): Observable<[Option | undefined, [AccountId, Data] | undefined]> => { if (identityOfOpt?.isSome) { // this identity has something set @@ -104,7 +103,6 @@ function retrieveIdentity (api: ApiInterfaceRx, accountId?: AccountId): Observab // nothing of value returned return of([undefined, undefined]); }), - observeOn(asyncScheduler), map(([identityOfOpt, superOf]): DeriveAccountRegistration => extractIdentity(identityOfOpt, superOf) ) @@ -118,7 +116,6 @@ function retrieveIdentity (api: ApiInterfaceRx, accountId?: AccountId): Observab export function info (api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | string | null) => Observable { return memo((address?: AccountIndex | AccountId | Address | string | null): Observable => api.derive.accounts.idAndIndex(address).pipe( - observeOn(asyncScheduler), switchMap(([accountId, accountIndex]): Observable<[Partial, DeriveAccountRegistration, string?]> => combineLatest([ of({ accountId, accountIndex }), @@ -126,7 +123,6 @@ export function info (api: ApiInterfaceRx): (address?: AccountIndex | AccountId retrieveNick(api, accountId) ]) ), - observeOn(asyncScheduler), map(([{ accountId, accountIndex }, identity, nickname]): DeriveAccountInfo => ({ accountId, accountIndex, identity, nickname })) diff --git a/packages/api-derive/src/balances/account.ts b/packages/api-derive/src/balances/account.ts index 023237e0c6..8db57f7fb0 100644 --- a/packages/api-derive/src/balances/account.ts +++ b/packages/api-derive/src/balances/account.ts @@ -6,8 +6,8 @@ import { AccountId, AccountData, AccountIndex, AccountInfo, Address, Balance, In import { ITuple } from '@polkadot/types/types'; import { DerivedBalancesAccount } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { memo } from '../util'; @@ -82,7 +82,6 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable Observable { return memo((address: AccountIndex | AccountId | Address | string): Observable => api.derive.accounts.info(address).pipe( - observeOn(asyncScheduler), switchMap(({ accountId }): Observable<[AccountId, Result]> => (accountId ? combineLatest([ @@ -96,7 +95,6 @@ export function account (api: ApiInterfaceRx): (address: AccountIndex | AccountI : of([api.registry.createType('AccountId'), [api.registry.createType('Balance'), api.registry.createType('Balance'), api.registry.createType('Balance'), api.registry.createType('Balance'), api.registry.createType('Index')]]) ) ), - observeOn(asyncScheduler), map((result): DerivedBalancesAccount => calcBalances(api, result)) )); } diff --git a/packages/api-derive/src/balances/all.ts b/packages/api-derive/src/balances/all.ts index 1c55df689a..45ea030bb7 100644 --- a/packages/api-derive/src/balances/all.ts +++ b/packages/api-derive/src/balances/all.ts @@ -6,8 +6,8 @@ import { AccountId, AccountIndex, Address, Balance, BalanceLock, BalanceLockTo21 import { DerivedBalancesAccount, DerivedBalancesAll } from '../types'; import BN from 'bn.js'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { Option, Vec } from '@polkadot/types'; import { bnMax } from '@polkadot/util'; @@ -130,7 +130,6 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable Observable { return memo((address: AccountIndex | AccountId | Address | string): Observable => api.derive.balances.account(address).pipe( - observeOn(asyncScheduler), switchMap((account): Observable => (!account.accountId.isEmpty ? combineLatest([ @@ -143,7 +142,6 @@ export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId | : of([account, api.registry.createType('BlockNumber'), [null, api.registry.createType('Vec')]]) ) ), - observeOn(asyncScheduler), map((result): DerivedBalancesAll => calcBalances(api, result)) )); } diff --git a/packages/api-derive/src/balances/votingBalances.ts b/packages/api-derive/src/balances/votingBalances.ts index eef10f828f..ff18be1d7f 100644 --- a/packages/api-derive/src/balances/votingBalances.ts +++ b/packages/api-derive/src/balances/votingBalances.ts @@ -5,8 +5,7 @@ import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces'; import { DerivedBalancesAccount } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { observeOn } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { memo } from '../util'; @@ -19,6 +18,6 @@ export function votingBalances (api: ApiInterfaceRx): (addresses?: (AccountId | addresses.map((accountId): Observable => api.derive.balances.account(accountId) ) - ).pipe(observeOn(asyncScheduler)) + ) ); } diff --git a/packages/api-derive/src/chain/bestNumberLag.ts b/packages/api-derive/src/chain/bestNumberLag.ts index 9453d6057c..294fc326a8 100644 --- a/packages/api-derive/src/chain/bestNumberLag.ts +++ b/packages/api-derive/src/chain/bestNumberLag.ts @@ -4,8 +4,8 @@ import { BlockNumber } from '@polkadot/types/interfaces'; -import { Observable, asyncScheduler, combineLatest } from 'rxjs'; -import { map, observeOn } from 'rxjs/operators'; +import { Observable, combineLatest } from 'rxjs'; +import { map } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { memo } from '../util'; @@ -29,7 +29,6 @@ export function bestNumberLag (api: ApiInterfaceRx): () => Observable api.registry.createType('BlockNumber', bestNumber.sub(bestNumberFinalized)) ) diff --git a/packages/api-derive/src/chain/getHeader.ts b/packages/api-derive/src/chain/getHeader.ts index 5de051fc37..7f11cb2779 100644 --- a/packages/api-derive/src/chain/getHeader.ts +++ b/packages/api-derive/src/chain/getHeader.ts @@ -4,8 +4,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { catchError, map, observeOn } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { catchError, map } from 'rxjs/operators'; import { HeaderExtended } from '../type'; import { memo } from '../util'; @@ -32,7 +32,6 @@ export function getHeader (api: ApiInterfaceRx): (hash: Uint8Array | string) => ? api.query.session.validators.at(hash) : of([]) ]).pipe( - observeOn(asyncScheduler), map(([header, validators]): HeaderExtended => new HeaderExtended(api.registry, header, validators) ), diff --git a/packages/api-derive/src/chain/subscribeNewHeads.ts b/packages/api-derive/src/chain/subscribeNewHeads.ts index 6061b0cf10..d895bf38d4 100644 --- a/packages/api-derive/src/chain/subscribeNewHeads.ts +++ b/packages/api-derive/src/chain/subscribeNewHeads.ts @@ -4,8 +4,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map } from 'rxjs/operators'; import { HeaderExtended } from '../type'; import { memo } from '../util'; @@ -31,7 +31,6 @@ export function subscribeNewHeads (api: ApiInterfaceRx): () => Observable
new HeaderExtended(api.registry, header, validators) ) diff --git a/packages/api-derive/src/collective/proposals.ts b/packages/api-derive/src/collective/proposals.ts index 5bc9f04e22..bbc51681e0 100644 --- a/packages/api-derive/src/collective/proposals.ts +++ b/packages/api-derive/src/collective/proposals.ts @@ -6,8 +6,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { Hash, Proposal, Votes } from '@polkadot/types/interfaces'; import { DerivedCollectiveProposal } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { Option } from '@polkadot/types'; type Result = [Hash[], Option[], Option[]]; @@ -30,7 +30,6 @@ export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalC return (): Observable => api.query[section]?.proposals ? api.query[section].proposals().pipe( - observeOn(asyncScheduler), switchMap((hashes: Hash[]): Observable => hashes.length ? combineLatest([ @@ -40,7 +39,6 @@ export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalC ]) : of([[], [], []]) ), - observeOn(asyncScheduler), map(parse) ) : of([] as DerivedCollectiveProposal[]); diff --git a/packages/api-derive/src/democracy/proposals.ts b/packages/api-derive/src/democracy/proposals.ts index 68c51a1004..2093e2dd33 100644 --- a/packages/api-derive/src/democracy/proposals.ts +++ b/packages/api-derive/src/democracy/proposals.ts @@ -6,8 +6,8 @@ import { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal } from '@pol import { ITuple } from '@polkadot/types/types'; import { DeriveProposal } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { Bytes, Option, Vec } from '@polkadot/types'; @@ -65,7 +65,6 @@ export function proposals (api: ApiInterfaceRx): () => Observable => api.query.democracy?.publicProps && api.query.democracy?.preimages ? api.query.democracy.publicProps().pipe( - observeOn(asyncScheduler), switchMap((proposals) => combineLatest([ of(proposals), @@ -75,7 +74,6 @@ export function proposals (api: ApiInterfaceRx): () => Observable index)) ]) ), - observeOn(asyncScheduler), map(([proposals, preimages, depositors]): DeriveProposal[] => parse(api, { depositors, proposals, preimages }) ) diff --git a/packages/api-derive/src/democracy/referendumInfos.ts b/packages/api-derive/src/democracy/referendumInfos.ts index 018274e2c4..72536ced7b 100644 --- a/packages/api-derive/src/democracy/referendumInfos.ts +++ b/packages/api-derive/src/democracy/referendumInfos.ts @@ -6,8 +6,8 @@ import { ReferendumInfo } from '@polkadot/types/interfaces/democracy'; import { DerivedReferendum } from '../types'; import BN from 'bn.js'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { Option } from '@polkadot/types'; @@ -21,7 +21,6 @@ export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) = ? of([] as Option[]) : api.query.democracy.referendumInfoOf.multi>(ids) ).pipe( - observeOn(asyncScheduler), switchMap((infos): Observable<(DerivedReferendum | null)[]> => combineLatest( ids.map((id, index): Observable => @@ -29,7 +28,6 @@ export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) = ) ) ), - observeOn(asyncScheduler), map((infos): DerivedReferendum[] => infos.filter((referendum): referendum is DerivedReferendum => !!referendum) ) diff --git a/packages/api-derive/src/democracy/referendumVotesFor.ts b/packages/api-derive/src/democracy/referendumVotesFor.ts index 970196c88e..eb37949681 100644 --- a/packages/api-derive/src/democracy/referendumVotesFor.ts +++ b/packages/api-derive/src/democracy/referendumVotesFor.ts @@ -5,8 +5,8 @@ import { AccountId, Vote } from '@polkadot/types/interfaces'; import BN from 'bn.js'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { Vec } from '@polkadot/types'; @@ -16,7 +16,6 @@ import { memo } from '../util'; export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | number) => Observable { return memo((referendumId: BN | number): Observable => api.query.democracy.votersFor>(referendumId).pipe( - observeOn(asyncScheduler), switchMap((votersFor): Observable<[Vec, Vote[], DerivedBalancesAccount[]]> => combineLatest([ of(votersFor), @@ -24,7 +23,6 @@ export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | nu api.derive.balances.votingBalances(votersFor) ]) ), - observeOn(asyncScheduler), map(([votersFor, votes, balances]): DerivedReferendumVote[] => votersFor.map((accountId, index): DerivedReferendumVote => ({ accountId, diff --git a/packages/api-derive/src/imOnline/receivedHeartbeats.ts b/packages/api-derive/src/imOnline/receivedHeartbeats.ts index 5180e47c35..7024ba4622 100644 --- a/packages/api-derive/src/imOnline/receivedHeartbeats.ts +++ b/packages/api-derive/src/imOnline/receivedHeartbeats.ts @@ -5,8 +5,8 @@ import { AccountId } from '@polkadot/types/interfaces'; import { DerivedHeartbeats } from '../types'; -import { Observable, asyncScheduler, of, combineLatest } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, of, combineLatest } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { Bytes, Option, u32 } from '@polkadot/types'; @@ -19,7 +19,6 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable => api.query.imOnline?.receivedHeartbeats ? api.derive.staking.overview().pipe( - observeOn(asyncScheduler), switchMap(({ currentIndex, validators }): Observable<[AccountId[], Option[], u32[]]> => combineLatest([ of(validators), @@ -29,7 +28,6 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable [currentIndex, address])) ]) ), - observeOn(asyncScheduler), map(([validators, heartbeats, numBlocks]): DerivedHeartbeats => validators.reduce((result: DerivedHeartbeats, validator, index): DerivedHeartbeats => ({ ...result, diff --git a/packages/api-derive/src/parachains/overview.ts b/packages/api-derive/src/parachains/overview.ts index 9a652eb211..e3a32a2a72 100644 --- a/packages/api-derive/src/parachains/overview.ts +++ b/packages/api-derive/src/parachains/overview.ts @@ -6,8 +6,8 @@ import { ParaId } from '@polkadot/types/interfaces'; import { DeriveParachain, DeriveParachainInfo } from '../types'; import { DidUpdate, ParaInfoResult, PendingSwap, RelayDispatchQueueSize } from './types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { memo } from '../util'; @@ -38,7 +38,6 @@ export function overview (api: ApiInterfaceRx): () => Observable => api.query.registrar?.parachains && api.query.parachains ? api.query.registrar.parachains().pipe( - observeOn(asyncScheduler), switchMap((paraIds) => combineLatest([ of(paraIds), @@ -48,7 +47,6 @@ export function overview (api: ApiInterfaceRx): () => Observable(paraIds) ]) ), - observeOn(asyncScheduler), map((result: Result): DeriveParachain[] => parse(result) ) diff --git a/packages/api-derive/src/session/info.ts b/packages/api-derive/src/session/info.ts index 98081f67ef..629c7b417b 100644 --- a/packages/api-derive/src/session/info.ts +++ b/packages/api-derive/src/session/info.ts @@ -5,8 +5,8 @@ import { SessionIndex } from '@polkadot/types/interfaces'; import { DerivedSessionInfo, DeriveSessionIndexes } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { Option, u64 } from '@polkadot/types'; @@ -60,7 +60,6 @@ function queryAura (api: ApiInterfaceRx): Observable { function queryBabe (api: ApiInterfaceRx): Observable<[DeriveSessionIndexes, ResultSlotsFlat]> { return api.derive.session.indexes().pipe( - observeOn(asyncScheduler), switchMap((indexes): Observable<[DeriveSessionIndexes, ResultSlots]> => combineLatest([ of(indexes), @@ -72,7 +71,6 @@ function queryBabe (api: ApiInterfaceRx): Observable<[DeriveSessionIndexes, Resu ]) ]) ), - observeOn(asyncScheduler), map(([indexes, [currentSlot, epochIndex, genesisSlot, optStartIndex]]): [DeriveSessionIndexes, ResultSlotsFlat] => [ indexes, [currentSlot, epochIndex, genesisSlot, optStartIndex.unwrapOr(api.registry.createType('SessionIndex', 1))] ]) @@ -101,7 +99,6 @@ export function info (api: ApiInterfaceRx): () => Observable ? queryBabe(api) // 2.x with Babe : queryBabeNoHistory(api) ).pipe( - observeOn(asyncScheduler), map(([indexes, slots]: [DeriveSessionIndexes, ResultSlotsFlat]): DerivedSessionInfo => createDerived(api, [ [true, api.consts.babe.epochDuration, api.consts.staking.sessionsPerEra], diff --git a/packages/api-derive/src/society/candidates.ts b/packages/api-derive/src/society/candidates.ts index 3835540d70..8ea4ce96e6 100644 --- a/packages/api-derive/src/society/candidates.ts +++ b/packages/api-derive/src/society/candidates.ts @@ -7,8 +7,8 @@ import { AccountId, BalanceOf, Bid, BidKind } from '@polkadot/types/interfaces'; import { ITuple } from '@polkadot/types/types'; import { DeriveSocietyCandidate } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { Option, Vec } from '@polkadot/types'; import { memo } from '../util'; @@ -22,7 +22,6 @@ type Result = [Bid[], ResultSuspend[]] export function candidates (api: ApiInterfaceRx): () => Observable { return memo((): Observable => api.query.society.candidates>().pipe( - observeOn(asyncScheduler), switchMap((candidates: Vec): Observable => combineLatest([ of(candidates), @@ -30,7 +29,6 @@ export function candidates (api: ApiInterfaceRx): () => Observable who)) ]) ), - observeOn(asyncScheduler), map(([candidates, suspended]: Result): DeriveSocietyCandidate[] => candidates.map(({ who, kind, value }, index) => ({ accountId: who, diff --git a/packages/api-derive/src/society/members.ts b/packages/api-derive/src/society/members.ts index 9aa4442b6e..5ca7b50523 100644 --- a/packages/api-derive/src/society/members.ts +++ b/packages/api-derive/src/society/members.ts @@ -6,8 +6,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { AccountId } from '@polkadot/types/interfaces'; import { DeriveSocietyMember } from '../types'; -import { Observable, asyncScheduler, combineLatest } from 'rxjs'; -import { observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest } from 'rxjs'; +import { switchMap } from 'rxjs/operators'; import { memo } from '../util'; @@ -17,7 +17,6 @@ import { memo } from '../util'; export function members (api: ApiInterfaceRx): () => Observable { return memo((): Observable => api.query.society.members().pipe( - observeOn(asyncScheduler), switchMap((members): Observable => combineLatest( members.map((accountId): Observable => diff --git a/packages/api-derive/src/staking/account.ts b/packages/api-derive/src/staking/account.ts index 63323d0068..4ce5647ba9 100644 --- a/packages/api-derive/src/staking/account.ts +++ b/packages/api-derive/src/staking/account.ts @@ -7,8 +7,8 @@ import { Balance, BlockNumber, StakingLedger, UnlockChunk } from '@polkadot/type import { DerivedSessionInfo, DerivedStakingAccount, DerivedStakingQuery, DerivedUnlocking } from '../types'; import BN from 'bn.js'; -import { Observable, asyncScheduler, combineLatest } from 'rxjs'; -import { map, observeOn } from 'rxjs/operators'; +import { Observable, combineLatest } from 'rxjs'; +import { map } from 'rxjs/operators'; import { isUndefined } from '@polkadot/util'; @@ -93,7 +93,6 @@ export function account (api: ApiInterfaceRx): (accountId: Uint8Array | string) api.derive.session.info(), api.derive.staking.query(accountId) ]).pipe( - observeOn(asyncScheduler), map(([sessionInfo, query]: [DerivedSessionInfo, DerivedStakingQuery]) => parseResult(api, sessionInfo, query)) )); diff --git a/packages/api-derive/src/staking/controllers.ts b/packages/api-derive/src/staking/controllers.ts index 607101f876..a65a2d2199 100644 --- a/packages/api-derive/src/staking/controllers.ts +++ b/packages/api-derive/src/staking/controllers.ts @@ -6,8 +6,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { AccountId, ValidatorPrefs } from '@polkadot/types/interfaces'; import { ITuple } from '@polkadot/types/types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { switchMap } from 'rxjs/operators'; import { Option, Vec } from '@polkadot/types'; import { memo } from '../util'; @@ -20,7 +20,6 @@ type DeriveControllers = [AccountId[], Option[]]; export function controllers (api: ApiInterfaceRx): () => Observable { return memo((): Observable<[AccountId[], Option[]]> => api.query.staking.validators, Vec]>>().pipe( - observeOn(asyncScheduler), switchMap(([stashIds]): Observable => combineLatest([ of(stashIds), @@ -29,7 +28,6 @@ export function controllers (api: ApiInterfaceRx): () => Observable>(stashIds) ]) - ), - observeOn(asyncScheduler) + ) )); } diff --git a/packages/api-derive/src/staking/electedInfo.ts b/packages/api-derive/src/staking/electedInfo.ts index 55fa2ece26..cad7315960 100644 --- a/packages/api-derive/src/staking/electedInfo.ts +++ b/packages/api-derive/src/staking/electedInfo.ts @@ -6,15 +6,14 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { AccountId } from '@polkadot/types/interfaces'; import { DerivedStakingQuery, DerivedStakingElected } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { memo } from '../util'; export function electedInfo (api: ApiInterfaceRx): () => Observable { return memo((): Observable => api.derive.staking.validators().pipe( - observeOn(asyncScheduler), switchMap(({ nextElected }): Observable<[AccountId[], DerivedStakingQuery[]]> => combineLatest([ of(nextElected), @@ -25,7 +24,6 @@ export function electedInfo (api: ApiInterfaceRx): () => Observable ({ info, nextElected diff --git a/packages/api-derive/src/staking/erasExposure.ts b/packages/api-derive/src/staking/erasExposure.ts index 682cd52a50..25a6a152fa 100644 --- a/packages/api-derive/src/staking/erasExposure.ts +++ b/packages/api-derive/src/staking/erasExposure.ts @@ -7,8 +7,8 @@ import { EraIndex, Exposure } from '@polkadot/types/interfaces'; import { DeriveEraExposure, DeriveEraNominatorExposure, DeriveEraValidatorExposure } from '../types'; import BN from 'bn.js'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap, take } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { StorageKey } from '@polkadot/types'; import { memo } from '../util'; @@ -38,8 +38,6 @@ function mapStakers (era: EraIndex, stakers: KeysAndExposures): DeriveEraExposur export function eraExposure (api: ApiInterfaceRx): (era: EraIndex) => Observable { return memo((era: EraIndex): Observable => api.query.staking.erasStakersClipped.entries(era).pipe( - observeOn(asyncScheduler), - take(1), map((stakers) => mapStakers(era, stakers)) ) ); @@ -48,7 +46,6 @@ export function eraExposure (api: ApiInterfaceRx): (era: EraIndex) => Observable export function erasExposure (api: ApiInterfaceRx): (withActive?: boolean | BN | number) => Observable { return memo((withActive?: boolean | BN | number): Observable => api.derive.staking.erasHistoric(withActive).pipe( - observeOn(asyncScheduler), switchMap((eras): Observable => eras.length ? combineLatest( diff --git a/packages/api-derive/src/staking/erasPoints.ts b/packages/api-derive/src/staking/erasPoints.ts index 066b0230e1..7b3948b63c 100644 --- a/packages/api-derive/src/staking/erasPoints.ts +++ b/packages/api-derive/src/staking/erasPoints.ts @@ -7,8 +7,8 @@ import { EraIndex, EraRewardPoints } from '@polkadot/types/interfaces'; import { DeriveEraPoints, DeriveEraValPoints } from '../types'; import BN from 'bn.js'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { memo } from '../util'; @@ -25,7 +25,6 @@ function mapValidators ({ individual }: EraRewardPoints): DeriveEraValPoints { export function erasPoints (api: ApiInterfaceRx): (withActive?: boolean | BN | number) => Observable { return memo((withActive?: boolean | number): Observable => api.derive.staking.erasHistoric(withActive).pipe( - observeOn(asyncScheduler), switchMap((eras): Observable<[EraIndex[], EraRewardPoints[]]> => combineLatest([ of(eras), @@ -34,7 +33,6 @@ export function erasPoints (api: ApiInterfaceRx): (withActive?: boolean | BN | n : of([]) ]) ), - observeOn(asyncScheduler), map(([eras, points]): DeriveEraPoints[] => eras.map((era, index): DeriveEraPoints => ({ era, diff --git a/packages/api-derive/src/staking/erasRewards.ts b/packages/api-derive/src/staking/erasRewards.ts index 8d747ad27c..d4df51b332 100644 --- a/packages/api-derive/src/staking/erasRewards.ts +++ b/packages/api-derive/src/staking/erasRewards.ts @@ -7,8 +7,8 @@ import { Balance, EraIndex } from '@polkadot/types/interfaces'; import { DeriveEraRewards } from '../types'; import BN from 'bn.js'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { Option } from '@polkadot/types'; import { memo } from '../util'; @@ -16,7 +16,6 @@ import { memo } from '../util'; export function erasRewards (api: ApiInterfaceRx): (withActive?: boolean | BN | number) => Observable { return memo((withActive?: boolean | BN | number): Observable => api.derive.staking.erasHistoric(withActive).pipe( - observeOn(asyncScheduler), switchMap((eras): Observable<[EraIndex[], Option[]]> => combineLatest([ of(eras), @@ -25,7 +24,6 @@ export function erasRewards (api: ApiInterfaceRx): (withActive?: boolean | BN | : of([]) ]) ), - observeOn(asyncScheduler), map(([eras, rewards]): DeriveEraRewards[] => eras.map((era, index): DeriveEraRewards => ({ era, diff --git a/packages/api-derive/src/staking/overview.ts b/packages/api-derive/src/staking/overview.ts index cb0fabb527..953aeb92e0 100644 --- a/packages/api-derive/src/staking/overview.ts +++ b/packages/api-derive/src/staking/overview.ts @@ -6,8 +6,8 @@ import { AccountId, EraIndex, EraPoints, EraRewardPoints, RewardPoint } from '@p import { ApiInterfaceRx } from '@polkadot/api/types'; import { DerivedStakingOverview } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { memo } from '../util'; @@ -35,7 +35,6 @@ export function overview (api: ApiInterfaceRx): () => Observable combineLatest([ of({ ...indexes, nextElected, validators }), @@ -46,7 +45,6 @@ export function overview (api: ApiInterfaceRx): () => Observable ({ ...info, eraPoints })) diff --git a/packages/api-derive/src/staking/query.ts b/packages/api-derive/src/staking/query.ts index 622cc9056b..89645c8ff4 100644 --- a/packages/api-derive/src/staking/query.ts +++ b/packages/api-derive/src/staking/query.ts @@ -7,8 +7,8 @@ import { AccountId, Exposure, Keys, Nominations, RewardDestination, ValidatorPre import { ITuple } from '@polkadot/types/types'; import { DerivedStakingQuery } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { Option, Vec } from '@polkadot/types'; import { memo } from '../util'; @@ -88,7 +88,6 @@ export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) => ? retrieveCurr(api, stashId) : retrievePrev(api, stashId) ]).pipe( - observeOn(asyncScheduler), switchMap((result): Observable => retrieveController(api, stashId, result) ) diff --git a/packages/api-derive/src/staking/stakerRewards.ts b/packages/api-derive/src/staking/stakerRewards.ts index 78d8bdc291..b964d644a0 100644 --- a/packages/api-derive/src/staking/stakerRewards.ts +++ b/packages/api-derive/src/staking/stakerRewards.ts @@ -7,8 +7,8 @@ import { Balance } from '@polkadot/types/interfaces'; import { DeriveEraPoints, DeriveEraRewards, DeriveStakerExposure, DeriveStakerReward } from '../types'; import BN from 'bn.js'; -import { Observable, asyncScheduler, combineLatest } from 'rxjs'; -import { map, observeOn } from 'rxjs/operators'; +import { Observable, combineLatest } from 'rxjs'; +import { map } from 'rxjs/operators'; import { memo } from '../util'; @@ -67,7 +67,6 @@ export function stakerRewards (api: ApiInterfaceRx): (accountId: Uint8Array | st api.derive.staking.erasRewards(startEra), api.derive.staking.stakerExposure(stakerId, startEra) ]).pipe( - observeOn(asyncScheduler), map((result): DeriveStakerReward[] => parseRewards(api, stakerId, result) ) diff --git a/packages/api-derive/src/staking/validators.ts b/packages/api-derive/src/staking/validators.ts index 2ddfeff1e0..1f231b7aad 100644 --- a/packages/api-derive/src/staking/validators.ts +++ b/packages/api-derive/src/staking/validators.ts @@ -6,8 +6,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { AccountId } from '@polkadot/types/interfaces'; import { DeriveStakingValidators } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap, take } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { StorageKey } from '@polkadot/types'; import { memo } from '../util'; @@ -19,7 +19,7 @@ export function nextElected (api: ApiInterfaceRx): () => Observable // only populate for next era in the last session, so track both here - entries are not // subscriptions, so we need a trigger - currentIndex acts as that trigger to refresh switchMap(({ currentEra }): Observable => - api.query.staking.erasStakers.keys(currentEra).pipe(take(1)) + api.query.staking.erasStakers.keys(currentEra) ), map((keys): AccountId[] => keys.map((key): AccountId => key.args[1] as AccountId) @@ -45,7 +45,6 @@ export function validators (api: ApiInterfaceRx): () => Observable ({ nextElected: nextElected.length ? nextElected diff --git a/packages/api-derive/src/treasury/proposals.ts b/packages/api-derive/src/treasury/proposals.ts index 489534b408..bb60779a3f 100644 --- a/packages/api-derive/src/treasury/proposals.ts +++ b/packages/api-derive/src/treasury/proposals.ts @@ -6,8 +6,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { ProposalIndex, TreasuryProposal } from '@polkadot/types/interfaces'; import { DerivedCollectiveProposals, DerivedTreasuryProposal, DerivedTreasuryProposals } from '../types'; -import { Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap } from 'rxjs/operators'; +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; import { Option } from '@polkadot/types'; import { memo } from '../util'; @@ -65,7 +65,6 @@ function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, a api.query.treasury.proposals.multi>(allIds), api.derive.council.proposals() ]).pipe( - observeOn(asyncScheduler), map(([allProposals, councilProposals]: [Option[], DerivedCollectiveProposals]): DerivedTreasuryProposals => parseResult(api, { allIds, allProposals, approvalIds, councilProposals, proposalCount }) ) @@ -82,7 +81,6 @@ export function proposals (api: ApiInterfaceRx): () => Observable retrieveProposals(api, proposalCount, approvalIds) ) diff --git a/packages/api/src/augment/rpc.ts b/packages/api/src/augment/rpc.ts index 0025ebef1a..663d560eca 100644 --- a/packages/api/src/augment/rpc.ts +++ b/packages/api/src/augment/rpc.ts @@ -130,6 +130,10 @@ declare module '@polkadot/rpc-core/types.jsonrpc' { * Retrieves the keys with a certain prefix **/ getKeys: AugmentedRpc<(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array) => Observable>>; + /** + * Returns the keys with prefix with pagination support. + **/ + getKeysPaged: AugmentedRpc<(key: StorageKey | string | Uint8Array | any, count: u32 | AnyNumber | Uint8Array, startKey?: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array) => Observable>>; /** * Returns the runtime metadata **/ diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index 431c70ea4f..12b422fd59 100644 --- a/packages/api/src/base/Decorate.ts +++ b/packages/api/src/base/Decorate.ts @@ -10,8 +10,8 @@ import { SubmittableExtrinsic } from '../submittable/types'; import { ApiInterfaceRx, ApiOptions, ApiTypes, DecorateMethod, DecoratedRpc, DecoratedRpcSection, QueryableModuleStorage, QueryableStorage, QueryableStorageEntry, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics, SubmittableModuleExtrinsics } from '../types'; import BN from 'bn.js'; -import { BehaviorSubject, Observable, asyncScheduler, combineLatest, of } from 'rxjs'; -import { map, observeOn, switchMap, take } from 'rxjs/operators'; +import { BehaviorSubject, Observable, combineLatest, from, of } from 'rxjs'; +import { concatMap, map, switchMap, take, tap, toArray } from 'rxjs/operators'; import decorateDerive, { ExactDerive } from '@polkadot/api-derive'; import { memo } from '@polkadot/api-derive/util'; import DecoratedMeta from '@polkadot/metadata/Decorated'; @@ -40,6 +40,9 @@ interface MetaDecoration { type LinkageData = ITuple<[Codec, Linkage]>; +const PAGE_SIZE_KEYS = 256; +const PAGE_SIZE_VALS = PAGE_SIZE_KEYS / 2; + export default abstract class Decorate extends Events { public readonly registry: Registry; @@ -433,7 +436,7 @@ export default abstract class Decorate extends Events private retrieveMapKeys ({ iterKey, meta }: StorageEntry, arg?: Arg): Observable { assert(iterKey && (meta.type.isMap || meta.type.isDoubleMap), 'keys can only be retrieved on maps, linked maps and double maps'); - const startKey = this.createType('Raw', u8aConcat( + const headKey = this.createType('Raw', u8aConcat( iterKey, meta.type.isDoubleMap && !isUndefined(arg) && !isNull(arg) ? getHasher(meta.type.asDoubleMap.hasher)( @@ -441,38 +444,71 @@ export default abstract class Decorate extends Events ) : new Uint8Array([]) )); + const startSubject = new BehaviorSubject(headKey); - return this._rpcCore.state.getKeys(startKey).pipe( - map((keys): StorageKey[] => - keys.map((key) => key.decodeArgsFromMeta(meta)) + return this._rpcCore.state.getKeysPaged + ? startSubject.pipe( + switchMap((startKey) => + this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE_KEYS, startKey).pipe( + map((keys): StorageKey[] => + keys.map((key) => key.decodeArgsFromMeta(meta)) + ) + ) + ), + tap((keys): void => { + keys.length === PAGE_SIZE_KEYS + ? startSubject.next(keys[PAGE_SIZE_KEYS - 1].toHex()) + : startSubject.complete(); + }), + toArray(), // toArray since we want to startSubject to be completed + map((keysArr: StorageKey[][]): StorageKey[] => + keysArr.reduce((result: StorageKey[], keys): StorageKey[] => + result.concat(keys), [] + ) + ) ) - ); + : this._rpcCore.state.getKeys(headKey).pipe( + map((keys): StorageKey[] => + keys.map((key) => key.decodeArgsFromMeta(meta)) + ) + ); } private retrieveMapEntries (entry: StorageEntry, arg?: Arg): Observable<[StorageKey, Codec][]> { const outputType = unwrapStorageType(entry.meta.type, entry.meta.modifier.isOptional); - return this.retrieveMapKeys(entry, arg) - .pipe( - switchMap((keys): Observable<[StorageKey[], Option[]]> => - combineLatest([ - of(keys), - // Since we have a default constructed key, we have Option as the result - // Don't keep the subscription here active, retrieve and get out of Dodge - // TODO Once we have a multiple key RPC available, use that via fallback - this._rpcCore.state.subscribeStorage[]>(keys).pipe( - take(1), - observeOn(asyncScheduler) + return this.retrieveMapKeys(entry, arg).pipe( + switchMap((keys): Observable<[StorageKey[], Option[]]> => + combineLatest([ + of(keys), + from(Array(Math.ceil(keys.length / PAGE_SIZE_VALS)).fill(0)).pipe( + // FIXME New RPC to take care of this in the works... + concatMap((_, index): Observable[]> => + this._rpcCore.state.subscribeStorage[]>( + keys.slice(index * PAGE_SIZE_VALS, (index * PAGE_SIZE_VALS) + PAGE_SIZE_VALS) + ).pipe(take(1)) + ), + toArray(), + map((valsArr: Option[][]): Option[] => + valsArr.reduce((result: Option[], vals): Option[] => + result.concat(vals), [] + ) ) - ]) - ), - map(([keys, values]): [StorageKey, Codec][] => - keys.map((key, index): [StorageKey, Codec] => [ - key, - this.createType(outputType, values[index].isSome ? values[index].unwrap().toHex() : undefined) - ]) - ) - ); + ) + ]) + ), + map(([keys, vals]): [StorageKey, Codec][] => + keys.map((key, index): [StorageKey, Codec] => [ + key, + this.createType( + outputType, + vals[index].isSome + ? vals[index].unwrap().toHex() + : undefined + ) + ]) + ) + ); } protected decorateDeriveRx (decorateMethod: DecorateMethod): DeriveAllSections<'rxjs', ExactDerive> { diff --git a/packages/api/test/api.spec.ts b/packages/api/test/api.spec.ts index b6d1072afb..9f59762f2e 100644 --- a/packages/api/test/api.spec.ts +++ b/packages/api/test/api.spec.ts @@ -5,6 +5,7 @@ import { ApiPromise, WsProvider } from '@polkadot/api'; function createApi (): Promise { + jest.setTimeout(30000); process.env.NODE_ENV = 'test'; const provider = new WsProvider('wss://kusama-rpc.polkadot.io'); @@ -24,12 +25,28 @@ describe.skip('misc quick tests', (): void => { )); }); + it.skip('handles map keys', async (): Promise => { + const api = await createApi(); + + console.time('map.keys'); + + const keys = await api.query.system.account.keys(); + + console.error('# keys', keys.length); + + console.timeEnd('map.keys'); + }); + it.skip('handles map entries', async (): Promise => { const api = await createApi(); - console.error(JSON.stringify( - await api.query.indices.accounts.entries() - )); + console.time('map.entries'); + + const entries = await api.query.system.account.entries(); // api.query.indices.accounts.entries(); + + console.error('# entries', entries.length); + + console.timeEnd('map.entries'); }); it.skip('handles doublemap entries', async (): Promise => { diff --git a/packages/jsonrpc/src/state.ts b/packages/jsonrpc/src/state.ts index 98dc6d95a0..ff8123947a 100644 --- a/packages/jsonrpc/src/state.ts +++ b/packages/jsonrpc/src/state.ts @@ -30,6 +30,17 @@ const getKeys: RpcMethodOpt = { type: 'Vec' }; +const getKeysPaged: RpcMethodOpt = { + description: 'Returns the keys with prefix with pagination support.', + params: [ + createParam('key', 'StorageKey'), + createParam('count', 'u32'), + createParam('startKey', 'StorageKey', { isOptional: true }), + createParam('at', 'BlockHash', { isOptional: true }) + ], + type: 'Vec' +}; + const getStorage: RpcMethodOpt = { description: 'Retrieves the storage for a key', params: KEY_QUERY_PARAMS, @@ -148,6 +159,7 @@ export default { getChildStorageHash: createMethod(section, 'getChildStorageHash', getChildStorageHash), getChildStorageSize: createMethod(section, 'getChildStorageSize', getChildStorageSize), getKeys: createMethod(section, 'getKeys', getKeys), + getKeysPaged: createMethod(section, 'getKeysPaged', getKeysPaged), getMetadata: createMethod(section, 'getMetadata', getMetadata), getRuntimeVersion: createMethod(section, 'getRuntimeVersion', getRuntimeVersion), getStorage: createMethod(section, 'getStorage', getStorage), diff --git a/packages/rpc-provider/src/mock/index.ts b/packages/rpc-provider/src/mock/index.ts index b6ec8c2945..488fba7eee 100644 --- a/packages/rpc-provider/src/mock/index.ts +++ b/packages/rpc-provider/src/mock/index.ts @@ -60,6 +60,7 @@ export default class Mock implements ProviderInterface { chain_getBlockHash: (blockNumber: number): string => '0x1234', chain_getHeader: (): any => this.registry.createType('Header', rpcHeader.result).toJSON(), state_getKeys: (): string[] => [], + state_getKeysPaged: (): string[] => [], state_getRuntimeVersion: (): string => this.registry.createType('RuntimeVersion').toHex(), state_getMetadata: (): string => rpcMetadata, state_getStorage: (storage: MockStateDb, params: any[]): string => u8aToHex(storage[(params[0] as string)]),