@electrum-cash/network 4.0.0-development.6655313659 → 4.0.0-development.8017676278

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,33 +1,14 @@
1
+ import $dvphU$electrumcashdebuglogs from "@electrum-cash/debug-logs";
1
2
  import {EventEmitter as $dvphU$EventEmitter} from "events";
2
3
  import {Mutex as $dvphU$Mutex} from "async-mutex";
3
- import $dvphU$debug from "debug";
4
+ import {ElectrumWebSocket as $dvphU$ElectrumWebSocket} from "@electrum-cash/sockets";
4
5
  import {parse as $dvphU$parse, parseNumberAndBigInt as $dvphU$parseNumberAndBigInt} from "lossless-json";
5
- import {connect as $dvphU$connect, TLSSocket as $dvphU$TLSSocket} from "tls";
6
- import {isIP as $dvphU$isIP, connect as $dvphU$connect1} from "net";
7
- import {WebSocket as $dvphU$WebSocket} from "@monsterbitar/isomorphic-ws";
8
6
 
9
7
 
10
8
  function $parcel$export(e, n, v, s) {
11
9
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
12
10
  }
13
11
 
14
- // Create the debug logs.
15
- const $623a31cc1663a627$var$debug = {
16
- client: (0, $dvphU$debug)("electrum-cash:client "),
17
- errors: (0, $dvphU$debug)("electrum-cash:error "),
18
- warning: (0, $dvphU$debug)("electrum-cash:warning"),
19
- network: (0, $dvphU$debug)("electrum-cash:network"),
20
- ping: (0, $dvphU$debug)("electrum-cash:pulses ")
21
- };
22
- // Set log colors.
23
- $623a31cc1663a627$var$debug.client.color = "2";
24
- $623a31cc1663a627$var$debug.errors.color = "9";
25
- $623a31cc1663a627$var$debug.warning.color = "13";
26
- $623a31cc1663a627$var$debug.network.color = "4";
27
- $623a31cc1663a627$var$debug.ping.color = "8";
28
- var // Export the logs.
29
- $623a31cc1663a627$export$2e2bcd8739ae039 = $623a31cc1663a627$var$debug;
30
-
31
12
 
32
13
 
