Make api.rpc.*.* typed (#1237)

* Generate correctly

* Fix rpc-core

* Flexible types

* Make types work!

* Lint

* Fix grumble

* Re generate

* Fix lint

* Fix small bugs

* Maybe really fix lint?

* Fix lint again

* Fix lint

* Small ordering & formatting  changes while playing...
This commit is contained in:
Amaury Martiny
2019-08-01 10:46:28 +02:00
committed by GitHub
parent 3290f14a75
commit 92044d471c
18 changed files with 330 additions and 157 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ import { drr } from '../util/drr';
*/
export function bestNumber (api: ApiInterfaceRx): () => Observable<BlockNumber> {
return (): Observable<BlockNumber> =>
(api.rpc.chain.subscribeNewHead() as Observable<Header>)
api.rpc.chain.subscribeNewHead()
.pipe(
filter((header: Header): boolean => !!header && !!header.number),
map((header: Header): BlockNumber => header.number.unwrap()),
@@ -25,7 +25,7 @@ import { drr } from '../util/drr';
*/
export function bestNumberFinalized (api: ApiInterfaceRx): () => Observable<BlockNumber> {
return (): Observable<BlockNumber> =>
(api.rpc.chain.subscribeFinalizedHeads() as Observable<Header>)
api.rpc.chain.subscribeFinalizedHeads()
.pipe(
filter((header: Header): boolean => !!header && !!header.number),
map((header: Header): BlockNumber => header.number.unwrap()),
+1 -3
View File
@@ -2,8 +2,6 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Header } from '@polkadot/types/interfaces';
import { Observable, combineLatest, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
@@ -30,7 +28,7 @@ export function getHeader (api: ApiInterfaceRx): (hash: Uint8Array | string) =>
return (hash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
// tslint:disable-next-line
(combineLatest([
api.rpc.chain.getHeader(hash) as Observable<Header>,
api.rpc.chain.getHeader(hash),
api.query.session
? api.query.session.validators.at(hash)
: of([])