import { PromiseEventWrap } from './model/PromiEventWrap'; import { IWeb3ClientStatus } from './interfaces/IWeb3ClientStatus'; import { ClientStatus } from './model/ClientStatus'; import { ClientPoolTrace } from './ClientPoolStats'; import { IWeb3ClientOptions } from './interfaces/IWeb3Client'; import { RateLimitGuard } from './handlers/RateLimitGuard'; import { Web3BatchRequests } from './Web3BatchRequests'; import { Rpc, RpcTypes } from '../rpc/Rpc'; import { PromiseEvent } from '../class/PromiseEvent'; import { TTransport } from '../rpc/transports/ITransport'; import { TRpc } from '../rpc/RpcBase'; import { TEth } from '../models/TEth'; import { DataLike } from '../utils/types'; export interface IRpcConfig { url?: string; options?: TTransport.Options.Http | TTransport.Options.Ws; /** Will be a preferred node for submitting transactions */ safe?: boolean; distinct?: boolean; wallet?: boolean; web3?: TTransport.Transport | Promise; name?: string; /** Will be used only if manually requested with .getWeb3, or .getNodeUrl */ manual?: boolean; /** max block range per request when getting for example the past logs*/ fetchableBlockRange?: number; /** True if the node supports traceTransaction calls */ traceable?: boolean; rateLimit?: string; blockRangeLimit?: string | number; batchLimit?: number; methods?: { exclude?: string[]; only?: string[]; }; } export interface IPoolWeb3Request { ws?: boolean; preferSafe?: boolean; /** Request wallet node to submit unsigned transactions */ wallet?: boolean; distinct?: boolean; name?: string; /** HTTP Web3 Client traces */ trace?: ClientPoolTrace; /** Supported node features */ node?: { url?: string; /** Supports traceTransaction */ traceable?: boolean; }; /** RPC method - will find the node that has the configuration */ method?: string; batchRequestCount?: number; blockRangeCount?: number; } export declare class ClientPool { private discoveredPartial; private discoveredFull; private clients; private ws; /** Minimum rate limit range to assume the RPC is alive */ MINIMUM_BLOCK_RANGE: number; constructor(config: IWeb3ClientOptions); callBatched(data: { requests: (rpc: Rpc) => Promise; map?: (results: any[]) => any; }, opts?: IPoolWeb3Request): Promise; call(fn: (wClient: WClient) => Promise, opts?: IPoolWeb3Request): Promise; getRpc(options?: IPoolWeb3Request): Promise; getWrappedWeb3(options?: IPoolWeb3Request): Promise; getNodeURL(options?: IPoolWeb3Request): Promise; releaseWeb3(): Promise; getOptionForFetchableRange(blockRangeLimits?: WClient['blockRangeLimits']): number; wrappedPromiEvent(asyncFactory: () => Promise): PromiseEvent; callPromiEvent>(fn: (web3: WClient) => TResult, opts?: { preferSafe?: boolean; parallel?: number; silent?: boolean; distinct?: boolean; wallet?: boolean; }, used?: Map, errors?: any[], root?: PromiseEventWrap): TResult; getNodeStats(): { success: number; fail: number; ping: number; url: string; }[]; getNodeInfos(options?: { timeout?: number; calls?: ('net_peerCount' | 'eth_blockNumber' | 'eth_syncing' | 'net_version')[]; }): Promise; private next; private getClientWithLowestWaitTime; /** * We may have tens of Nodes to communicate with. Discover LIVE and operating nodes. * Resolves when first 3 active nodes are discovered, to prevent waiting for all of them. * @returns * - Ready Promise - in case 3 clients look good * - Complete Promise - when all clients are resolved */ private discoverLive; } export declare class WClient { lastStatus: number; lastDate: number; status: 'ok' | 'off' | 'ping'; requests: { success: number; fail: number; ping: number; }; rpc: Rpc; config: IRpcConfig; rateLimitGuard: RateLimitGuard; /** For getLogs method, as some providers limit the range request or page result value */ blockRangeLimits: { blocks?: number; results?: number; }; batchLimit?: number; healthy(): boolean; private updateRateLimitInfo; updateBlockRangeInfo(info: WClient['blockRangeLimits']): void; constructor(mix: IRpcConfig); send(fn: (web3: WClient) => PromiseEvent): Promise<{ status: ClientStatus; error?: any; result?: PromiseEvent; }>; sendSignedTransaction(tx: TEth.Hex): PromiseEvent; sendTransaction(tx: any): PromiseEvent; sign(address: TEth.Address, message: string): Promise; signTypedData(address: TEth.Address, typedData: DataLike): Promise; callBatched(requests: TRpc.IRpcAction[]): Promise; call>(fn: (wClient: WClient) => TResult, options?: { batchRequestCount?: number; }): Promise<{ status: ClientStatus; error?: any; result?: Awaited; time: number; }>; callPromiEvent>(fn: (web3: WClient) => TResult): TResult; callSubscription>(fn: (web3: WClient) => TResult): TResult; onComplete(status: ClientStatus, timeMs: number): void; ensureConnected(): Promise; getRequestCount(): number; /** * Checks the rate limit wait time, so that the POOL can select the wClient with shortest wait time **/ getRateLimitGuardTime(): number; private getSpanLimit; }