* 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
31 lines
998 B
TypeScript
31 lines
998 B
TypeScript
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Observable } from 'rxjs';
|
|
import type { SignedBlockExtended } from '../type/types.js';
|
|
import type { DeriveApi } from '../types.js';
|
|
|
|
import { switchMap } from 'rxjs';
|
|
|
|
import { memo } from '../util/index.js';
|
|
|
|
/**
|
|
* @name subscribeFinalizedBlocks
|
|
* @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> =>
|
|
api.derive.chain.subscribeFinalizedHeads().pipe(
|
|
switchMap((header) =>
|
|
api.derive.chain.getBlock(header.createdAtHash || header.hash)
|
|
)
|
|
)
|
|
);
|
|
}
|