diff --git a/CHANGELOG.md b/CHANGELOG.md index ddf8a6c0d3..d60df0bece 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Adjust API cloning to take RPC filters from source into account - Simplification of isPedantic checks and less overhead on StorageData types - Cleanups and fixes around RPC and derive type definitions +- Fix `derive.imOnline.receivedHeatbeats` to query via indexes - Adjustment of `api.derive.elections.{approvalsOf|approvalsOfAt}` to allow ss58 address input - Add documentation for custom extrinsic formats (advanced chains) diff --git a/packages/api-derive/src/imOnline/receivedHeartbeats.ts b/packages/api-derive/src/imOnline/receivedHeartbeats.ts index 15ed53c162..4178d6e5f3 100644 --- a/packages/api-derive/src/imOnline/receivedHeartbeats.ts +++ b/packages/api-derive/src/imOnline/receivedHeartbeats.ts @@ -7,7 +7,7 @@ import { AccountId, SessionIndex } from '@polkadot/types/interfaces'; import { of, Observable } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { Bytes } from '@polkadot/types'; +import { Bytes, Vec } from '@polkadot/types'; import { drr } from '../util/drr'; @@ -17,21 +17,22 @@ import { drr } from '../util/drr'; export function receivedHeartbeats (api: ApiInterfaceRx): (addresses: (AccountId | string)[]) => Observable { return (addresses: (AccountId | string)[]): Observable => { return api.query.imOnline && api.query.imOnline.receivedHeartbeats - ? api.query.session - .currentIndex() - .pipe( - switchMap((currentIndex): Observable => - api.query.imOnline.receivedHeartbeats.multi( - addresses.map((address): [SessionIndex, AccountId | string] => - [currentIndex, address] - ) + ? api.queryMulti<[SessionIndex, Vec]>([ + api.query.session.currentIndex, + api.query.imOnline.keys + ]).pipe( + switchMap(([currentIndex, keys]): Observable => + api.query.imOnline.receivedHeartbeats.multi( + addresses.map((address): [SessionIndex, number] => + [currentIndex, keys.indexOf(address)] ) - ), - map((heartbeats): boolean[] => - heartbeats.map((heartbeat): boolean => !heartbeat.isEmpty) - ), - drr() - ) + ) + ), + map((heartbeats): boolean[] => + heartbeats.map((heartbeat): boolean => !heartbeat.isEmpty) + ), + drr() + ) : of([...new Array(addresses.length).keys()].map((): boolean => false)); }; }