Chunk keys & values retrievals on keys()/entries() (#2046)
* Chunk keys & values retrievals on keys()/entries() * Bump chunk sizes * Fix concatMap index * Update mock
This commit is contained in:
@@ -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<Registration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]>).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(([identityOfOpt, superOfOpt]): Observable<[Option<Registration> | 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<DeriveAccountInfo> {
|
||||
return memo((address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
|
||||
api.derive.accounts.idAndIndex(address).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, 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
|
||||
}))
|
||||
|
||||
@@ -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<Re
|
||||
export function account (api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DerivedBalancesAccount> {
|
||||
return memo((address: AccountIndex | AccountId | Address | string): Observable<DerivedBalancesAccount> =>
|
||||
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))
|
||||
));
|
||||
}
|
||||
|
||||
@@ -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<Re
|
||||
export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DerivedBalancesAll> {
|
||||
return memo((address: AccountIndex | AccountId | Address | string): Observable<DerivedBalancesAll> =>
|
||||
api.derive.balances.account(address).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((account): Observable<Result> =>
|
||||
(!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<BalanceLock>')]])
|
||||
)
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map((result): DerivedBalancesAll => calcBalances(api, result))
|
||||
));
|
||||
}
|
||||
|
||||
@@ -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<DerivedBalancesAccount> =>
|
||||
api.derive.balances.account(accountId)
|
||||
)
|
||||
).pipe(observeOn(asyncScheduler))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<BlockNumbe
|
||||
api.derive.chain.bestNumber(),
|
||||
api.derive.chain.bestNumberFinalized()
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map(([bestNumber, bestNumberFinalized]): BlockNumber =>
|
||||
api.registry.createType('BlockNumber', bestNumber.sub(bestNumberFinalized))
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
),
|
||||
|
||||
@@ -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<Header
|
||||
? api.query.session.validators()
|
||||
: of([])
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map(([header, validators]): HeaderExtended =>
|
||||
new HeaderExtended(api.registry, header, validators)
|
||||
)
|
||||
|
||||
@@ -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<Proposal>[], Option<Votes>[]];
|
||||
@@ -30,7 +30,6 @@ export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalC
|
||||
return (): Observable<DerivedCollectiveProposal[]> =>
|
||||
api.query[section]?.proposals
|
||||
? api.query[section].proposals().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((hashes: Hash[]): Observable<Result> =>
|
||||
hashes.length
|
||||
? combineLatest([
|
||||
@@ -40,7 +39,6 @@ export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalC
|
||||
])
|
||||
: of([[], [], []])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(parse)
|
||||
)
|
||||
: of([] as DerivedCollectiveProposal[]);
|
||||
|
||||
@@ -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<DeriveProposal
|
||||
return memo((): Observable<DeriveProposal[]> =>
|
||||
api.query.democracy?.publicProps && api.query.democracy?.preimages
|
||||
? api.query.democracy.publicProps<Proposals>().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((proposals) =>
|
||||
combineLatest([
|
||||
of(proposals),
|
||||
@@ -75,7 +74,6 @@ export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal
|
||||
proposals.map(([index]): PropIndex => index))
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([proposals, preimages, depositors]): DeriveProposal[] =>
|
||||
parse(api, { depositors, proposals, preimages })
|
||||
)
|
||||
|
||||
@@ -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<ReferendumInfo>[])
|
||||
: api.query.democracy.referendumInfoOf.multi<Option<ReferendumInfo>>(ids)
|
||||
).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((infos): Observable<(DerivedReferendum | null)[]> =>
|
||||
combineLatest(
|
||||
ids.map((id, index): Observable<DerivedReferendum | null> =>
|
||||
@@ -29,7 +28,6 @@ export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) =
|
||||
)
|
||||
)
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map((infos): DerivedReferendum[] =>
|
||||
infos.filter((referendum): referendum is DerivedReferendum => !!referendum)
|
||||
)
|
||||
|
||||
@@ -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<DerivedReferendumVote[]> {
|
||||
return memo((referendumId: BN | number): Observable<DerivedReferendumVote[]> =>
|
||||
api.query.democracy.votersFor<Vec<AccountId>>(referendumId).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((votersFor): Observable<[Vec<AccountId>, 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,
|
||||
|
||||
@@ -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<Deriv
|
||||
return memo((): Observable<DerivedHeartbeats> =>
|
||||
api.query.imOnline?.receivedHeartbeats
|
||||
? api.derive.staking.overview().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(({ currentIndex, validators }): Observable<[AccountId[], Option<Bytes>[], u32[]]> =>
|
||||
combineLatest([
|
||||
of(validators),
|
||||
@@ -29,7 +28,6 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<Deriv
|
||||
validators.map((address) => [currentIndex, address]))
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([validators, heartbeats, numBlocks]): DerivedHeartbeats =>
|
||||
validators.reduce((result: DerivedHeartbeats, validator, index): DerivedHeartbeats => ({
|
||||
...result,
|
||||
|
||||
@@ -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<DeriveParachain
|
||||
return memo((): Observable<DeriveParachain[]> =>
|
||||
api.query.registrar?.parachains && api.query.parachains
|
||||
? api.query.registrar.parachains<ParaId[]>().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((paraIds) =>
|
||||
combineLatest([
|
||||
of(paraIds),
|
||||
@@ -48,7 +47,6 @@ export function overview (api: ApiInterfaceRx): () => Observable<DeriveParachain
|
||||
api.query.parachains.relayDispatchQueueSize.multi<RelayDispatchQueueSize>(paraIds)
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map((result: Result): DeriveParachain[] =>
|
||||
parse(result)
|
||||
)
|
||||
|
||||
@@ -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<DerivedSessionInfo> {
|
||||
|
||||
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<DerivedSessionInfo>
|
||||
? 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],
|
||||
|
||||
@@ -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<DeriveSocietyCandidate[]> {
|
||||
return memo((): Observable<DeriveSocietyCandidate[]> =>
|
||||
api.query.society.candidates<Vec<Bid>>().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((candidates: Vec<Bid>): Observable<Result> =>
|
||||
combineLatest([
|
||||
of(candidates),
|
||||
@@ -30,7 +29,6 @@ export function candidates (api: ApiInterfaceRx): () => Observable<DeriveSociety
|
||||
candidates.map(({ who }): AccountId => who))
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([candidates, suspended]: Result): DeriveSocietyCandidate[] =>
|
||||
candidates.map(({ who, kind, value }, index) => ({
|
||||
accountId: who,
|
||||
|
||||
@@ -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<DeriveSocietyMember[]> {
|
||||
return memo((): Observable<DeriveSocietyMember[]> =>
|
||||
api.query.society.members<AccountId[]>().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((members): Observable<DeriveSocietyMember[]> =>
|
||||
combineLatest(
|
||||
members.map((accountId): Observable<DeriveSocietyMember> =>
|
||||
|
||||
@@ -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))
|
||||
));
|
||||
|
||||
@@ -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<AccountId>[]];
|
||||
export function controllers (api: ApiInterfaceRx): () => Observable<DeriveControllers> {
|
||||
return memo((): Observable<[AccountId[], Option<AccountId>[]]> =>
|
||||
api.query.staking.validators<ITuple<[Vec<AccountId>, Vec<ValidatorPrefs>]>>().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(([stashIds]): Observable<DeriveControllers> =>
|
||||
combineLatest([
|
||||
of(stashIds),
|
||||
@@ -29,7 +28,6 @@ export function controllers (api: ApiInterfaceRx): () => Observable<DeriveContro
|
||||
? of([])
|
||||
: api.query.staking.bonded.multi<Option<AccountId>>(stashIds)
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -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<DerivedStakingElected> {
|
||||
return memo((): Observable<DerivedStakingElected> =>
|
||||
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<DerivedStaki
|
||||
)
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([nextElected, info]): DerivedStakingElected => ({
|
||||
info,
|
||||
nextElected
|
||||
|
||||
@@ -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<DeriveEraExposure> {
|
||||
return memo((era: EraIndex): Observable<DeriveEraExposure> =>
|
||||
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<DeriveEraExposure[]> {
|
||||
return memo((withActive?: boolean | BN | number): Observable<DeriveEraExposure[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((eras): Observable<DeriveEraExposure[]> =>
|
||||
eras.length
|
||||
? combineLatest(
|
||||
|
||||
@@ -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<DeriveEraPoints[]> {
|
||||
return memo((withActive?: boolean | number): Observable<DeriveEraPoints[]> =>
|
||||
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,
|
||||
|
||||
@@ -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<DeriveEraRewards[]> {
|
||||
return memo((withActive?: boolean | BN | number): Observable<DeriveEraRewards[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((eras): Observable<[EraIndex[], Option<Balance>[]]> =>
|
||||
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,
|
||||
|
||||
@@ -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<DerivedStakingO
|
||||
api.derive.session.indexes(),
|
||||
api.derive.staking.validators()
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(([indexes, { nextElected, validators }]) =>
|
||||
combineLatest([
|
||||
of({ ...indexes, nextElected, validators }),
|
||||
@@ -46,7 +45,6 @@ export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingO
|
||||
: of(api.registry.createType('EraRewardPoints'))
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([info, eraPoints]): DerivedStakingOverview => ({
|
||||
...info, eraPoints
|
||||
}))
|
||||
|
||||
@@ -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<DerivedStakingQuery> =>
|
||||
retrieveController(api, stashId, result)
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
|
||||
@@ -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<AccountId[]>
|
||||
// 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<StorageKey[]> =>
|
||||
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<DeriveStaking
|
||||
? api.derive.staking.nextElected()
|
||||
: of([])
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map(([validators, nextElected]): DeriveStakingValidators => ({
|
||||
nextElected: nextElected.length
|
||||
? nextElected
|
||||
|
||||
@@ -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<Option<TreasuryProposal>>(allIds),
|
||||
api.derive.council.proposals()
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map(([allProposals, councilProposals]: [Option<TreasuryProposal>[], DerivedCollectiveProposals]): DerivedTreasuryProposals =>
|
||||
parseResult(api, { allIds, allProposals, approvalIds, councilProposals, proposalCount })
|
||||
)
|
||||
@@ -82,7 +81,6 @@ export function proposals (api: ApiInterfaceRx): () => Observable<DerivedTreasur
|
||||
api.query.treasury.proposalCount(),
|
||||
api.query.treasury.approvals()
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(([proposalCount, approvalIds]: [ProposalIndex, ProposalIndex[]]) =>
|
||||
retrieveProposals(api, proposalCount, approvalIds)
|
||||
)
|
||||
|
||||
@@ -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<Vec<StorageKey>>>;
|
||||
/**
|
||||
* 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<Vec<StorageKey>>>;
|
||||
/**
|
||||
* Returns the runtime metadata
|
||||
**/
|
||||
|
||||
@@ -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<Codec>]>;
|
||||
|
||||
const PAGE_SIZE_KEYS = 256;
|
||||
const PAGE_SIZE_VALS = PAGE_SIZE_KEYS / 2;
|
||||
|
||||
export default abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
public readonly registry: Registry;
|
||||
|
||||
@@ -433,7 +436,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
private retrieveMapKeys ({ iterKey, meta }: StorageEntry, arg?: Arg): Observable<StorageKey[]> {
|
||||
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<ApiType extends ApiTypes> extends Events
|
||||
)
|
||||
: new Uint8Array([])
|
||||
));
|
||||
const startSubject = new BehaviorSubject<Codec | string | undefined>(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<Raw>[]]> =>
|
||||
combineLatest([
|
||||
of(keys),
|
||||
// Since we have a default constructed key, we have Option<Raw> 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<Option<Raw>[]>(keys).pipe(
|
||||
take(1),
|
||||
observeOn(asyncScheduler)
|
||||
return this.retrieveMapKeys(entry, arg).pipe(
|
||||
switchMap((keys): Observable<[StorageKey[], Option<Raw>[]]> =>
|
||||
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<Option<Raw>[]> =>
|
||||
this._rpcCore.state.subscribeStorage<Option<Raw>[]>(
|
||||
keys.slice(index * PAGE_SIZE_VALS, (index * PAGE_SIZE_VALS) + PAGE_SIZE_VALS)
|
||||
).pipe(take(1))
|
||||
),
|
||||
toArray(),
|
||||
map((valsArr: Option<Raw>[][]): Option<Raw>[] =>
|
||||
valsArr.reduce((result: Option<Raw>[], vals): Option<Raw>[] =>
|
||||
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<ApiType>): DeriveAllSections<'rxjs', ExactDerive> {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { ApiPromise, WsProvider } from '@polkadot/api';
|
||||
|
||||
function createApi (): Promise<ApiPromise> {
|
||||
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<void> => {
|
||||
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<void> => {
|
||||
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<void> => {
|
||||
|
||||
@@ -30,6 +30,17 @@ const getKeys: RpcMethodOpt = {
|
||||
type: 'Vec<StorageKey>'
|
||||
};
|
||||
|
||||
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<StorageKey>'
|
||||
};
|
||||
|
||||
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),
|
||||
|
||||
@@ -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)]),
|
||||
|
||||
Reference in New Issue
Block a user