@bigmi/core
Version:
TypeScript library for Bitcoin apps.
28 lines (27 loc) • 1.69 kB
TypeScript
import type { Chain } from '../types/chain.js';
import type { Client } from '../types/client.js';
import type { Transport } from '../types/transport.js';
import { type GetBlockCountReturnType } from './getBlockCount.js';
export type OnBlockNumberParameter = GetBlockCountReturnType;
export type OnBlockNumberFn = (blockNumber: OnBlockNumberParameter, prevBlockNumber: OnBlockNumberParameter | undefined) => Promise<void>;
export type WatchBlockNumberParameters = {
/** The callback to call when a new block number is received. */
onBlockNumber: OnBlockNumberFn;
/** The callback to call when an error occurred when trying to get for a new block. */
onError?: ((error: Error) => void) | undefined;
} & {
/** Whether or not to emit the missed block numbers to the callback. */
emitMissed?: boolean | undefined;
/** Whether or not to emit the latest block number to the callback when the subscription opens. */
emitOnBegin?: boolean | undefined;
/** Polling frequency (in ms). Defaults to Client's pollingInterval config. */
pollingInterval?: number | undefined;
};
export type WatchBlockNumberReturnType = () => void;
/**
* Watches and returns incoming block numbers.
* @param client - Client to use
* @param parameters - {@link WatchBlockNumberParameters}
* @returns A function that can be invoked to stop watching for new block numbers. {@link WatchBlockNumberReturnType}
*/
export declare function watchBlockNumber<chain extends Chain | undefined, transport extends Transport>(client: Client<transport, chain>, { emitOnBegin, emitMissed, onBlockNumber, onError, pollingInterval, }: WatchBlockNumberParameters): WatchBlockNumberReturnType;