33
14
  /**
@@ -38,9 +19,9 @@ $623a31cc1663a627$export$2e2bcd8739ae039 = $623a31cc1663a627$var$debug;
38
19
  /**
39
20
  * Helper function that builds an Electrum request object.
40
21
  *
41
- * @param {string} method method to call.
42
- * @param {array} parameters method parameters for the call.
43
- * @param {string} requestId unique string or number referencing this request.
22
+ * @param method - method to call.
23
+ * @param parameters - method parameters for the call.
24
+ * @param requestId - unique string or number referencing this request.
44
25
  *
45
26
  * @returns a properly formatted Electrum request string.
46
27
  */ static buildRequestObject(method, parameters, requestId) {
@@ -87,354 +68,17 @@ const $e83d2e7688025acd$export$9598f0c76aa41d73 = function(object) {
87
68
 
88
69
  var $d801b1f9b7fc3074$exports = {};
89
70
 
90
- $parcel$export($d801b1f9b7fc3074$exports, "ElectrumTransport", () => $d801b1f9b7fc3074$export$d048df559e6d3842);
91
- $parcel$export($d801b1f9b7fc3074$exports, "DefaultParameters", () => $d801b1f9b7fc3074$export$f019be48b3aacb1a);
92
- const $d801b1f9b7fc3074$export$d048df559e6d3842 = {
93
- TCP: {
94
- Port: 50001,
95
- Scheme: "tcp"
96
- },
97
- TCP_TLS: {
98
- Port: 50002,
99
- Scheme: "tcp_tls"
100
- },
101
- WS: {
102
- Port: 50003,
103
- Scheme: "ws"
104
- },
105
- WSS: {
106
- Port: 50004,
107
- Scheme: "wss"
108
- }
109
- };
110
- const $d801b1f9b7fc3074$export$f019be48b3aacb1a = {
111
- // Port number for TCP TLS connections
112
- PORT: $d801b1f9b7fc3074$export$d048df559e6d3842.TCP_TLS.Port,
113
- // Transport to connect to the Electrum server
114
- TRANSPORT_SCHEME: $d801b1f9b7fc3074$export$d048df559e6d3842.TCP_TLS.Scheme,
115
- // How long to wait before attempting to reconnect, in milliseconds.
116
- RECONNECT: 5000,
117
- // How long to wait for network operations before following up, in milliseconds.
118
- TIMEOUT: 30000,
119
- // Time between ping messages, in milliseconds. Pinging keeps the connection alive.
120
- // The reason for pinging this frequently is to detect connection problems early.
121
- PING_INTERVAL: 1000,
122
- // If we use BigInt for numbers in json when parsing and returning json response from the server.
123
- USE_BIG_INT: false
124
- };
125
-
71
+ $parcel$export($d801b1f9b7fc3074$exports, "DEFAULT_PING_INTERVAL", () => $d801b1f9b7fc3074$export$a3a6b8a974871191);
72
+ $parcel$export($d801b1f9b7fc3074$exports, "DEFAULT_RECONNECT_INTERVAL", () => $d801b1f9b7fc3074$export$b2115084b892a79d);
73
+ $parcel$export($d801b1f9b7fc3074$exports, "DEFAULT_BIG_INTEGERS", () => $d801b1f9b7fc3074$export$788e8376894ebb88);
74
+ // Time between ping messages, in milliseconds. Pinging keeps the connection alive.
75
+ // The reason for pinging this frequently is to detect connection problems early.
76
+ const $d801b1f9b7fc3074$export$a3a6b8a974871191 = 1000;
77
+ const $d801b1f9b7fc3074$export$b2115084b892a79d = 5000;
78
+ const $d801b1f9b7fc3074$export$788e8376894ebb88 = false;
126
79
 
127
80
 
128
81
 
129
-
130
-
131
-
132
-
133
-
134
- class $0a4cf22b9d6c493c$export$22c0ca2c816c3e08 extends (0, $dvphU$EventEmitter) {
135
- /**
136
- * Connect to host:port using the specified transport
137
- *
138
- * @param {string} host Fully qualified domain name or IP address of the host
139
- * @param {number} port Network port for the host to connect to
140
- * @param {TransportScheme} scheme Transport scheme to use
141
- * @param {number} timeout If no connection is established after `timeout` ms, the connection is terminated
142
- *
143
- * @throws {Error} if an incorrect transport scheme is specified
144
- */ connect(host, port, scheme, timeout) {
145
- // Check that no existing socket exists before initiating a new connection.
146
- if (this.tcpSocket) throw new Error("Cannot initiate a new socket connection when an existing connection exists");
147
- // Set a timer to force disconnect after `timeout` seconds
148
- this.timers.disconnect = setTimeout(()=>this.disconnectOnTimeout(host, port, timeout), timeout);
149
- // Remove the timer if a connection is successfully established
150
- this.once("connect", this.clearDisconnectTimerOnTimeout);
151
- // Define how to refer to the connection scheme in debug output.
152
- const socketTypes = {
153
- [(0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP.Scheme]: "a TCP Socket",
154
- [(0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP_TLS.Scheme]: "an encrypted TCP socket"
155
- };
156
- // Log that we are trying to establish a connection.
157
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Initiating ${socketTypes[scheme]} connection to '${host}:${port}'.`);
158
- if (scheme !== (0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP.Scheme && scheme !== (0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP_TLS.Scheme) // Throw an error if an incorrect transport is specified
159
- throw new Error("Incorrect transport specified");
160
- if (scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP_TLS.Scheme) {
161
- // Initialize connection options.
162
- const connectionOptions = {
163
- rejectUnauthorized: false
164
- };
165
- // If the hostname is not an IP address..
166
- if (!$dvphU$isIP(host)) // Set the servername option which enables support for SNI.
167
- // NOTE: SNI enables a server that hosts multiple domains to provide the appropriate TLS certificate.
168
- connectionOptions.serverName = host;
169
- // Initialize the socket (allowing self-signed certificates).
170
- this.tcpSocket = $dvphU$connect(port, host, connectionOptions);
171
- // Add a 'secureConnect' listener that checks the authorization status of
172
- // the socket, and logs a warning when it uses a self signed certificate.
173
- this.tcpSocket.once("secureConnect", ()=>{
174
- // Cannot happen, since this event callback *only* exists on TLSSocket
175
- if (!(this.tcpSocket instanceof $dvphU$TLSSocket)) return;
176
- // Force cast authorizationError from Error to string (through unknown)
177
- // because it is incorrectly typed as an Error
178
- const authorizationError = this.tcpSocket.authorizationError;
179
- if (authorizationError === "DEPTH_ZERO_SELF_SIGNED_CERT") (0, $623a31cc1663a627$export$2e2bcd8739ae039).warning(`Connection to ${host}:${port} uses a self-signed certificate`);
180
- });
181
- // Trigger successful connection events.
182
- this.tcpSocket.on("secureConnect", this.onConnect.bind(this, socketTypes[scheme], host, port));
183
- } else {
184
- // Initialize the socket.
185
- this.tcpSocket = $dvphU$connect1({
186
- host: host,
187
- port: port
188
- });
189
- // Trigger successful connection events.
190
- this.tcpSocket.on("connect", this.onConnect.bind(this, socketTypes[scheme], host, port));
191
- }
192
- // Configure encoding.
193
- this.tcpSocket.setEncoding("utf8");
194
- // Enable persistent connections.
195
- // NOTE: This will send a non-data message 0.25 second after last activity.
196
- // After 10 consecutive such messages with no response, the connection will be cut.
197
- this.tcpSocket.setKeepAlive(true, 250);
198
- // Disable buffering of outgoing data.
199
- this.tcpSocket.setNoDelay(true);
200
- // Forward the encountered errors.
201
- this.tcpSocket.on("error", this.eventForwarders.tcpError);
202
- }
203
- /**
204
- * Sets up forwarding of events related to the connection.
205
- *
206
- * @param {string} connectionType Name of the connection/transport type, used for logging.
207
- * @param {string} host Fully qualified domain name or IP address of the host
208
- * @param {number} port Network port for the host to connect to
209
- */ onConnect(connectionType, host, port) {
210
- // If the onConnect function has already run, do not execute it again.
211
- if (this.onConnectHasRun) return;
212
- // Log that the connection has been established.
213
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Established ${connectionType} connection with '${host}:${port}'.`);
214
- // Forward the socket events
215
- this.tcpSocket.addListener("close", this.eventForwarders.disconnect);
216
- this.tcpSocket.addListener("data", this.eventForwarders.tcpData);
217
- // Indicate that the onConnect function has run.
218
- this.onConnectHasRun = true;
219
- // Emit the connect event.
220
- this.emit("connect");
221
- }
222
- /**
223
- * Clears the disconnect timer if it is still active.
224
- */ clearDisconnectTimerOnTimeout() {
225
- // Clear the retry timer if it is still active.
226
- if (this.timers.disconnect) clearTimeout(this.timers.disconnect);
227
- }
228
- /**
229
- * Forcibly terminate the connection.
230
- *
231
- * @throws {Error} if no connection was found
232
- */ disconnect() {
233
- // Clear the disconnect timer so that the socket does not try to disconnect again later.
234
- this.clearDisconnectTimerOnTimeout();
235
- if (this.tcpSocket) {
236
- // Remove all event forwarders.
237
- this.tcpSocket.removeListener("close", this.eventForwarders.disconnect);
238
- this.tcpSocket.removeListener("data", this.eventForwarders.tcpData);
239
- this.tcpSocket.removeListener("error", this.eventForwarders.tcpError);
240
- // Terminate the connection.
241
- this.tcpSocket.destroy();
242
- // Remove the stored socket.
243
- this.tcpSocket = undefined;
244
- }
245
- // Indicate that the onConnect function has not run and it has to be run again.
246
- this.onConnectHasRun = false;
247
- // Emit a disconnect event
248
- this.emit("disconnect");
249
- }
250
- /**
251
- * Write data to the socket
252
- *
253
- * @param {Uint8Array | string} data Data to be written to the socket
254
- * @param {function} callback Callback function to be called when the write has completed
255
- *
256
- * @throws {Error} if no connection was found
257
- * @returns true if the message was fully flushed to the socket, false if part of the message
258
- * is queued in the user memory
259
- */ write(data, callback) {
260
- // Throw an error if no active connection is found
261
- if (!this.tcpSocket) throw new Error("Cannot write to socket when there is no active connection");
262
- // Write data to the TLS Socket and return the status indicating
263
- // whether the full message was flushed to the socket
264
- return this.tcpSocket.write(data, callback);
265
- }
266
- /**
267
- * Force a disconnection if no connection is established after `timeout` milliseconds.
268
- *
269
- * @param {string} host Host of the connection that timed out
270
- * @param {number} port Port of the connection that timed out
271
- * @param {number} timeout Elapsed milliseconds
272
- */ disconnectOnTimeout(host, port, timeout) {
273
- // Remove the connect listener.
274
- this.removeListener("connect", this.clearDisconnectTimerOnTimeout);
275
- // Create a new timeout error.
276
- const timeoutError = {
277
- code: "ETIMEDOUT",
278
- message: `Connection to '${host}:${port}' timed out after ${timeout} milliseconds`
279
- };
280
- // Emit an error event so that connect is rejected upstream.
281
- this.emit("error", timeoutError);
282
- // Forcibly disconnect to clean up the connection on timeout
283
- this.disconnect();
284
- }
285
- constructor(...args){
286
- super(...args);
287
- // Declare timers for keep-alive pings and reconnection
288
- this.timers = {};
289
- // Initialize boolean that indicates whether the onConnect function has run (initialize to false).
290
- this.onConnectHasRun = false;
291
- // Initialize event forwarding functions.
292
- this.eventForwarders = {
293
- disconnect: ()=>this.emit("disconnect"),
294
- tcpData: (data)=>this.emit("data", data),
295
- tcpError: (err)=>this.emit("error", err)
296
- };
297
- }
298
- }
299
- class $0a4cf22b9d6c493c$export$25b4633f61498e1 extends (0, $dvphU$EventEmitter) {
300
- /**
301
- * Connect to host:port using the specified transport
302
- *
303
- * @param {string} host Fully qualified domain name or IP address of the host
304
- * @param {number} port Network port for the host to connect to
305
- * @param {TransportScheme} scheme Transport scheme to use
306
- * @param {number} timeout If no connection is established after `timeout` ms, the connection is terminated
307
- *
308
- * @throws {Error} if an incorrect transport scheme is specified
309
- */ connect(host, port, scheme, timeout) {
310
- // Check that no existing socket exists before initiating a new connection.
311
- if (this.webSocket) throw new Error("Cannot initiate a new socket connection when an existing connection exists");
312
- // Set a timer to force disconnect after `timeout` seconds
313
- this.timers.disconnect = setTimeout(()=>this.disconnectOnTimeout(host, port, timeout), timeout);
314
- // Remove the timer if a connection is successfully established
315
- this.once("connect", this.clearDisconnectTimerOnTimeout);
316
- // Define how to refer to the connection scheme in debug output.
317
- const socketTypes = {
318
- [(0, $d801b1f9b7fc3074$export$d048df559e6d3842).WS.Scheme]: "a WebSocket",
319
- [(0, $d801b1f9b7fc3074$export$d048df559e6d3842).WSS.Scheme]: "an encrypted WebSocket"
320
- };
321
- // Log that we are trying to establish a connection.
322
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Initiating ${socketTypes[scheme]} connection to '${host}:${port}'.`);
323
- if (scheme !== (0, $d801b1f9b7fc3074$export$d048df559e6d3842).WS.Scheme && scheme !== (0, $d801b1f9b7fc3074$export$d048df559e6d3842).WSS.Scheme) // Throw an error if an incorrect transport is specified
324
- throw new Error("Incorrect transport specified");
325
- if (scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).WSS.Scheme) // Initialize this.webSocket (rejecting self-signed certificates).
326
- // We reject self-signed certificates to match functionality of browsers.
327
- this.webSocket = new (0, $dvphU$WebSocket)(`wss://${host}:${port}`);
328
- else // Initialize this.webSocket.
329
- this.webSocket = new (0, $dvphU$WebSocket)(`ws://${host}:${port}`);
330
- // Trigger successful connection events.
331
- this.webSocket.addEventListener("open", this.onConnect.bind(this, socketTypes[scheme], host, port));
332
- // Forward the encountered errors.
333
- this.webSocket.addEventListener("error", this.eventForwarders.wsError);
334
- }
335
- /**
336
- * Sets up forwarding of events related to the connection.
337
- *
338
- * @param {string} connectionType Name of the connection/transport type, used for logging.
339
- * @param {string} host Fully qualified domain name or IP address of the host
340
- * @param {number} port Network port for the host to connect to
341
- */ onConnect(connectionType, host, port) {
342
- // If the onConnect function has already run, do not execute it again.
343
- if (this.onConnectHasRun) return;
344
- // Log that the connection has been established.
345
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Established ${connectionType} connection with '${host}:${port}'.`);
346
- // Forward the socket events
347
- this.webSocket.addEventListener("close", this.eventForwarders.disconnect);
348
- this.webSocket.addEventListener("message", this.eventForwarders.wsData);
349
- // Indicate that the onConnect function has run.
350
- this.onConnectHasRun = true;
351
- // Emit the connect event.
352
- this.emit("connect");
353
- }
354
- /**
355
- * Clears the disconnect timer if it is still active.
356
- */ clearDisconnectTimerOnTimeout() {
357
- // Clear the retry timer if it is still active.
358
- if (this.timers.disconnect) clearTimeout(this.timers.disconnect);
359
- }
360
- /**
361
- * Forcibly terminate the connection.
362
- *
363
- * @throws {Error} if no connection was found
364
- */ disconnect() {
365
- // Clear the disconnect timer so that the socket does not try to disconnect again later.
366
- this.clearDisconnectTimerOnTimeout();
367
- try {
368
- // Remove all event forwarders.
369
- this.webSocket.removeEventListener("close", this.eventForwarders.disconnect);
370
- this.webSocket.removeEventListener("message", this.eventForwarders.wsData);
371
- this.webSocket.removeEventListener("error", this.eventForwarders.wsError);
372
- // Gracefully terminate the connection.
373
- this.webSocket.close();
374
- } catch (ignored) {
375
- // close() will throw an error if the connection has not been established yet.
376
- // We ignore this error, since no similar error gets thrown in the TLS Socket.
377
- } finally{
378
- // Remove the stored socket regardless of any thrown errors.
379
- this.webSocket = undefined;
380
- }
381
- // Indicate that the onConnect function has not run and it has to be run again.
382
- this.onConnectHasRun = false;
383
- // Emit a disconnect event
384
- this.emit("disconnect");
385
- }
386
- /**
387
- * Write data to the socket
388
- *
389
- * @param {Uint8Array | string} data Data to be written to the socket
390
- * @param {function} callback Callback function to be called when the write has completed
391
- *
392
- * @throws {Error} if no connection was found
393
- * @returns true if the message was fully flushed to the socket, false if part of the message
394
- * is queued in the user memory
395
- */ write(data, callback) {
396
- // Throw an error if no active connection is found
397
- if (!this.webSocket) throw new Error("Cannot write to socket when there is no active connection");
398
- // Write data to the WebSocket
399
- this.webSocket.send(data, callback);
400
- // WebSockets always fit everything in a single request, so we return true
401
- return true;
402
- }
403
- /**
404
- * Force a disconnection if no connection is established after `timeout` milliseconds.
405
- *
406
- * @param {string} host Host of the connection that timed out
407
- * @param {number} port Port of the connection that timed out
408
- * @param {number} timeout Elapsed milliseconds
409
- */ disconnectOnTimeout(host, port, timeout) {
410
- // Remove the connect listener.
411
- this.removeListener("connect", this.clearDisconnectTimerOnTimeout);
412
- // Create a new timeout error.
413
- const timeoutError = {
414
- code: "ETIMEDOUT",
415
- message: `Connection to '${host}:${port}' timed out after ${timeout} milliseconds`
416
- };
417
- // Emit an error event so that connect is rejected upstream.
418
- this.emit("error", timeoutError);
419
- // Forcibly disconnect to clean up the connection on timeout
420
- this.disconnect();
421
- }
422
- constructor(...args){
423
- super(...args);
424
- // Declare timers for keep-alive pings and reconnection
425
- this.timers = {};
426
- // Initialize boolean that indicates whether the onConnect function has run (initialize to false).
427
- this.onConnectHasRun = false;
428
- // Initialize event forwarding functions.
429
- this.eventForwarders = {
430
- disconnect: ()=>this.emit("disconnect"),
431
- wsData: (event)=>this.emit("data", `${event.data}\n`),
432
- wsError: (event)=>this.emit("error", event.error)
433
- };
434
- }
435
- }
436
-
437
-
438
82
  var $db7c797e63383364$exports = {};
439
83
 
440
84
  $parcel$export($db7c797e63383364$exports, "ClientState", () => $db7c797e63383364$export$c4f81c6d30ca200f);
@@ -467,38 +111,39 @@ var $db7c797e63383364$export$7516420eb880ab68;
467
111
  /**
468
112
  * Sets up network configuration for an Electrum client connection.
469
113
  *
470
- * @param {string} application your application name, used to identify to the electrum host.
471
- * @param {string} version protocol version to use with the host.
472
- * @param {string} host fully qualified domain name or IP number of the host.
473
- * @param {number} port the network port of the host.
474
- * @param {TransportScheme} scheme the transport scheme to use for connection
475
- * @param {number} timeout how long network delays we will wait for before taking action, in milliseconds.
476
- * @param {number} pingInterval the time between sending pings to the electrum host, in milliseconds.
477
- * @param {number} reconnectInterval the time between reconnection attempts to the electrum host, in milliseconds.
478
- * @param {boolean} useBigInt whether to use bigint for numbers in json response.
114
+ * @param application - your application name, used to identify to the electrum host.
115
+ * @param version - protocol version to use with the host.
116
+ * @param socketOrHostname - socket fully qualified domain name or IP number of the host
117
+ * @param pingInterval - the time between sending pings to the electrum host, in milliseconds.
118
+ * @param reconnectInterval - the time between reconnection attempts to the electrum host, in milliseconds.
119
+ * @param useBigInt - whether to use bigint for numbers in json response.
479
120
  *
480
121
  * @throws {Error} if `version` is not a valid version string.
481
- */ constructor(application, version, host, port = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).PORT, scheme = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).TRANSPORT_SCHEME, timeout = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).TIMEOUT, pingInterval = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).PING_INTERVAL, reconnectInterval = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).RECONNECT, useBigInt = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).USE_BIG_INT){
122
+ */ constructor(application, version, socketOrHostname, pingInterval = (0, $d801b1f9b7fc3074$export$a3a6b8a974871191), reconnectInterval = (0, $d801b1f9b7fc3074$export$b2115084b892a79d), useBigInt = (0, $d801b1f9b7fc3074$export$788e8376894ebb88)){
482
123
  // Initialize the event emitter.
483
124
  super();
484
125
  this.application = application;
485
126
  this.version = version;
486
- this.host = host;
487
- this.port = port;
488
- this.scheme = scheme;
489
- this.timeout = timeout;
127
+ this.socketOrHostname = socketOrHostname;
490
128
  this.pingInterval = pingInterval;
491
129
  this.reconnectInterval = reconnectInterval;
492
130
  this.useBigInt = useBigInt;
493
131
  this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED;
494
- this.timers = {};
495
132
  this.verifications = [];
496
133
  this.messageBuffer = "";
497
134
  // Check if the provided version is a valid version number.
498
135
  if (!(0, $24139611f53a54b8$export$2e2bcd8739ae039).versionRegexp.test(version)) // Throw an error since the version number was not valid.
499
136
  throw new Error(`Provided version string (${version}) is not a valid protocol version number.`);
500
- // Create an initial network socket.
501
- this.createSocket();
137
+ // If a hostname was provided..
138
+ if (typeof socketOrHostname === "string") // Use a web socket with default parameters.
139
+ this.socket = new (0, $dvphU$ElectrumWebSocket)(socketOrHostname);
140
+ else // Use the provided socket.
141
+ this.socket = socketOrHostname;
142
+ // Set up handlers for connection and disconnection.
143
+ this.socket.on("connect", this.onSocketConnect.bind(this));
144
+ this.socket.on("disconnect", this.onSocketDisconnect.bind(this));
145
+ // Set up handler for incoming data.
146
+ this.socket.on("data", this.parseMessageChunk.bind(this));
502
147
  // Handle visibility changes when run in a browser environment.
503
148
  if (typeof document !== "undefined") document.addEventListener("visibilitychange", this.handleVisibilityChange.bind(this));
504
149
  // Handle network connection changes when run in a browser environment.
@@ -507,36 +152,30 @@ var $db7c797e63383364$export$7516420eb880ab68;
507
152
  window.addEventListener("offline", this.handleNetworkChange.bind(this));
508
153
  }
509
154
  }
510
- /**
511
- * Returns a string for the host identifier for usage in debug messages.
512
- */ get hostIdentifier() {
513
- return `${this.host}:${this.port}`;
155
+ // Expose hostIdentifier from the socket.
156
+ get hostIdentifier() {
157
+ return this.socket.hostIdentifier;
514
158
  }
515
- /**
516
- * Create and configures a fresh socket and attaches all relevant listeners.
517
- */ createSocket() {
518
- if (this.scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP.Scheme || this.scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP_TLS.Scheme) // Initialize a new ElectrumTcpSocket
519
- this.socket = new (0, $0a4cf22b9d6c493c$export$22c0ca2c816c3e08)();
520
- else if (this.scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).WS.Scheme || this.scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).WSS.Scheme) // Initialize a new ElectrumWebSocket
521
- this.socket = new (0, $0a4cf22b9d6c493c$export$25b4633f61498e1)();
522
- else // Throw an error if an incorrect transport is specified
523
- throw new Error(`Provided transport (${this.scheme}) is not a valid ElectrumTransport`);
524
- // Set up handlers for connection and disconnection.
525
- this.socket.on("connect", this.onSocketConnect.bind(this));
526
- this.socket.on("disconnect", this.onSocketDisconnect.bind(this));
527
- // Set up handler for incoming data.
528
- this.socket.on("data", this.parseMessageChunk.bind(this));
159
+ // Expose host from the socket.
160
+ get host() {
161
+ return this.socket.host;
529
162
  }
530
- /**
531
- * Shuts down and destroys the current socket.
532
- */ destroySocket() {
533
- // Close the socket connection and destroy the socket.
534
- this.socket.disconnect();
163
+ // Expose port from the socket.
164
+ get port() {
165
+ return this.socket.port;
166
+ }
167
+ // Expose port from the socket.
168
+ get encrypted() {
169
+ return this.socket.encrypted;
170
+ }
171
+ // Expose timeout from the socket.
172
+ get timeout() {
173
+ return this.socket.timeout;
535
174
  }
536
175
  /**
537
176
  * Assembles incoming data into statements and hands them off to the message parser.
538
177
  *
539
- * @param {string} data data to append to the current message buffer, as a string.
178
+ * @param data - data to append to the current message buffer, as a string.
540
179
  *
541
180
  * @throws {SyntaxError} if the passed statement parts are not valid JSON.
542
181
  */ parseMessageChunk(data) {
@@ -601,7 +240,7 @@ var $db7c797e63383364$export$7516420eb880ab68;
601
240
  * part of the message is queued in the user memory
602
241
  */ ping() {
603
242
  // Write a log message.
604
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).ping(`Sending keep-alive ping to '${this.hostIdentifier}'`);
243
+ (0, $dvphU$electrumcashdebuglogs).ping(`Sending keep-alive ping to '${this.hostIdentifier}'`);
605
244
  // Craft a keep-alive message.
606
245
  const message = (0, $24139611f53a54b8$export$2e2bcd8739ae039).buildRequestObject("server.ping", [], "keepAlive");
607
246
  // Send the keep-alive message.
@@ -637,7 +276,7 @@ var $db7c797e63383364$export$7516420eb880ab68;
637
276
  // Define a function to wrap version negotiation as a callback.
638
277
  const versionNegotiator = ()=>{
639
278
  // Write a log message to show that we have started version negotiation.
640
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Requesting protocol version ${this.version} with '${this.hostIdentifier}'.`);
279
+ (0, $dvphU$electrumcashdebuglogs).network(`Requesting protocol version ${this.version} with '${this.hostIdentifier}'.`);
641
280
  // remove the one-time error handler since no error was detected.
642
281
  this.socket.removeListener("error", rejector);
643
282
  // Build a version negotiation message.
@@ -654,7 +293,7 @@ var $db7c797e63383364$export$7516420eb880ab68;
654
293
  // Declare an error message.
655
294
  const errorMessage = "unsupported protocol version.";
656
295
  // Log the error.
657
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);
296
+ (0, $dvphU$electrumcashdebuglogs).errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);
658
297
  // Reject the connection with false since version negotiation failed.
659
298
  reject(errorMessage);
660
299
  } else if (version.protocol !== this.version && `${version.protocol}.0` !== this.version && `${version.protocol}.0.0` !== this.version) {
@@ -663,12 +302,12 @@ var $db7c797e63383364$export$7516420eb880ab68;
663
302
  // Declare an error message.
664
303
  const errorMessage = `incompatible protocol version negotiated (${version.protocol} !== ${this.version}).`;
665
304
  // Log the error.
666
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);
305
+ (0, $dvphU$electrumcashdebuglogs).errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);
667
306
  // Reject the connection with false since version negotiation failed.
