diff --git a/packages/api-derive/src/chain/subscribeNewHeads.ts b/packages/api-derive/src/chain/subscribeNewHeads.ts index 4d9a1d6394..d895bf38d4 100644 --- a/packages/api-derive/src/chain/subscribeNewHeads.ts +++ b/packages/api-derive/src/chain/subscribeNewHeads.ts @@ -4,7 +4,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; -import { Observable, combineLatest } from 'rxjs'; +import { Observable, combineLatest, of } from 'rxjs'; import { map } from 'rxjs/operators'; import { HeaderExtended } from '../type'; @@ -27,9 +27,11 @@ export function subscribeNewHeads (api: ApiInterfaceRx): () => Observable
=> combineLatest([ api.rpc.chain.subscribeNewHeads(), - api.derive.staking.validators() + api.query.session + ? api.query.session.validators() + : of([]) ]).pipe( - map(([header, { validators }]): HeaderExtended => + map(([header, validators]): HeaderExtended => new HeaderExtended(api.registry, header, validators) ) )); diff --git a/packages/api-derive/src/staking/validators.ts b/packages/api-derive/src/staking/validators.ts index ef91b41f8d..8680da8ea3 100644 --- a/packages/api-derive/src/staking/validators.ts +++ b/packages/api-derive/src/staking/validators.ts @@ -2,13 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { AccountId } from '@polkadot/types/interfaces'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { DeriveStakingValidators } from '../types'; -import { Observable, of } from 'rxjs'; +import { Observable, combineLatest, of } from 'rxjs'; import { map } from 'rxjs/operators'; -import { Vec } from '@polkadot/types'; import { memo } from '../util'; @@ -17,16 +15,17 @@ import { memo } from '../util'; */ export function validators (api: ApiInterfaceRx): () => Observable { return memo((): Observable => - ( - // Sadly the node-template is (for some obscure reason) not comprehensive, so while the derive works - // in all actual real-world deployed chains, it does create some confusion for limited template chains - api.query.session && api.query.staking - ? api.queryMulti<[Vec, Vec]>([ - api.query.session.validators, - api.query.staking.currentElected - ]) - : of([[], []] as [AccountId[], AccountId[]]) - ).pipe( + // Sadly the node-template is (for some obscure reason) not comprehensive, so while the derive works + // in all actual real-world deployed chains, it does create some confusion for limited template chains + // NOTE: Not doing multi queries here, since we have validators as a single in the derived newHead + combineLatest([ + api.query.session + ? api.query.session.validators() + : of([]), + api.query.staking + ? api.query.staking.currentElected() + : of([]) + ]).pipe( map(([validators, currentElected]): DeriveStakingValidators => ({ currentElected, validators }))