evernode-js-client 0.6.15 → 0.6.16
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +46 -16
- package/package.json +1 -1
- package/postinstall.js/index.js +1 -1
package/index.js
CHANGED
@@ -12443,6 +12443,16 @@ class BaseEvernodeClient {
|
|
12443
12443
|
fullHostList = fullHostList.concat(hosts);
|
12444
12444
|
}
|
12445
12445
|
|
12446
|
+
const curMomentStartIdx = await this.getMomentStartIndex();
|
12447
|
+
await Promise.all((fullHostList).map(async host => {
|
12448
|
+
const hostAcc = new XrplAccount(host.address, null, { xrplApi: this.xrplApi });
|
12449
|
+
host.domain = await hostAcc.getDomain();
|
12450
|
+
host.active = (host.lastHeartbeatIndex > (this.config.hostHeartbeatFreq * this.config.momentSize) ?
|
12451
|
+
(host.lastHeartbeatIndex >= (curMomentStartIdx - (this.config.hostHeartbeatFreq * this.config.momentSize))) :
|
12452
|
+
(host.lastHeartbeatIndex > 0));
|
12453
|
+
return host;
|
12454
|
+
}));
|
12455
|
+
|
12446
12456
|
return fullHostList;
|
12447
12457
|
}
|
12448
12458
|
|
@@ -17141,33 +17151,49 @@ class XrplApi {
|
|
17141
17151
|
#client;
|
17142
17152
|
#events = new EventEmitter();
|
17143
17153
|
#addressSubscriptions = [];
|
17144
|
-
#
|
17154
|
+
#initialConnectCalled = false;
|
17155
|
+
#isPermanentlyDisconnected = false;
|
17156
|
+
#autoReconnect;
|
17145
17157
|
|
17146
17158
|
constructor(rippledServer = null, options = {}) {
|
17147
|
-
|
17148
17159
|
this.#rippledServer = rippledServer || DefaultValues.rippledServer;
|
17149
17160
|
this.#initXrplClient(options.xrplClientOptions);
|
17161
|
+
this.#autoReconnect = options.autoReconnect ?? true;
|
17150
17162
|
}
|
17151
17163
|
|
17152
17164
|
async #initXrplClient(xrplClientOptions = {}) {
|
17153
|
-
|
17154
17165
|
if (this.#client) { // If the client already exists, clean it up.
|
17155
17166
|
this.#client.removeAllListeners(); // Remove existing event listeners to avoid them getting called from the old client object.
|
17156
17167
|
await this.#client.disconnect();
|
17157
17168
|
this.#client = null;
|
17158
17169
|
}
|
17159
17170
|
|
17160
|
-
|
17171
|
+
try {
|
17172
|
+
this.#client = new xrpl.Client(this.#rippledServer, xrplClientOptions);
|
17173
|
+
}
|
17174
|
+
catch (e) {
|
17175
|
+
console.log("Error occurred in Client initiation:", e)
|
17176
|
+
}
|
17161
17177
|
|
17162
17178
|
this.#client.on('error', (errorCode, errorMessage) => {
|
17163
17179
|
console.log(errorCode + ': ' + errorMessage);
|
17164
17180
|
});
|
17165
17181
|
|
17182
|
+
this.#client.on('reconnect', () => {
|
17183
|
+
console.log("Reconnecting....");
|
17184
|
+
});
|
17185
|
+
|
17166
17186
|
this.#client.on('disconnected', (code) => {
|
17167
|
-
|
17187
|
+
this.#autoReconnect && console.log(" : ", this.#autoReconnect)
|
17188
|
+
if (this.#autoReconnect && !this.#isPermanentlyDisconnected) {
|
17168
17189
|
console.log(`Connection failure for ${this.#rippledServer} (code:${code})`);
|
17169
|
-
console.log("
|
17170
|
-
|
17190
|
+
console.log("Re-initializing xrpl client.");
|
17191
|
+
try {
|
17192
|
+
this.#initXrplClient().then(() => this.#connectXrplClient(true));
|
17193
|
+
}
|
17194
|
+
catch (e) {
|
17195
|
+
console.log("Error occurred while re-initializing", e)
|
17196
|
+
}
|
17171
17197
|
}
|
17172
17198
|
});
|
17173
17199
|
|
@@ -17217,6 +17243,7 @@ class XrplApi {
|
|
17217
17243
|
}
|
17218
17244
|
}
|
17219
17245
|
}
|
17246
|
+
|
17220
17247
|
});
|
17221
17248
|
}
|
17222
17249
|
|
@@ -17224,14 +17251,15 @@ class XrplApi {
|
|
17224
17251
|
|
17225
17252
|
if (reconnect) {
|
17226
17253
|
let attempts = 0;
|
17227
|
-
while (this.#
|
17254
|
+
while (!this.#isPermanentlyDisconnected) { // Keep attempting until consumer calls disconnect() manually.
|
17228
17255
|
console.log(`Reconnection attempt ${++attempts}`);
|
17229
17256
|
try {
|
17230
17257
|
await this.#client.connect();
|
17231
17258
|
break;
|
17232
17259
|
}
|
17233
|
-
catch {
|
17234
|
-
|
17260
|
+
catch (e) {
|
17261
|
+
console.log("Error occurred while re-connecting", e)
|
17262
|
+
if (!this.#isPermanentlyDisconnected) {
|
17235
17263
|
const delaySec = 2 * attempts; // Retry with backoff delay.
|
17236
17264
|
console.log(`Attempt ${attempts} failed. Retrying in ${delaySec}s...`);
|
17237
17265
|
await new Promise(resolve => setTimeout(resolve, delaySec * 1000));
|
@@ -17246,7 +17274,7 @@ class XrplApi {
|
|
17246
17274
|
|
17247
17275
|
// After connection established, check again whether maintainConnections has become false.
|
17248
17276
|
// This is in case the consumer has called disconnect() while connection is being established.
|
17249
|
-
if (this.#
|
17277
|
+
if (!this.#isPermanentlyDisconnected) {
|
17250
17278
|
this.ledgerIndex = await this.#client.getLedgerIndex();
|
17251
17279
|
this.#subscribeToStream('ledger');
|
17252
17280
|
|
@@ -17295,15 +17323,17 @@ class XrplApi {
|
|
17295
17323
|
}
|
17296
17324
|
|
17297
17325
|
async connect() {
|
17298
|
-
if (this.#
|
17299
|
-
return
|
17300
|
-
|
17301
|
-
this.#
|
17326
|
+
if (this.#initialConnectCalled) {
|
17327
|
+
return
|
17328
|
+
}
|
17329
|
+
this.#initialConnectCalled = true
|
17330
|
+
this.#isPermanentlyDisconnected = false
|
17302
17331
|
await this.#connectXrplClient();
|
17303
17332
|
}
|
17304
17333
|
|
17305
17334
|
async disconnect() {
|
17306
|
-
this.#
|
17335
|
+
this.#initialConnectCalled = false;
|
17336
|
+
this.#isPermanentlyDisconnected = true
|
17307
17337
|
|
17308
17338
|
if (this.#client.isConnected()) {
|
17309
17339
|
await this.#client.disconnect().catch(console.error);
|