668
307
  reject(errorMessage);
669
308
  } else {
670
309
  // Write a log message.
671
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Negotiated protocol version ${version.protocol} with '${this.hostIdentifier}', powered by ${version.software}.`);
310
+ (0, $dvphU$electrumcashdebuglogs).network(`Negotiated protocol version ${version.protocol} with '${this.hostIdentifier}', powered by ${version.software}.`);
672
311
  // Set connection status to connected
673
312
  this.status = (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED;
674
313
  // Emit a connect event now that the connection is usable.
@@ -687,7 +326,7 @@ var $db7c797e63383364$export$7516420eb880ab68;
687
326
  // Set up handler for network errors.
688
327
  this.socket.on("error", this.onSocketError.bind(this));
689
328
  // Connect to the server.
690
- this.socket.connect(this.host, this.port, this.scheme, this.timeout);
329
+ this.socket.connect();
691
330
  };
692
331
  // Wait until connection is established and version negotiation succeeds.
693
332
  await new Promise(connectionResolver);
@@ -698,14 +337,13 @@ var $db7c797e63383364$export$7516420eb880ab68;
698
337
  // If a reconnect timer is set, remove it
699
338
  await this.clearReconnectTimer();
700
339
  // Write a log message.
701
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Trying to reconnect to '${this.hostIdentifier}'..`);
340
+ (0, $dvphU$electrumcashdebuglogs).network(`Trying to reconnect to '${this.hostIdentifier}'..`);
702
341
  // Set the status to reconnecting for more accurate log messages.
