Basic same-type multi queries (#866)

* Basic same-type multi queries

* Remove extra map, straight to switchMap
This commit is contained in:
Jaco Greeff
2019-05-03 13:54:05 +02:00
committed by GitHub
parent 5c6729aa83
commit 21dab00203
8 changed files with 38 additions and 14 deletions
@@ -20,7 +20,9 @@ export function indexToId (api: ApiInterface$Rx) {
return (querySection.enumSet(accountIndex.div(ENUMSET_SIZE)) as Observable<Vector<AccountId>>)
.pipe(
startWith([]),
map((accounts) => (accounts || [])[accountIndex.mod(ENUMSET_SIZE).toNumber()]),
map((accounts) =>
(accounts || [])[accountIndex.mod(ENUMSET_SIZE).toNumber()]
),
drr()
);
};
+6 -9
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { combineLatest, Observable } from 'rxjs';
import { Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { ENUMSET_SIZE } from '@polkadot/types/type/AccountIndex';
@@ -24,15 +24,12 @@ export function indexes (api: ApiInterface$Rx) {
return (api.query.indices.nextEnumSet() as Observable<AccountIndex>)
.pipe(
// use the nextEnumSet (which is a counter of the number of sets) to construct
// a range of values to query [0, 1, 2, ...]
map((next: AccountIndex) =>
[...Array(next.toNumber() + 1).keys()]
// a range of values to query [0, 1, 2, ...]. Retrieve the full enum set for the
// specific index - each query can return up to ENUMSET_SIZE (64) records, each
// containing an AccountId
switchMap((next: AccountIndex) =>
api.query.indices.enumSet.multi([...Array(next.toNumber() + 1).keys()]) as Observable<any>
),
switchMap((enumRange) => combineLatest(
// retrieve the full enum set for the specific index - each query can return
// up to ENUMSET_SIZE (64) records, each containing an AccountId
enumRange.map((index) => (api.query.indices.enumSet(index) as Observable<any>))
)),
map((all: Array<Array<AccountId> | undefined>) =>
(all || []).reduce((result, list, outerIndex) => {
(list || []).forEach((accountId, innerIndex) => {
+1
View File
@@ -12,6 +12,7 @@ import { drr } from '../util/drr';
export function fees (api: ApiInterface$Rx) {
return (): Observable<DerivedFees> => {
// FIXME Remove fees checks, only use balances (fees is a removed module now)
return (combineLatest([
api.query.balances.creationFee(),
api.query.balances.existentialDeposit(),
@@ -14,6 +14,7 @@ export function votes (api: ApiInterface$Rx) {
return !accountIds || !accountIds.length
? of([]).pipe(drr())
: combineLatest(
// FIXME Convert to multi
accountIds.map(
(accountId) => api.query.democracy.voteOf([referendumId, accountId]) as Observable<Vote>
)
@@ -11,6 +11,7 @@ import { drr } from '../util/drr';
function allBonds (api: ApiInterface$Rx, stashIds: Array<AccountId>) {
return combineLatest(
// FIXME Convert to multi
stashIds.map((id) =>
(api.query.staking.bonded(id) as Observable<Option<AccountId>>)
)