@electrum-cash/network
Advanced tools
Comparing version
@@ -1,5 +0,2 @@ | ||
import * as net from "net"; | ||
import { WebSocket, MessageEvent, ErrorEvent } from "@monsterbitar/isomorphic-ws"; | ||
import { EventEmitter } from "events"; | ||
import { Mutex } from "async-mutex"; | ||
type RPCParameter = string | number | boolean | null; | ||
@@ -150,72 +147,2 @@ interface RPCBase { | ||
/** | ||
* Isomorphic Socket interface supporting TCP sockets and WebSockets (Node and browser). | ||
* The interface is a subset of the TLSSocket interface with some slight modifications. | ||
* It can be expanded when more socket functionality is needed in the rest of the | ||
* electrum-cash code. Changes from the TLSSocket interface (besides it being a subset): | ||
* - Event 'close' -> 'disconnect' | ||
* - New function socket.disconnect() | ||
* | ||
* @ignore | ||
*/ | ||
declare class ElectrumSocket extends EventEmitter { | ||
tcpSocket?: net.Socket; | ||
webSocket?: WebSocket; | ||
timers: { | ||
retryConnection?: number; | ||
disconnect?: number; | ||
}; | ||
onConnectHasRun: boolean; | ||
eventForwarders: { | ||
disconnect: () => boolean; | ||
tcpData: (data: string) => boolean; | ||
wsData: (event: MessageEvent) => boolean; | ||
tcpError: (err: Error) => boolean; | ||
wsError: (event: ErrorEvent) => boolean; | ||
}; | ||
/** | ||
* Connect to host:port using the specified transport | ||
* | ||
* @param {string} host Fully qualified domain name or IP address of the host | ||
* @param {number} port Network port for the host to connect to | ||
* @param {TransportScheme} scheme Transport scheme to use | ||
* @param {number} timeout If no connection is established after `timeout` ms, the connection is terminated | ||
* | ||
* @throws {Error} if an incorrect transport scheme is specified | ||
*/ | ||
connect(host: string, port: number, scheme: TransportScheme, timeout: number): void; | ||
/** | ||
* Sets up forwarding of events related to the connection. | ||
* | ||
* @param {string} connectionType Name of the connection/transport type, used for logging. | ||
* @param {string} host Fully qualified domain name or IP address of the host | ||
* @param {number} port Network port for the host to connect to | ||
*/ | ||
onConnect(connectionType: string, host: string, port: number): void; | ||
/** | ||
* Forcibly terminate the connection. | ||
* | ||
* @throws {Error} if no connection was found | ||
*/ | ||
disconnect(): void; | ||
/** | ||
* Write data to the socket | ||
* | ||
* @param {Uint8Array | string} data Data to be written to the socket | ||
* @param {function} callback Callback function to be called when the write has completed | ||
* | ||
* @throws {Error} if no connection was found | ||
* @returns true if the message was fully flushed to the socket, false if part of the message | ||
* is queued in the user memory | ||
*/ | ||
write(data: Uint8Array | string, callback?: (err?: Error) => void): boolean; | ||
/** | ||
* Force a disconnection if no connection is established after `timeout` milliseconds. | ||
* | ||
* @param {string} host Host of the connection that timed out | ||
* @param {number} port Port of the connection that timed out | ||
* @param {number} timeout Elapsed milliseconds | ||
*/ | ||
disconnectOnTimeout(host: string, port: number, timeout: number): void; | ||
} | ||
/** | ||
* Wrapper around TLS/WSS sockets that gracefully separates a network stream into Electrum protocol messages. | ||
@@ -235,12 +162,5 @@ * | ||
useBigInt: boolean; | ||
socket: ElectrumSocket; | ||
status: ConnectionStatus; | ||
lastReceivedTimestamp: number; | ||
software: string; | ||
timers: { | ||
keepAlive?: number; | ||
reconnect?: number; | ||
}; | ||
verifications: Array<number>; | ||
status: ConnectionStatus; | ||
messageBuffer: string; | ||
/** | ||
@@ -379,9 +299,12 @@ * Sets up network configuration for an Electrum client connection. | ||
export class ElectrumClient extends EventEmitter { | ||
application: string; | ||
version: string; | ||
host: string; | ||
port: number; | ||
scheme: TransportScheme; | ||
timeout: number; | ||
pingInterval: number; | ||
reconnectInterval: number; | ||
useBigInt: boolean; | ||
connection: ElectrumConnection; | ||
subscriptionMethods: Record<string, Set<string>>; | ||
requestId: number; | ||
requestResolvers: { | ||
[index: number]: RequestResolver; | ||
}; | ||
connectionLock: Mutex; | ||
/** | ||
@@ -470,155 +393,3 @@ * Initializes an Electrum client. | ||
} | ||
/** | ||
* Triggers when the cluster connects to enough servers to satisfy both the cluster confidence and distribution policies. | ||
* | ||
* @event ElectrumCluster#ready | ||
* @deprecated | ||
*/ | ||
/** | ||
* Triggers when the cluster loses a connection and can no longer satisfy the cluster distribution policy. | ||
* | ||
* @event ElectrumCluster#degraded | ||
* @deprecated | ||
*/ | ||
/** | ||
* Triggers when the cluster loses a connection and can no longer satisfy the cluster confidence policy. | ||
* | ||
* @event ElectrumCluster#disabled | ||
* @deprecated | ||
*/ | ||
/** | ||
* Triggers when the cluster verifies the integrity of remote server sent data that is not a request responses. | ||
* | ||
* @event ElectrumCluster#notification | ||
* @deprecated | ||
*/ | ||
/** | ||
* High-level electrum client that provides transparent load balancing, confidence checking and/or low-latency polling. | ||
* @deprecated | ||
*/ | ||
export class ElectrumCluster extends EventEmitter { | ||
application: string; | ||
version: string; | ||
confidence: number; | ||
distribution: number; | ||
order: ClusterOrder; | ||
timeout: number; | ||
pingInterval: number; | ||
reconnectInterval: number; | ||
useBigInt: boolean; | ||
clients: { | ||
[index: string]: ClientConfig; | ||
}; | ||
connections: number; | ||
notifications: Record<string, Set<string>>; | ||
status: ClusterStatus; | ||
requestCounter: number; | ||
requestPromises: { | ||
[index: number]: Promise<Error | RequestResponse>[]; | ||
}; | ||
requestLock: Mutex; | ||
responseLock: Mutex; | ||
/** | ||
* @param {string} application your application name, used to identify to the electrum hosts. | ||
* @param {string} version protocol version to use with the hosts. | ||
* @param {number} confidence wait for this number of hosts to provide identical results. | ||
* @param {number} distribution request information from this number of hosts. | ||
* @param {ClusterOrder} order select hosts to communicate with in this order. | ||
* @param {number} timeout how long network delays we will wait for before taking action, in milliseconds. | ||
* @param {number} pingInterval the time between sending pings to the electrum host, in milliseconds. | ||
* @param {number} reconnectInterval the time between reconnection attempts to the electrum host, in milliseconds. | ||
* @param {boolean} useBigInt whether to use bigint for numbers in json response. | ||
*/ | ||
constructor(application: string, version: string, confidence?: number, distribution?: number, order?: ClusterOrder, timeout?: number, pingInterval?: number, reconnectInterval?: number, useBigInt?: boolean); | ||
/** | ||
* Adds a server to the cluster. | ||
* @deprecated | ||
* | ||
* @param {string} host fully qualified domain name or IP number of the host. | ||
* @param {number} port the TCP network port of the host. | ||
* @param {TransportScheme} scheme the transport scheme to use for connection | ||
* @param {boolean} autoConnect flag indicating whether the server should automatically connect (default true) | ||
* | ||
* @throws {Error} if the cluster's version is not a valid version string. | ||
* @returns a promise that resolves when the connection has been initiated. | ||
*/ | ||
addServer(host: string, port?: number, scheme?: TransportScheme, autoConnect?: boolean): Promise<void>; | ||
/** | ||
* Calls a method on the remote server with the supplied parameters. | ||
* @deprecated | ||
* | ||
* @param {string} method name of the method to call. | ||
* @param {...string} parameters one or more parameters for the method. | ||
* | ||
* @throws {Error} if not enough clients are connected | ||
* @throws {Error} if no response is received with sufficient integrity | ||
* @returns a promise that resolves with the result of the method. | ||
*/ | ||
request(method: string, ...parameters: RPCParameter[]): Promise<Error | RequestResponse>; | ||
/** | ||
* Subscribes to the method at the cluster and attaches the callback function to the event feed. | ||
* @deprecated | ||
* | ||
* @note the response for the subscription request is issued as a notification event. | ||
* | ||
* @param {string} method one of the subscribable methods the server supports. | ||
* @param {...string} parameters one or more parameters for the method. | ||
* | ||
* @throws {Error} if not enough clients are connected | ||
* @throws {Error} if no response is received with sufficient integrity for the initial request | ||
*/ | ||
subscribe(method: string, ...parameters: RPCParameter[]): Promise<void>; | ||
/** | ||
* Unsubscribes to the method at the cluster and removes any callback functions | ||
* when there are no more subscriptions for the method. | ||
* @deprecated | ||
* | ||
* @param {string} method one of the subscribable methods the server supports. | ||
* @param {...string} parameters one or more parameters for the method. | ||
* | ||
* @throws {Error} if, for any of the clients, no subscriptions exist for the combination of the provided `method` and `parameters. | ||
*/ | ||
unsubscribe(method: string, ...parameters: RPCParameter[]): Promise<void>; | ||
/** | ||
* Define a callback function to validate server notifications and pass them to the subscribe callback. | ||
* @deprecated | ||
* | ||
* @ignore | ||
*/ | ||
handleSubscriptionNotifications(clientIdentity: string, data: RPCNotification): Promise<void>; | ||
/** | ||
* Forgets/Removes notification data for a specific notification. | ||
* | ||
* This is required in order to allow future identical notifications to be properly processed and emitted. | ||
* @deprecated | ||
*/ | ||
dismissSubscriptionNotification(responseDataIdentifier: any): Promise<void>; | ||
/** | ||
* Provides a method to check or wait for the cluster to become ready. | ||
* @deprecated | ||
* | ||
* @returns a promise that resolves when the required servers are available. | ||
*/ | ||
ready(): Promise<boolean>; | ||
/** | ||
* Connects all servers from the cluster and attaches event listeners and handlers | ||
* for all underlying clients and connections. | ||
* @deprecated | ||
* | ||
* @throws {Error} if the cluster's version is not a valid version string. | ||
*/ | ||
startup(): Promise<void[]>; | ||
/** | ||
* Disconnects all servers from the cluster. Removes all event listeners and | ||
* handlers from all underlying clients and connections. This includes all | ||
* active subscriptions, unless retainSubscriptions is set to true. | ||
* @deprecated | ||
* | ||
* @param {boolean} retainSubscriptions retain subscription data so they will be restored on reconnection. | ||
* | ||
* @returns a list with the disconnection result for every client | ||
*/ | ||
shutdown(retainSubscriptions?: boolean): Promise<boolean[]>; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@electrum-cash/network", | ||
"version": "3.3.1-development.6372294997", | ||
"version": "4.0.0-development.6391574314", | ||
"description": "@electrum-cash/network is a lightweight JavaScript library that lets you connect with one or more Electrum servers.", | ||
@@ -24,6 +24,4 @@ "homepage": "https://gitlab.com/electrum-cash/network#readme", | ||
"type": "module", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
"exports": { | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.mjs", | ||
@@ -54,5 +52,5 @@ "browser": "./dist/browser.mjs" | ||
"@typescript-eslint/eslint-plugin": "^6.8.0", | ||
"@vitest/coverage-v8": "^0.34.6", | ||
"@vitest/coverage-v8": "^1.3.1", | ||
"better-docs": "^2.7.2", | ||
"cspell": "^7.3.8", | ||
"cspell": "^8.6.0", | ||
"del-cli": "^5.0.0", | ||
@@ -65,5 +63,4 @@ "docdash": "^2.0.1", | ||
"parcel": "^2.9.2", | ||
"process": "^0.11.10", | ||
"typescript": "^5.1.3", | ||
"vitest": "^0.34.6" | ||
"vitest": "^1.3.1" | ||
}, | ||
@@ -73,5 +70,5 @@ "dependencies": { | ||
"@types/ws": "^8.5.5", | ||
"async-mutex": "^0.4.0", | ||
"async-mutex": "^0.5.0", | ||
"debug": "^4.3.2", | ||
"lossless-json": "^2.0.11", | ||
"lossless-json": "^4.0.1", | ||
"ws": "^8.13.0" | ||
@@ -78,0 +75,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
19
-5%2
-50%184185
-60.12%7
-22.22%1575
-58.33%+ Added
+ Added
- Removed
- Removed
Updated
Updated