From 0bdbf4b7a79890075fde9052f805b8edfdc19d73 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 31 Mar 2020 09:17:36 +0200 Subject: [PATCH] Use querystorageAt for map entries (optional) (#2119) --- CHANGELOG.md | 5 ++++- packages/api/src/base/Decorate.ts | 16 +++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c15864178..f4adc35f58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,16 @@ # 1.9.0-beta.x **Breaking change** (TypeScript with derives only) The type names for `api.derive.*` returns has been adjusted to be consistent with `Derive*` (previously a mixture of `Derived*` and `Derive*`) -**Breaking change** (derives only) Additional cleanups of democracy proposeal & referenda derives, including support for new Polkadot/Substrate vote retrievals +**Breaking change** (derives only) Additional cleanups of democracy proposal & referenda derives, including support for new Polkadot/Substrate vote retrievals - Tx signing via `signAndSend` & `signAsync` now tries to use the last finalized block (depending on finalized drift) - Add support for `api.rpc.childstate.*` Substrate RPCs, older nodes with still populate `api.rpc.state.*` with the child methods - Adjust `Error.message` on RPC failures to not include the (already known) method signature - Internal adjustment of interface types to align with modules (no external impact via `@polkadot/types/interfaces`) - Extended `api.derive.democracy` to cater for dispatchQueue and externals - Extended `api.derive.council` to cater for new phragmen elections +- Use new `queryStorageAt` for query `.entries`, removing unneeded subscriptions (as available) +- Fix `BTreeSet` initialization when part of query interfaces +- Fix encoding for `Vec`-related types as part of constants # 1.8.1 Mar 22, 2020 diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index 08567cd92a..9410b4d1e3 100644 --- a/packages/api/src/base/Decorate.ts +++ b/packages/api/src/base/Decorate.ts @@ -41,7 +41,7 @@ interface MetaDecoration { type LinkageData = ITuple<[Codec, Linkage]>; const PAGE_SIZE_KEYS = 256; -const PAGE_SIZE_VALS = PAGE_SIZE_KEYS / 2; +const PAGE_SIZE_VALS = PAGE_SIZE_KEYS; const l = logger('api/init'); @@ -248,6 +248,7 @@ export default abstract class Decorate extends Events // eslint-disable-next-line @typescript-eslint/no-unused-vars .forEach(([_, { method, section }]): void => { delete (this._rpc as any)[section][method]; + delete (this._rpcCore as any)[section][method]; delete (this._rx.rpc as any)[section][method]; }); } @@ -502,12 +503,13 @@ export default abstract class Decorate extends Events 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)) - ), + concatMap((_, 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._rpcCore.state.subscribeStorage[]>(keyset).pipe(take(1)); + }), toArray(), map((valsArr: Option[][]): Option[] => valsArr.reduce((result: Option[], vals): Option[] =>