import { BlockHash, Extrinsic, Hash, Metadata, PortableRegistry, RuntimeVersion } from '@dedot/codecs'; import { type JsonRpcProvider } from '@dedot/providers'; import { type IStorage } from '@dedot/storage'; import { Callback, ChainSubmittableExtrinsic, GenericStorageQuery, GenericSubstrateApi, InjectedSigner, IRuntimeTxCall, ISubmittableResult, Query, QueryFnResult, RpcVersion, TxUnsub, Unsub } from '@dedot/types'; import { Deferred, HexString, LRUCache } from '@dedot/utils'; import type { SubstrateApi } from '../chaintypes/index.js'; import { JsonRpcClient } from '../json-rpc/index.js'; import { BaseStorageQuery } from '../storage/index.js'; import type { ApiEvent, ApiOptions, BlockExplorer, EventHandlerFn, IChainSpec, ISubstrateClient, ISubstrateClientAt, JsonRpcClientOptions, MetadataKey, SubstrateRuntimeVersion } from '../types.js'; export declare function ensurePresence(value: T): NonNullable; /** * @name BaseSubstrateClient * @description Base & shared abstraction for Substrate API Clients */ export declare abstract class BaseSubstrateClient extends JsonRpcClient implements ISubstrateClient { #private; rpcVersion: RpcVersion; protected _options: ApiOptions; protected _registry?: PortableRegistry; protected _metadata?: Metadata; protected _genesisHash?: Hash; protected _runtimeVersion?: SubstrateRuntimeVersion; protected _localCache?: IStorage; protected _runtimeUpgrading?: Deferred; protected _apiAtCache: LRUCache; protected constructor(rpcVersion: RpcVersion, options: JsonRpcClientOptions | JsonRpcProvider); protected normalizeOptions(options: ApiOptions | JsonRpcProvider): ApiOptions; protected initializeLocalCache(): Promise; protected setupMetadata(preloadMetadata: Metadata | undefined): Promise; /** * Safely set metadata to cache with fallback cleanup if storage limit is exceeded */ protected safeSetMetadataToCache(key: string, value: string): Promise; protected setMetadata(metadata: Metadata): Promise; protected getMetadataKey(runtime?: SubstrateRuntimeVersion): MetadataKey; get currentMetadataKey(): string; protected shouldPreloadMetadata(): Promise; protected getMetadataFromOptions(runtime?: SubstrateRuntimeVersion): Metadata | undefined; /** * Find metadata from cached API instances by specVersion * This allows reusing metadata from previously created API instances * instead of downloading it again from the network */ protected findMetadataInCache(specVersion: number): [Metadata, PortableRegistry] | undefined; protected fetchMetadata(hash?: BlockHash, runtime?: SubstrateRuntimeVersion): Promise; /** * Set up staling detection with timeout reset logic. * Returns a callback function that should be called on each activity (block/event). * * @returns A function to call on each activity to reset the timeout */ protected getStalingDetectionFn(): (() => void) | undefined; /** * Clean up staling detection timer */ protected cleanupStalingDetection(): void; protected cleanUp(): void; /** * @description Clear local cache and API at-block cache * @param keepMetadataCache Keep the metadata cache, only clear other caches. */ clearCache(keepMetadataCache?: boolean): Promise; protected doConnect(): Promise; protected onConnected: () => Promise; protected onDisconnected: () => Promise; protected initialize(): Promise; protected doInitialize(): Promise; protected beforeDisconnect(): Promise; protected afterDisconnect(): Promise; protected toSubstrateRuntimeVersion(runtimeVersion: RuntimeVersion): SubstrateRuntimeVersion; protected startRuntimeUpgrade(): void; protected doneRuntimeUpgrade(): void; protected ensureRuntimeUpgraded(): Promise; /** * @description Connect to blockchain node */ connect(): Promise; /** * @description Disconnect to blockchain node */ disconnect(): Promise; get options(): ApiOptions; get metadata(): Metadata; get registry(): PortableRegistry; get genesisHash(): Hash; get runtimeVersion(): SubstrateRuntimeVersion; getRuntimeVersion(): Promise; get block(): BlockExplorer; get consts(): ChainApi['consts']; get errors(): ChainApi['errors']; get events(): ChainApi['events']; get query(): ChainApi['query']; get view(): ChainApi['view']; get call(): ChainApi['call']; protected callAt(hash?: BlockHash): ChainApi['call']; get tx(): ChainApi['tx']; at(hash: BlockHash): Promise>; setSigner(signer?: InjectedSigner): void; protected internalQueryMulti(queries: { fn: GenericStorageQuery; args?: any[]; }[], callback?: Callback, blockHash?: BlockHash): Promise; /** * Query multiple storage items in a single call * * This method allows you to query multiple storage items in a single call or set up a subscription * to multiple storage items. It provides type safety for both the query functions and their results. * * @example * // One-time query with type-safe results * const [balance, blockNumber] = await client.queryMulti([ * { fn: client.query.system.account, args: [ALICE] }, * { fn: client.query.system.number, args: [] } * ]); * // balance will be typed as AccountInfo * // blockNumber will be typed as number * * * @template Fns Array of storage query functions * @param queries - Array of query specifications, each with a function and optional arguments * @param callback - Optional callback for subscription-based queries * @returns For one-time queries: Array of decoded values with proper types; For subscriptions: Unsubscribe function */ queryMulti(queries: { [K in keyof Fns]: Query; }): Promise<{ [K in keyof Fns]: QueryFnResult; }>; queryMulti(queries: { [K in keyof Fns]: Query; }, callback: Callback<{ [K in keyof Fns]: QueryFnResult; }>): Promise; protected getStorageQuery(): BaseStorageQuery; sendTx(tx: HexString | Extrinsic, callback?: Callback>): TxUnsub; toTx(tx: HexString | Uint8Array | Extrinsic | IRuntimeTxCall): ChainSubmittableExtrinsic; get chainSpec(): IChainSpec; on(event: Event, handler: EventHandlerFn): () => void; }