diff --git a/packages/api-derive/src/chain/getHeader.ts b/packages/api-derive/src/chain/getHeader.ts index 21440b4cfd..078afe46d3 100644 --- a/packages/api-derive/src/chain/getHeader.ts +++ b/packages/api-derive/src/chain/getHeader.ts @@ -5,7 +5,6 @@ import { Observable, combineLatest, of } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { ApiInterface$Rx } from '@polkadot/api/types'; -import { AccountId, Header } from '@polkadot/types/index'; import { HeaderExtended } from '@polkadot/types/Header'; import { drr } from '../util/drr'; @@ -25,11 +24,14 @@ import { HeaderAndValidators } from './subscribeNewHead'; */ export function getHeader (api: ApiInterface$Rx) { return (hash: Uint8Array | string): Observable => - combineLatest( - api.rpc.chain.getHeader(hash) as Observable
, - api.query.session.validators.at(hash) as any as Observable> - ).pipe( - map(([header, validators]: HeaderAndValidators) => + // tslint:disable-next-line + (combineLatest( + api.rpc.chain.getHeader(hash), + api.query.session + ? api.query.session.validators.at(hash) + : of([]) + ) as Observable).pipe( + map(([header, validators]) => new HeaderExtended(header, validators) ), catchError(() => diff --git a/packages/api-derive/src/chain/subscribeNewHead.ts b/packages/api-derive/src/chain/subscribeNewHead.ts index 0ff951075a..0bc03c2101 100644 --- a/packages/api-derive/src/chain/subscribeNewHead.ts +++ b/packages/api-derive/src/chain/subscribeNewHead.ts @@ -36,7 +36,9 @@ export function subscribeNewHead (api: ApiInterface$Rx) { // theoretically we could combine at the first call with session.validators(), however // we make 100% sure we actually get the validators at a specific block so when these // change at an era boundary, we have the previous values to ensure our indexes are correct - api.query.session.validators.at(header.hash) as any as Observable> + api.query.session + ? api.query.session.validators.at(header.hash) + : of([]) ) ), map(([header, validators]) => diff --git a/packages/types/src/Header.ts b/packages/types/src/Header.ts index d87ae1e5ae..311908514d 100644 --- a/packages/types/src/Header.ts +++ b/packages/types/src/Header.ts @@ -91,7 +91,7 @@ export default class Header extends Struct { export class HeaderExtended extends Header { private _author?: AccountId; - constructor (header: Header, sessionValidators: Array) { + constructor (header: Header, sessionValidators: Array = []) { super(header); const { digest: { logs } } = header;