Document available Api Derives (#6106)
* document derives from accounts to democracy * Derive Documentation progress * Derive Documentation progress * tx and staking docs * Staking docs progress * more staking docs * Staking module complete * imonline, elections and progress in democracy * Document missing derives * lint
This commit is contained in:
@@ -7,10 +7,8 @@ import { createBlockNumberDerive } from './util.js';
|
||||
|
||||
/**
|
||||
* @name bestNumber
|
||||
* @returns The latest block number.
|
||||
* @descrive Retrieves the latest block number.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* api.derive.chain.bestNumber((blockNumber) => {
|
||||
* console.log(`the current best block is #${blockNumber}`);
|
||||
|
||||
@@ -10,8 +10,6 @@ import { createBlockNumberDerive } from './util.js';
|
||||
* @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}`);
|
||||
|
||||
@@ -13,9 +13,7 @@ import { memo } from '../util/index.js';
|
||||
* @name bestNumberLag
|
||||
* @returns A number of blocks
|
||||
* @description Calculates the lag between finalized head and best head
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* @examplew
|
||||
* ```javascript
|
||||
* api.derive.chain.bestNumberLag((lag) => {
|
||||
* console.log(`finalized is ${lag} blocks behind head`);
|
||||
|
||||
@@ -13,11 +13,9 @@ import { getAuthorDetails } from './util.js';
|
||||
|
||||
/**
|
||||
* @name getBlock
|
||||
* @param {( Uint8Array | string )} hash - A block hash as U8 array or string.
|
||||
* @param {( Uint8Array | string )} hash A block hash as U8 array or string.
|
||||
* @description Get a specific block (e.g. rpc.chain.getBlock) and extend it with the author
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const { author, block } = await api.derive.chain.getBlock('0x123...456');
|
||||
*
|
||||
|
||||
@@ -10,6 +10,17 @@ import { switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name getBlockByNumber
|
||||
* @param {( BN | bigint | Uint8Array | number | string )} blockNumber
|
||||
* @description Get a specific block (e.g. rpc.chain.getBlock) and extend it with the author by block number
|
||||
* @example
|
||||
* ```javascript
|
||||
* const { author, block } = await api.derive.chain.getBlockByNumber(123);
|
||||
*
|
||||
* console.log(`block #${block.header.number} was authored by ${author}`);
|
||||
* ```
|
||||
*/
|
||||
export function getBlockByNumber (instanceId: string, api: DeriveApi): (blockNumber: AnyNumber) => Observable<SignedBlockExtended> {
|
||||
return memo(instanceId, (blockNumber: AnyNumber): Observable<SignedBlockExtended> =>
|
||||
api.rpc.chain.getBlockHash(blockNumber).pipe(
|
||||
|
||||
@@ -17,8 +17,6 @@ import { getAuthorDetails } from './util.js';
|
||||
* @returns An array containing the block header and the block author
|
||||
* @description Get a specific block header and extend it with the author
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const { author, number } = await api.derive.chain.getHeader('0x123...456');
|
||||
*
|
||||
|
||||
@@ -11,7 +11,13 @@ import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name subscribeFinalizedBlocks
|
||||
* @returns The finalized block & events for that block
|
||||
* @description Retrieves the finalized block & events for that block
|
||||
* @example
|
||||
* ```javascript
|
||||
* const unsub = await api.derive.chain.subscribeFinalizedBlocks((finalizedBlock) => {
|
||||
* console.log(`# Finalized block ${finalizedBlock.block.hash}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function subscribeFinalizedBlocks (instanceId: string, api: DeriveApi): () => Observable<SignedBlockExtended> {
|
||||
return memo(instanceId, (): Observable<SignedBlockExtended> =>
|
||||
|
||||
@@ -29,8 +29,14 @@ export function _getHeaderRange (instanceId: string, api: DeriveApi): (startHash
|
||||
* @description An observable of the finalized block headers. Unlike the base
|
||||
* chain.subscribeFinalizedHeads this does not skip any headers. Since finalization
|
||||
* may skip specific blocks (finalization happens in terms of chains), this version
|
||||
* of the derive tracks missing headers (since last retrieved) and provides them
|
||||
* to the caller
|
||||
* of the derive tracks missing headers (since last retrieved) and provides them
|
||||
* to the caller.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const unsub = await api.derive.chain.subscribeFinalizedHeads((finalizedHead) => {
|
||||
* console.log(`${finalizedHead.hash}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function subscribeFinalizedHeads (instanceId: string, api: DeriveApi): () => Observable<Header> {
|
||||
return memo(instanceId, (): Observable<Header> => {
|
||||
|
||||
@@ -12,6 +12,12 @@ import { memo } from '../util/index.js';
|
||||
/**
|
||||
* @name subscribeNewBlocks
|
||||
* @returns The latest block & events for that block
|
||||
* @example
|
||||
* ```javascript
|
||||
* const unsub = await api.derive.chain.subscribeNewBlocks((newBlock) => {
|
||||
* console.log(`Block Hash: ${newBlock.hash}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function subscribeNewBlocks (instanceId: string, api: DeriveApi): () => Observable<SignedBlockExtended> {
|
||||
return memo(instanceId, (): Observable<SignedBlockExtended> =>
|
||||
|
||||
@@ -13,11 +13,9 @@ import { getAuthorDetails } from './util.js';
|
||||
|
||||
/**
|
||||
* @name subscribeNewHeads
|
||||
* @returns A header with the current header (including extracted author)
|
||||
* @description An observable of the current block header and it's author
|
||||
* @returns A header with the current header (including extracted author).
|
||||
* @description An observable of the current block header and it's author.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* api.derive.chain.subscribeNewHeads((header) => {
|
||||
* console.log(`block #${header.number} was authored by ${header.author}`);
|
||||
|
||||
Reference in New Issue
Block a user