* 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
31 lines
879 B
TypeScript
31 lines
879 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 bestNumber
|
|
* @returns The latest block number.
|
|
* @example
|
|
* <BR>
|
|
*
|
|
* ```javascript
|
|
* api.derive.chain.bestNumber((blockNumber) => {
|
|
* console.log(`the current best block is #${blockNumber}`);
|
|
* });
|
|
* ```
|
|
*/
|
|
export function bestNumber (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
|
return memo((): Observable<BlockNumber> =>
|
|
api.derive.chain.subscribeNewHeads().pipe(
|
|
map((header) => header.number.unwrap())
|
|
));
|
|
}
|