* Some minor cleanups * Small additions * Cleanup ExtrinsicEra decoding * Minor adjustments * Remove support for metadata v0 parsing * Adjust refCountDelay * refCountDelay comments * Adjust Metadata tests * Metadata default creation * Funky lines * Cleanup as AccountIdAndIndex * Some derive returns * Try and cleanup info extraction
32 lines
958 B
TypeScript
32 lines
958 B
TypeScript
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
|
// This software may be modified and distributed under the terms
|
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
|
|
import { BlockNumber } from '@polkadot/types/interfaces';
|
|
|
|
import { Observable } from 'rxjs';
|
|
import { map } from 'rxjs/operators';
|
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
|
|
|
import { memo } from '../util';
|
|
|
|
/**
|
|
* @name bestNumberFinalized
|
|
* @returns A BlockNumber
|
|
* @description Get the latest finalized block number.
|
|
* @example
|
|
* <BR>
|
|
*
|
|
* ```javascript
|
|
* api.derive.chain.bestNumberFinalized((blockNumber) => {
|
|
* console.log(`the current finalized block is #${blockNumber}`);
|
|
* });
|
|
* ```
|
|
*/
|
|
export function bestNumberFinalized (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
|
return memo((): Observable<BlockNumber> =>
|
|
api.rpc.chain.subscribeFinalizedHeads().pipe(
|
|
map((header) => header.number.unwrap())
|
|
));
|
|
}
|