703
342
  this.status = (0, $db7c797e63383364$export$7516420eb880ab68).RECONNECTING;
704
343
  // Emit a connect event now that the connection is usable.
705
344
  this.emit("reconnecting");
706
- // Destroy and recreate the socket to get a clean slate.
707
- this.destroySocket();
708
- this.createSocket();
345
+ // Disconnect the underlying socket.
346
+ this.socket.disconnect();
709
347
  try {
710
348
  // Try to connect again.
711
349
  await this.connect();
@@ -717,30 +355,30 @@ var $db7c797e63383364$export$7516420eb880ab68;
717
355
  * Removes the current reconnect timer.
718
356
  */ clearReconnectTimer() {
719
357
  // If a reconnect timer is set, remove it
720
- if (this.timers.reconnect) clearTimeout(this.timers.reconnect);
358
+ if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
721
359
  // Reset the timer reference.
722
- this.timers.reconnect = undefined;
360
+ this.reconnectTimer = undefined;
723
361
  }
724
362
  /**
725
363
  * Removes the current keep-alive timer.
726
364
  */ clearKeepAliveTimer() {
727
365
  // If a keep-alive timer is set, remove it
728
- if (this.timers.keepAlive) clearTimeout(this.timers.keepAlive);
366
+ if (this.keepAliveTimer) clearTimeout(this.keepAliveTimer);
729
367
  // Reset the timer reference.
730
- this.timers.keepAlive = undefined;
368
+ this.keepAliveTimer = undefined;
731
369
  }
732
370
  /**
733
371
  * Initializes the keep alive timer loop.
734
372
  */ setupKeepAliveTimer() {
735
373
  // If the keep-alive timer loop is not currently set up..
736
- if (!this.timers.keepAlive) // Set a new keep-alive timer.
737
- this.timers.keepAlive = setTimeout(this.ping.bind(this), this.pingInterval);
374
+ if (!this.keepAliveTimer) // Set a new keep-alive timer.
375
+ this.keepAliveTimer = setTimeout(this.ping.bind(this), this.pingInterval);
738
376
  }
739
377
  /**
740
378
  * Tears down the current connection and removes all event listeners on disconnect.
741
379
  *
742
- * @param {boolean} force disconnect even if the connection has not been fully established yet.
743
- * @param {boolean} intentional update connection state if disconnect is intentional.
380
+ * @param force - disconnect even if the connection has not been fully established yet.
381
+ * @param intentional - update connection state if disconnect is intentional.
744
382
  *
745
383
  * @returns true if successfully disconnected, or false if there was no connection.
746
384
  */ async disconnect(force = false, intentional = true) {
@@ -761,8 +399,8 @@ var $db7c797e63383364$export$7516420eb880ab68;
761
399
  const disconnectResolver = (resolve)=>{
762
400
  // Resolve to true after the connection emits a disconnect
763
401
  this.once("disconnected", ()=>resolve(true));
764
- // Close the connection and destroy the socket.
765
- this.destroySocket();
402
+ // Close the connection on the socket level.
403
+ this.socket.disconnect();
766
404
  };
767
405
  // Return true to indicate that we disconnected.
768
406
  return new Promise(disconnectResolver);
@@ -810,7 +448,7 @@ var $db7c797e63383364$export$7516420eb880ab68;
810
448
  /**
811
449
  * Sends an arbitrary message to the server.
812
450
  *
813
- * @param {string} message json encoded request object to send to the server, as a string.
451
+ * @param message - json encoded request object to send to the server, as a string.
814
452
  *
815
453
  * @returns true if the message was fully flushed to the socket, false if part of the message
816
454
  * is queued in the user memory
@@ -841,7 +479,7 @@ var $db7c797e63383364$export$7516420eb880ab68;
841
479
  // Remove the current keep-alive timer if it exists.
842
480
  this.clearKeepAliveTimer();
843
481
  // Write a notification to the logs.
844
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Connection to '${this.hostIdentifier}' timed out.`);
482
+ (0, $dvphU$electrumcashdebuglogs).network(`Connection to '${this.hostIdentifier}' timed out.`);
845
483
  // Close the connection to avoid re-use.
846
484
  // NOTE: This initiates reconnection routines if the connection has not
847
485
  // been marked as intentionally disconnected.
@@ -878,18 +516,18 @@ var $db7c797e63383364$export$7516420eb880ab68;
878
516
  // Remove all event listeners
879
517
  this.removeAllListeners();
880
518
  // Write a log message.
881
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Disconnected from '${this.hostIdentifier}'.`);
519
+ (0, $dvphU$electrumcashdebuglogs).network(`Disconnected from '${this.hostIdentifier}'.`);
882
520
  } else {
883
521
  // If this is for an established connection..
884
522
  if (this.status === (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED) // Write a notification to the logs.
885
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(`Connection with '${this.hostIdentifier}' was closed, trying to reconnect in ${this.reconnectInterval / 1000} seconds.`);
523
+ (0, $dvphU$electrumcashdebuglogs).errors(`Connection with '${this.hostIdentifier}' was closed, trying to reconnect in ${this.reconnectInterval / 1000} seconds.`);
886
524
  // Mark the connection as disconnected for now..
887
525
  this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED;
888
526
  // Send a disconnect signal higher up the stack.
889
527
  this.emit("disconnected");
890
528
  // If we don't have a pending reconnection timer..
891
- if (!this.timers.reconnect) // Attempt to reconnect after one keep-alive duration.
892
- this.timers.reconnect = setTimeout(this.reconnect.bind(this), this.reconnectInterval);
529
+ if (!this.reconnectTimer) // Attempt to reconnect after one keep-alive duration.
530
+ this.reconnectTimer = setTimeout(this.reconnect.bind(this), this.reconnectInterval);
893
531
  }
894
532
  }
895
533
  /**
@@ -903,17 +541,17 @@ var $db7c797e63383364$export$7516420eb880ab68;
903
541
  return;
904
542
  // If the DNS lookup failed.
905
543
  if (error.code === "EAI_AGAIN") {
906
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(`Failed to look up DNS records for '${this.host}'.`);
544
+ (0, $dvphU$electrumcashdebuglogs).errors(`Failed to look up DNS records for '${this.host}'.`);
907
545
  return;
908
546
  }
909
547
  // If the connection timed out..
910
548
  if (error.code === "ETIMEDOUT") {
911
549
  // Log the provided timeout message.
912
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(error.message);
550
+ (0, $dvphU$electrumcashdebuglogs).errors(error.message);
913
551
  return;
914
552
  }
915
553
  // Log unknown error
916
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(`Unknown network error ('${this.hostIdentifier}'): `, error);
554
+ (0, $dvphU$electrumcashdebuglogs).errors(`Unknown network error ('${this.hostIdentifier}'): `, error);
917
555
  }
918
556
  }
919
557
  var // Export the connection.
@@ -958,26 +596,20 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
958
596
  /**
959
597
  * Initializes an Electrum client.
960
598
  *
961
- * @param {string} application your application name, used to identify to the electrum host.
962
- * @param {string} version protocol version to use with the host.
963
- * @param {string} host fully qualified domain name or IP number of the host.
964
- * @param {number} port the TCP network port of the host.
965
- * @param {TransportScheme} scheme the transport scheme to use for connection
966
- * @param {number} timeout how long network delays we will wait for before taking action, in milliseconds.
967
- * @param {number} pingInterval the time between sending pings to the electrum host, in milliseconds.
968
- * @param {number} reconnectInterval the time between reconnection attempts to the electrum host, in milliseconds.
969
- * @param {boolean} useBigInt whether to use bigint for numbers in json response.
599
+ * @param application - your application name, used to identify to the electrum host.
600
+ * @param version - protocol version to use with the host.
601
+ * @param socketOrHostname - socket fully qualified domain name or IP number of the host
602
+ * @param pingInterval - the time between sending pings to the electrum host, in milliseconds.
603
+ * @param reconnectInterval - the time between reconnection attempts to the electrum host, in milliseconds.
604
+ * @param useBigInt - whether to use bigint for numbers in json response.
970
605
  *
971
606
  * @throws {Error} if `version` is not a valid version string.
972
- */ constructor(application, version, host, port = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).PORT, scheme = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).TRANSPORT_SCHEME, timeout = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).TIMEOUT, pingInterval = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).PING_INTERVAL, reconnectInterval = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).RECONNECT, useBigInt = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).USE_BIG_INT){
607
+ */ constructor(application, version, socketOrHostname, pingInterval = (0, $d801b1f9b7fc3074$export$a3a6b8a974871191), reconnectInterval = (0, $d801b1f9b7fc3074$export$b2115084b892a79d), useBigInt = (0, $d801b1f9b7fc3074$export$788e8376894ebb88)){
973
608
  // Initialize the event emitter.
974
609
  super();
975
610
  this.application = application;
976
611
  this.version = version;
977
- this.host = host;
978
- this.port = port;
979
- this.scheme = scheme;
980
- this.timeout = timeout;
612
+ this.socketOrHostname = socketOrHostname;
981
613
  this.pingInterval = pingInterval;
982
614
  this.reconnectInterval = reconnectInterval;
983
615
  this.useBigInt = useBigInt;
@@ -987,7 +619,27 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
987
619
  this.requestResolvers = {};
988
620
  this.connectionLock = new (0, $dvphU$Mutex)();
989
621
  // Set up a connection to an electrum server.
990
- this.connection = new (0, $ff134c9a9e1f7361$export$2e2bcd8739ae039)(application, version, host, port, scheme, timeout, pingInterval, reconnectInterval, useBigInt);
622
+ this.connection = new (0, $ff134c9a9e1f7361$export$2e2bcd8739ae039)(application, version, socketOrHostname, pingInterval, reconnectInterval, useBigInt);
623
+ }
624
+ // Expose hostIdentifier from the connection.
625
+ get hostIdentifier() {
626
+ return this.connection.hostIdentifier;
627
+ }
628
+ // Expose host from the connection.
629
+ get host() {
630
+ return this.connection.host;
631
+ }
632
+ // Expose port from the connection.
633
+ get port() {
634
+ return this.connection.port;
635
+ }
636
+ // Expose port from the connection.
637
+ get encrypted() {
638
+ return this.connection.encrypted;
639
+ }
640
+ // Expose timeout from the connection.
641
+ get timeout() {
642
+ return this.connection.timeout;
991
643
  }
992
644
  /**
993
645
  * Connects to the remote server.
@@ -1023,8 +675,8 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
1023
675
  /**
1024
676
  * Disconnects from the remote server and removes all event listeners/subscriptions and open requests.
1025
677
  *
1026
- * @param {boolean} force disconnect even if the connection has not been fully established yet.
1027
- * @param {boolean} retainSubscriptions retain subscription data so they will be restored on reconnection.
678
+ * @param force - disconnect even if the connection has not been fully established yet.
679
+ * @param retainSubscriptions - retain subscription data so they will be restored on reconnection.
1028
680
  *
1029
681
  * @returns true if successfully disconnected, or false if there was no connection.
1030
682
  */ async disconnect(force = false, retainSubscriptions = false) {
@@ -1040,15 +692,15 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
1040
692
  /**
1041
693
  * Calls a method on the remote server with the supplied parameters.
1042
694
  *
1043
- * @param {string} method name of the method to call.
1044
- * @param {...string} parameters one or more parameters for the method.
695
+ * @param method - name of the method to call.
696
+ * @param parameters - one or more parameters for the method.
1045
697
  *
1046
698
  * @throws {Error} if the client is disconnected.
1047
699
  * @returns a promise that resolves with the result of the method or an Error.
1048
700
  */ async request(method, ...parameters) {
1049
701
  // If we are not connected to a server..
1050
702
  if (this.connection.status !== (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED) // Reject the request with a disconnected error message.
1051
- throw new Error(`Unable to send request to a disconnected server '${this.connection.host}'.`);
703
+ throw new Error(`Unable to send request to a disconnected server '${this.host}'.`);
1052
704
  // Increase the request ID by one.
1053
705
  this.requestId += 1;
1054
706
  // Store a copy of the request id.
@@ -1069,7 +721,7 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
1069
721
  this.connection.send(message);
1070
722
  };
1071
723
  // Write a log message.
1072
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Sending request '${method}' to '${this.connection.host}'`);
724
+ (0, $dvphU$electrumcashdebuglogs).network(`Sending request '${method}' to '${this.host}'`);
1073
725
  // return a promise to deliver results later.
1074
726
  return new Promise(requestResolver);
1075
727
  }
@@ -1078,8 +730,8 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
1078
730
  *
1079
731
  * @note the response for the subscription request is issued as a notification event.
1080
732
  *
1081
- * @param {string} method one of the subscribable methods the server supports.
1082
- * @param {...string} parameters one or more parameters for the method.
733
+ * @param method - one of the subscribable methods the server supports.
734
+ * @param parameters - one or more parameters for the method.
1083
735
  *
1084
736
  * @throws {Error} if the client is disconnected.
1085
737
  * @returns a promise resolving when the subscription is established.
@@ -1108,15 +760,15 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
1108
760
  * Unsubscribes to the method at the server and removes any callback functions
1109
761
  * when there are no more subscriptions for the method.
1110
762
  *
1111
- * @param {string} method a previously subscribed to method.
1112
- * @param {...string} parameters one or more parameters for the method.
763
+ * @param method - a previously subscribed to method.
764
+ * @param parameters - one or more parameters for the method.
1113
765
  *
1114
766
  * @throws {Error} if no subscriptions exist for the combination of the provided `method` and `parameters.
1115
767
  * @throws {Error} if the client is disconnected.
1116
768
  * @returns a promise resolving when the subscription is removed.
1117
769
  */ async unsubscribe(method, ...parameters) {
1118
770
  // Throw an error if the client is disconnected.
1119
- if (this.connection.status !== (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED) throw new Error(`Unable to send unsubscribe request to a disconnected server '${this.connection.host}'.`);
771
+ if (this.connection.status !== (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED) throw new Error(`Unable to send unsubscribe request to a disconnected server '${this.host}'.`);
1120
772
  // If this method has no subscriptions..
1121
773
  if (!this.subscriptionMethods[method]) // Reject this promise with an explanation.
1122
774
  throw new Error(`Cannot unsubscribe from '${method}' since the method has no subscriptions.`);
@@ -1131,7 +783,7 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
1131
783
  // NOTE: As a convenience we allow users to define the method as the subscribe or unsubscribe version.
1132
784
  await this.request(method.replace(".subscribe", ".unsubscribe"), ...parameters);
1133
785
  // Write a log message.
1134
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).client(`Unsubscribed from '${String(method)}' for the '${subscriptionParameters}' parameters.`);
786
+ (0, $dvphU$electrumcashdebuglogs).client(`Unsubscribed from '${String(method)}' for the '${subscriptionParameters}' parameters.`);
1135
787
  }
1136
788
  /**
1137
789
  * Restores existing subscriptions without updating status or triggering manual callbacks.
@@ -1143,7 +795,7 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
1143
795
  * @ignore
1144
796
  */ async resubscribeOnConnect() {
1145
797
  // Write a log message.
1146
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).client(`Connected to '${this.connection.hostIdentifier}'.`);
798
+ (0, $dvphU$electrumcashdebuglogs).client(`Connected to '${this.hostIdentifier}'.`);
1147
799
  // Synchronize with the underlying connection status.
1148
800
  this.handleConnectionStatusChanges("connected");
1149
801
  // Initialize an empty list of resubscription promises.
@@ -1161,12 +813,12 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
1161
813
  await Promise.all(resubscriptionPromises);
1162
814
  }
1163
815
  // Write a log message if there was any subscriptions to restore.
1164
- if (resubscriptionPromises.length > 0) (0, $623a31cc1663a627$export$2e2bcd8739ae039).client(`Restored ${resubscriptionPromises.length} previous subscriptions for '${this.connection.hostIdentifier}'`);
816
+ if (resubscriptionPromises.length > 0) (0, $dvphU$electrumcashdebuglogs).client(`Restored ${resubscriptionPromises.length} previous subscriptions for '${this.hostIdentifier}'`);
1165
817
  }
1166
818
  /**
1167
819
  * Parser messages from the remote server to resolve request promises and emit subscription events.
1168
820
  *
1169
- * @param {RPCNotification | RPCResponse} message the response message
821
+ * @param message - the response message
1170
822
  *
1171
823
  * @throws {Error} if the message ID does not match an existing request.
1172
824
  * @ignore
@@ -1174,7 +826,7 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
1174
826
  // If the received message is a notification, we forward it to all event listeners
1175
827
  if ((0, $abcb763a48577a1e$export$280de919a0cf6928)(message)) {
1176
828
  // Write a log message.
1177
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).client(`Received notification for '${message.method}' from '${this.connection.host}'`);
829
+ (0, $dvphU$electrumcashdebuglogs).client(`Received notification for '${message.method}' from '${this.host}'`);
1178
830
  // Forward the message content to all event listeners.
1179
831
  this.emit("notification", message);
1180
832
  // Try to update the chain height.
@@ -1190,7 +842,7 @@ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
1190
842
  // If we do not have a request resolver for this response message..
1191
843
  if (!requestResolver) {
1192
844
  // Log that a message was ignored since the request has already been rejected.
1193
- (0, $623a31cc1663a627$export$2e2bcd8739ae039).warning(`Ignoring response #${message.id} as the request has already been rejected.`);
845
+ (0, $dvphU$electrumcashdebuglogs).warning(`Ignoring response #${message.id} as the request has already been rejected.`);
1194
846
  // Return as this has now been fully handled.
1195
847
  return;
1196
848
  }
@@ -1286,5 +938,5 @@ $558b46d3f899ced5$export$2e2bcd8739ae039 = $558b46d3f899ced5$var$ElectrumClient;
1286
938
 
1287
939
 
1288
940
 
1289
- export {$558b46d3f899ced5$export$2e2bcd8739ae039 as ElectrumClient, $e83d2e7688025acd$export$e1f38ab2b4ebdde6 as isVersionRejected, $e83d2e7688025acd$export$9598f0c76aa41d73 as isVersionNegotiated, $d801b1f9b7fc3074$export$d048df559e6d3842 as ElectrumTransport, $d801b1f9b7fc3074$export$f019be48b3aacb1a as DefaultParameters, $db7c797e63383364$export$c4f81c6d30ca200f as ClientState, $db7c797e63383364$export$7516420eb880ab68 as ConnectionStatus};
941
+ export {$558b46d3f899ced5$export$2e2bcd8739ae039 as ElectrumClient, $e83d2e7688025acd$export$e1f38ab2b4ebdde6 as isVersionRejected, $e83d2e7688025acd$export$9598f0c76aa41d73 as isVersionNegotiated, $d801b1f9b7fc3074$export$a3a6b8a974871191 as DEFAULT_PING_INTERVAL, $d801b1f9b7fc3074$export$b2115084b892a79d as DEFAULT_RECONNECT_INTERVAL, $d801b1f9b7fc3074$export$788e8376894ebb88 as DEFAULT_BIG_INTEGERS, $db7c797e63383364$export$c4f81c6d30ca200f as ClientState, $db7c797e63383364$export$7516420eb880ab68 as ConnectionStatus};
1290
942
  //# sourceMappingURL=index.mjs.map