Skip to content

Commit 2cdd244

Browse files
authored
Adjust entriesPages w/ & w/o at (#4745)
* Adjust entriesPages w/ & w/o at * Adjust * Update packages/api/src/base/Decorate.ts * s/keyset/keys/ * CHANGELOG
1 parent e545f6f commit 2cdd244

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
## master
44

5+
Contributed:
6+
7+
- Adjust typegen for `Vec<{ struct: <type> }>` (Thanks to https://github.com/zannis)
8+
59
Changes:
610

11+
- Fix `entriesPaged` where no `at?: BlockHash` is specified
712
- Apply windcard matches for `democracy::vote::Vote` and `identity::type::Data`
813

914

packages/api/src/base/Decorate.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -687,13 +687,13 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
687687

688688
const headKey = iterKey(...args).toHex();
689689
const startSubject = new BehaviorSubject<string>(headKey);
690-
const queryCall = at
690+
const getKeysPaged = at
691691
? (startKey: string) => this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE_K, startKey, at)
692692
: (startKey: string) => this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE_K, startKey);
693693
const setMeta = (key: StorageKey) => key.setMeta(meta, section, method);
694694

695695
return startSubject.pipe(
696-
switchMap(queryCall),
696+
switchMap(getKeysPaged),
697697
map((keys) => keys.map(setMeta)),
698698
tap((keys): void => {
699699
setTimeout((): void => {
@@ -710,23 +710,25 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
710710
private _retrieveMapKeysPaged ({ iterKey, meta, method, section }: StorageEntry, at: Hash | Uint8Array | string | undefined, opts: PaginationOptions): Observable<StorageKey[]> {
711711
assert(iterKey && meta.type.isMap, 'keys can only be retrieved on maps');
712712

713-
const headKey = iterKey(...opts.args).toHex();
714713
const setMeta = (key: StorageKey) => key.setMeta(meta, section, method);
714+
const getKeysPaged = at
715+
? (headKey: string) => this._rpcCore.state.getKeysPaged(headKey, opts.pageSize, opts.startKey || headKey, at)
716+
: (headKey: string) => this._rpcCore.state.getKeysPaged(headKey, opts.pageSize, opts.startKey || headKey);
715717

716-
return this._rpcCore.state.getKeysPaged(headKey, opts.pageSize, opts.startKey || headKey, at).pipe(
718+
return getKeysPaged(iterKey(...opts.args).toHex()).pipe(
717719
map((keys) => keys.map(setMeta))
718720
);
719721
}
720722

721723
private _retrieveMapEntries (entry: StorageEntry, at: Hash | Uint8Array | string | null, args: unknown[]): Observable<[StorageKey, Codec][]> {
722-
const query = at
723-
? (keyset: StorageKey[]) => this._rpcCore.state.queryStorageAt(keyset, at)
724-
: (keyset: StorageKey[]) => this._rpcCore.state.queryStorageAt(keyset);
724+
const queryStorageAt = at
725+
? (keys: StorageKey[]) => this._rpcCore.state.queryStorageAt(keys, at)
726+
: (keys: StorageKey[]) => this._rpcCore.state.queryStorageAt(keys);
725727

726728
return this._retrieveMapKeys(entry, at, args).pipe(
727729
switchMap((keys) =>
728730
keys.length
729-
? combineLatest(arrayChunk(keys, PAGE_SIZE_V).map(query)).pipe(
731+
? combineLatest(arrayChunk(keys, PAGE_SIZE_V).map(queryStorageAt)).pipe(
730732
map((valsArr) =>
731733
arrayFlatten(valsArr).map((value, index): [StorageKey, Codec] => [keys[index], value])
732734
)
@@ -737,10 +739,14 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
737739
}
738740

739741
private _retrieveMapEntriesPaged (entry: StorageEntry, at: Hash | Uint8Array | string | undefined, opts: PaginationOptions): Observable<[StorageKey, Codec][]> {
742+
const queryStorageAt = at
743+
? (keys: StorageKey[]) => this._rpcCore.state.queryStorageAt(keys, at)
744+
: (keys: StorageKey[]) => this._rpcCore.state.queryStorageAt(keys);
745+
740746
return this._retrieveMapKeysPaged(entry, at, opts).pipe(
741747
switchMap((keys) =>
742748
keys.length
743-
? this._rpcCore.state.queryStorageAt(keys, at).pipe(
749+
? queryStorageAt(keys).pipe(
744750
map((valsArr) =>
745751
valsArr.map((value, index): [StorageKey, Codec] => [keys[index], value])
746752
)

0 commit comments

Comments
 (0)