From 7af915185427868a2dec43fecc51ec083981adca Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 25 Sep 2020 12:23:14 +0200 Subject: [PATCH] Support .entries() with no queryStorageAt (#2650) --- packages/api/src/base/Decorate.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index dcfe4372fe..0af853541a 100644 --- a/packages/api/src/base/Decorate.ts +++ b/packages/api/src/base/Decorate.ts @@ -10,7 +10,7 @@ import { ApiInterfaceRx, ApiOptions, ApiTypes, DecorateMethod, DecoratedRpc, Dec import BN from 'bn.js'; import { BehaviorSubject, Observable, combineLatest, of } from 'rxjs'; -import { map, switchMap, tap, toArray } from 'rxjs/operators'; +import { 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'; @@ -455,11 +455,14 @@ export default abstract class Decorate extends Events of(keys), ...Array(Math.ceil(keys.length / PAGE_SIZE_VALS)) .fill(0) - .map((_, index): Observable => - this._rpcCore.state.queryStorageAt( - keys.slice(index * PAGE_SIZE_VALS, (index * PAGE_SIZE_VALS) + PAGE_SIZE_VALS) - ) - ) + .map((_, index): Observable => { + const keyset = keys.slice(index * PAGE_SIZE_VALS, (index * PAGE_SIZE_VALS) + PAGE_SIZE_VALS); + + return this._rpcCore.state.queryStorageAt + ? this._rpcCore.state.queryStorageAt(keyset) + // this is horrible, but need older support + : this._rpcCore.state.subscribeStorage(keyset).pipe(take(1)); + }) ]) ), map(([keys, ...valsArr]): [StorageKey, Codec][] =>