opnet
Version:
The perfect library for building Bitcoin-based applications.
75 lines (74 loc) • 2.99 kB
TypeScript
import { Network } from '@btc-vision/bitcoin';
import { AbstractRpcProvider } from './AbstractRpcProvider.js';
import { JsonRpcPayload } from './interfaces/JSONRpc.js';
import { JsonRpcCallResult } from './interfaces/JSONRpcResult.js';
import { ConnectionState } from './websocket/types/ConnectionState.js';
import { SubscriptionType } from './websocket/types/SubscriptionType.js';
import { WebSocketClientConfig } from './websocket/types/WebSocketClientConfig.js';
import { BlockNotification, EpochNotification, EventHandler, MempoolNotification, SubscriptionHandler, WebSocketClientEvent } from './websocket/types/WebSocketProviderTypes.js';
export interface WebSocketRpcProviderConfig {
readonly url: string;
readonly network: Network;
readonly websocketConfig?: Partial<Omit<WebSocketClientConfig, 'url'>>;
}
export declare class WebSocketRpcProvider extends AbstractRpcProvider {
private readonly config;
private readonly pendingRequests;
private readonly subscriptions;
private readonly eventHandlers;
private socket;
private state;
private requestId;
private reconnectAttempt;
private pingTimeout;
private sessionId;
private userRequestedDisconnect;
private protoRoot;
private protoTypes;
constructor(providerConfig: WebSocketRpcProviderConfig);
getState(): ConnectionState;
isReady(): boolean;
connect(): Promise<void>;
disconnect(): void;
on<T>(event: WebSocketClientEvent, handler: EventHandler<T>): void;
off<T>(event: WebSocketClientEvent, handler: EventHandler<T>): void;
subscribeBlocks(handler: SubscriptionHandler<BlockNotification>): Promise<void>;
subscribeEpochs(handler: SubscriptionHandler<EpochNotification>): Promise<void>;
subscribeMempool(handler: SubscriptionHandler<MempoolNotification>): Promise<void>;
unsubscribe(subscriptionType: SubscriptionType): Promise<void>;
clearCache(): void;
_send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>;
protected providerUrl(url: string): string;
private sendJsonRpcRequest;
private translateJsonRpcParamsToFieldIds;
private convertOPNetTypeToString;
private convertTransaction;
private convertBlockResponse;
private translateProtoResponse;
private connectWebSocket;
private buildWebSocketUrl;
private performHandshake;
private buildMessageByFieldId;
private getFieldById;
private getFieldNameById;
private getNestedType;
private getType;
private nextRequestId;
private buildMessage;
private sendRequest;
private send;
private handleMessage;
private handleErrorResponse;
private handleBlockNotification;
private handleEpochNotification;
private handleMempoolNotification;
private handleClose;
private reconnect;
private resubscribe;
private cleanupPendingRequests;
private schedulePing;
private cancelPing;
private ping;
private emit;
private sleep;
}