import { BlockHash, Option } from '@dedot/codecs'; import type { ChainHeadRuntimeVersion, OperationId, StorageQuery, StorageResult } from '@dedot/types/json-rpc'; import { HashFn } from '@dedot/utils'; import { Deferred, HexString } from '@dedot/utils'; import type { IJsonRpcClient } from '../../../types.js'; import { Archive } from '../Archive.js'; import { JsonRpcGroup, type JsonRpcGroupOptions } from '../JsonRpcGroup.js'; export type OperationHandler = { operationId: OperationId; defer: Deferred; storageResults?: Array; hash: BlockHash; }; export type PendingRequest = { method: string; params: any[]; defer: Deferred; }; export type PinnedBlock = { hash: BlockHash; number: number; parent: BlockHash; runtime?: ChainHeadRuntimeVersion; runtimeUpgraded?: boolean; }; export type ChainHeadEvent = 'newBlock' | 'bestBlock' | 'finalizedBlock' | 'bestChainChanged'; export declare class ChainHead extends JsonRpcGroup { #private; constructor(client: IJsonRpcClient, options?: Partial); /** * Attach an Archive instance as fallback for operations that fail due to unpinned blocks. * When a ChainHeadBlockNotPinnedError occurs, the operation will automatically fallback * to the Archive API to attempt to retrieve the data from historical blocks. * * @param archive - Archive instance to use as fallback * @returns this ChainHead instance for method chaining */ withArchive(archive: Archive): this; /** * Override send() to track pending requests for retry on network disconnection */ send(method: string, ...params: any[]): Promise; runtimeVersion(): Promise; bestRuntimeVersion(): Promise; finalizedHash(): Promise; bestHash(): Promise; bestBlock(): Promise; finalizedBlock(): Promise; /** * Returns the detected hasher for the chain * Returns undefined if detection failed (client should use default) */ hasher(): Promise; findBlock(hash: BlockHash): PinnedBlock | undefined; isPinned(hash: BlockHash): boolean; /** * chainHead_unfollow */ unfollow(): Promise; /** * chainHead_follow */ follow(force?: boolean): Promise; /** * chainHead_body */ body(at?: BlockHash): Promise>; /** * chainHead_call */ call(func: string, params?: HexString, at?: BlockHash): Promise; /** * chainHead_header */ header(at?: BlockHash): Promise>; /** * chainHead_storage */ storage(items: Array, childTrie?: string | null, at?: BlockHash): Promise>; /** * chainHead_stopOperation * @protected */ protected stopOperation(operationId: OperationId): Promise; /** * chainHead_continue * @protected */ protected continue(operationId: OperationId): Promise; /** * chainHead_unpin * @protected */ protected unpin(hashes: BlockHash | BlockHash[]): Promise; /** * Clears the internal cache used for storing query results (both chainHead & archive instances) * This can be useful for memory management or when you want to force fresh data retrieval. * * @example * ```typescript * // Clear all cached results * chainHead.clearCache(); * ``` */ clearCache(): void; holdBlock(hash: BlockHash): void; releaseBlock(hash: BlockHash): void; }