* derive.subscribeFinalizedBlocks w/ events & author * Apply createdAtHash (some) * Pass through events registry * Throw on use
25 lines
772 B
TypeScript
25 lines
772 B
TypeScript
// Copyright 2017-2022 @polkadot/api-derive authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Observable } from 'rxjs';
|
|
import type { SignedBlockExtended } from '../type/types';
|
|
import type { DeriveApi } from '../types';
|
|
|
|
import { switchMap } from 'rxjs';
|
|
|
|
import { memo } from '../util';
|
|
|
|
/**
|
|
* @name subscribeFinalizedBlocks
|
|
* @returns The finalized block & events for that block
|
|
*/
|
|
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)
|
|
)
|
|
)
|
|
);
|
|
}
|