evernode-js-client 0.6.34 → 0.6.36

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -9149,7 +9149,7 @@ module.exports = { mask, unmask };
9149
9149
 
9150
9150
 
9151
9151
  try {
9152
- module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi1.node");
9152
+ module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi.node");
9153
9153
  } catch (e) {
9154
9154
  module.exports = __nccwpck_require__(2567);
9155
9155
  }
@@ -33340,7 +33340,7 @@ module.exports = isValidUTF8;
33340
33340
 
33341
33341
 
33342
33342
  try {
33343
- module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi.node");
33343
+ module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi1.node");
33344
33344
  } catch (e) {
33345
33345
  module.exports = __nccwpck_require__(9372);
33346
33346
  }
@@ -53169,29 +53169,6 @@ class RegistryClient extends BaseEvernodeClient {
53169
53169
  super(options.registryAddress, null, Object.values(RegistryEvents), false, options);
53170
53170
  }
53171
53171
 
53172
- /**
53173
- * Gets all the active hosts registered in Evernode without paginating.
53174
- * @returns The list of active hosts.
53175
- */
53176
- async getActiveHosts() {
53177
- let fullHostList = [];
53178
- const hosts = await this.getHosts();
53179
- if (hosts.nextPageToken) {
53180
- let currentPageToken = hosts.nextPageToken;
53181
- let nextHosts = null;
53182
- fullHostList = fullHostList.concat(hosts.data);
53183
- while (currentPageToken) {
53184
- nextHosts = await this.getHosts(null, null, currentPageToken);
53185
- fullHostList = fullHostList.concat(nextHosts.nextPageToken ? nextHosts.data : nextHosts);
53186
- currentPageToken = nextHosts.nextPageToken;
53187
- }
53188
- } else {
53189
- fullHostList = fullHostList.concat(hosts);
53190
- }
53191
- // Filter only active hosts.
53192
- return fullHostList.filter(h => h.active);
53193
- }
53194
-
53195
53172
  /**
53196
53173
  * Gets all the active hosts registered in ledger.
53197
53174
  * @returns The list of active hosts.
@@ -53861,6 +53838,12 @@ class HostClient extends BaseEvernodeClient {
53861
53838
  * @returns Transaction result.
53862
53839
  */
53863
53840
  async heartbeat(voteInfo = {}, options = {}) {
53841
+ let unofferedLeases = await this.getUnofferedLeases();
53842
+ if (unofferedLeases.length > 0) {
53843
+ console.log("Unoffered leases detected. Heartbeat was not sent.");
53844
+ return;
53845
+ }
53846
+
53864
53847
  let data;
53865
53848
  // Prepare voteInfo
53866
53849
  if (Object.keys(voteInfo).length > 1) {
@@ -57241,7 +57224,7 @@ class XrplApi {
57241
57224
  }
57242
57225
 
57243
57226
  async #acquireClient() {
57244
- while (this.#isClientAcquired || this.#isConnectionAcquired) {
57227
+ while (!(this.#isPrimaryServerConnected || this.#isFallbackServerConnected) && this.#isClientAcquired) {
57245
57228
  await new Promise((resolve) => setTimeout(resolve, 100));
57246
57229
  }
57247
57230
  this.#isClientAcquired = true;
@@ -57252,7 +57235,7 @@ class XrplApi {
57252
57235
  }
57253
57236
 
57254
57237
  async #acquireConnection() {
57255
- while (this.#isClientAcquired) {
57238
+ while (this.#isConnectionAcquired) {
57256
57239
  await new Promise((resolve) => setTimeout(resolve, 100));
57257
57240
  }
57258
57241
  this.#isConnectionAcquired = true;
@@ -57263,16 +57246,15 @@ class XrplApi {
57263
57246
  }
57264
57247
 
57265
57248
  async #setXrplClient(client) {
57266
- await this.#acquireClient();
57267
57249
  try {
57268
- if (this.#client) // Clear all listeners if there's an already created client.
57250
+ if (this.#client) { // Clear all listeners if there's an already created client.
57269
57251
  await this.#client.removeAllListeners();
57252
+ await this.#client.disconnect();
57253
+ }
57270
57254
 
57271
57255
  this.#client = client;
57272
- this.#releaseClient();
57273
57256
  }
57274
57257
  catch (e) {
57275
- this.#releaseClient();
57276
57258
  console.log("Error occurred in Client initiation:", e)
57277
57259
  }
57278
57260
  }
@@ -57372,9 +57354,14 @@ class XrplApi {
57372
57354
  }
57373
57355
 
57374
57356
  async #attemptFallbackServerReconnect(maxRounds, attemptsPerServer = 3) {
57357
+ if (!this.#fallbackServers || this.#fallbackServers?.length == 0)
57358
+ return;
57359
+
57360
+ await this.#acquireClient();
57361
+
57375
57362
  const fallbackServers = this.#fallbackServers;
57376
57363
  let round = 0;
57377
- while (fallbackServers?.length > 0 && !this.#isPermanentlyDisconnected && !this.#isPrimaryServerConnected && !this.#isFallbackServerConnected && (!maxRounds || round < maxRounds)) { // Keep attempting until consumer calls disconnect() manually or if the primary server is disconnected.
57364
+ while (!this.#isPermanentlyDisconnected && !this.#isPrimaryServerConnected && !this.#isFallbackServerConnected && (!maxRounds || round < maxRounds)) { // Keep attempting until consumer calls disconnect() manually or if the primary server is disconnected.
57378
57365
  ++round;
57379
57366
  serverIterator:
57380
57367
  for (let serverIndex in fallbackServers) {
@@ -57384,8 +57371,8 @@ class XrplApi {
57384
57371
  break serverIterator;
57385
57372
  }
57386
57373
  ++attempt;
57374
+ const client = new xrpl.Client(server, this.#xrplClientOptions);
57387
57375
  try {
57388
- const client = new xrpl.Client(server, this.#xrplClientOptions);
57389
57376
  if (!this.#isPrimaryServerConnected) {
57390
57377
  await this.#handleClientConnect(client);
57391
57378
  this.#isFallbackServerConnected = true;
@@ -57393,63 +57380,86 @@ class XrplApi {
57393
57380
  break serverIterator;
57394
57381
  }
57395
57382
  catch (e) {
57396
- console.log(`Error occurred while connecting to fallback server ${server}`, e)
57383
+ this.#releaseClient();
57384
+ console.log(`Error occurred while connecting to fallback server ${server}`);
57385
+ await new Promise(resolve => setTimeout(resolve, 1000));
57386
+ if (client.isConnected()) {
57387
+ console.log('Connection closure already handled');
57388
+ await client.disconnect();
57389
+ }
57390
+
57397
57391
  if (!this.#isPermanentlyDisconnected) {
57398
57392
  if (!maxRounds || round < maxRounds)
57399
57393
  console.log(`Fallback server ${server} connection attempt ${attempt} failed. Retrying in ${2 * round}s...`);
57400
57394
  else
57401
- throw `Fallback server ${server} connection max attempts failed.`;
57395
+ return { error: `Fallback server ${server} connection max attempts failed.`, exception: e };
57402
57396
  await new Promise(resolve => setTimeout(resolve, 2 * round * 1000));
57403
57397
  }
57404
57398
  }
57405
57399
  }
57406
57400
  }
57407
-
57408
57401
  }
57402
+
57403
+ return {};
57409
57404
  }
57410
57405
 
57411
57406
  async #attemptPrimaryServerReconnect(maxAttempts = null) {
57407
+ await this.#acquireClient();
57408
+
57412
57409
  let attempt = 0;
57413
- while (!this.#isPermanentlyDisconnected && !this.#isPrimaryServerConnected) { // Keep attempting until consumer calls disconnect() manually.
57410
+ while (!this.#isPermanentlyDisconnected && !this.#isPrimaryServerConnected && !this.#isFallbackServerConnected) { // Keep attempting until consumer calls disconnect() manually.
57414
57411
  ++attempt;
57412
+ const client = new xrpl.Client(this.#primaryServer, this.#xrplClientOptions);
57415
57413
  try {
57416
- const client = new xrpl.Client(this.#primaryServer, this.#xrplClientOptions);
57417
57414
  await this.#handleClientConnect(client);
57418
- this.#isFallbackServerConnected = false;
57419
57415
  this.#isPrimaryServerConnected = true;
57420
57416
  break;
57421
57417
  }
57422
57418
  catch (e) {
57423
- console.log("Error occurred while re-connecting to the primary server", e)
57419
+ this.#releaseClient();
57420
+ console.log("Error occurred while re-connecting to the primary server")
57421
+ await new Promise(resolve => setTimeout(resolve, 1000));
57422
+ if (client.isConnected()) {
57423
+ console.log('Connection closure already handled');
57424
+ await client.disconnect();
57425
+ }
57426
+
57424
57427
  if (!this.#isPermanentlyDisconnected) {
57425
57428
  const delaySec = 2 * attempt; // Retry with backoff delay.
57426
57429
  if (!maxAttempts || attempt < maxAttempts)
57427
57430
  console.log(`Primary server ${this.#primaryServer} attempt ${attempt} failed. Retrying in ${delaySec}s...`);
57428
57431
  else
57429
- throw `Primary server ${this.#primaryServer} connection max attempts failed.`;
57432
+ return { error: `Primary server ${this.#primaryServer} connection max attempts failed.`, exception: e };
57430
57433
  await new Promise(resolve => setTimeout(resolve, delaySec * 1000));
57431
57434
  }
57432
57435
  }
57433
57436
  }
57437
+
57438
+ return {};
57434
57439
  }
57435
57440
 
57436
57441
  async #connectXrplClient(reconnect = false) {
57442
+ let res = [];
57437
57443
  if (reconnect) {
57438
57444
  if (this.#primaryServer) {
57439
- Promise.all([this.#attemptFallbackServerReconnect(), this.#attemptPrimaryServerReconnect()]);
57445
+ res = await Promise.all([this.#attemptPrimaryServerReconnect(), this.#attemptFallbackServerReconnect()]);
57440
57446
  } else {
57441
- this.#attemptFallbackServerReconnect();
57447
+ res = [await this.#attemptFallbackServerReconnect()];
57442
57448
  }
57443
57449
  }
57444
57450
  else {
57445
57451
  if (this.#primaryServer) {
57446
- Promise.all([this.#attemptFallbackServerReconnect(1, 1), this.#attemptPrimaryServerReconnect(1)]);
57452
+ res = await Promise.all([this.#attemptPrimaryServerReconnect(1), this.#attemptFallbackServerReconnect(1, 1)]);
57447
57453
  } else {
57448
- this.#attemptFallbackServerReconnect(1, 1);
57454
+ res = [await this.#attemptFallbackServerReconnect(1, 1)];
57449
57455
  }
57450
57456
  }
57451
57457
 
57458
+ if (res.filter(r => r && !r.error).length == 0)
57459
+ throw res.filter(r => r && r.error).map(r => r.error);
57460
+
57452
57461
  await this.#waitForConnection();
57462
+ this.#releaseClient();
57453
57463
 
57454
57464
  // After connection established, check again whether maintainConnections has become false.
57455
57465
  // This is in case the consumer has called disconnect() while connection is being established.
@@ -57524,24 +57534,27 @@ class XrplApi {
57524
57534
 
57525
57535
  async connect() {
57526
57536
  this.#isPermanentlyDisconnected = false;
57527
- await this.#connectXrplClient();
57537
+
57538
+ if (!this.#client || !this.#client.isConnected()) {
57539
+ await this.#connectXrplClient();
57540
+ }
57528
57541
  const definitions = await this.#handleClientRequest({ command: 'server_definitions' })
57529
57542
  this.xrplHelper = new XrplHelpers(definitions.result);
57530
57543
  }
57531
57544
 
57532
57545
  async disconnect() {
57533
- await this.#acquireClient();
57546
+ await this.#acquireConnection();
57534
57547
 
57535
57548
  try {
57536
57549
  this.#isPermanentlyDisconnected = true;
57537
57550
 
57538
- if (this.#client.isConnected()) {
57551
+ if (this.#client && this.#client.isConnected()) {
57539
57552
  await this.#client.disconnect().catch(console.error);
57540
57553
  }
57541
- this.#releaseClient();
57554
+ this.#releaseConnection();
57542
57555
  }
57543
57556
  catch (e) {
57544
- this.#releaseClient();
57557
+ this.#releaseConnection();
57545
57558
  throw e;
57546
57559
  }
57547
57560
  }
@@ -57746,7 +57759,6 @@ class XrplApi {
57746
57759
  return { ...txResult, ...(hookExecRes ? { hookExecutionResult: hookExecRes } : {}) };
57747
57760
  else
57748
57761
  throw { ...txResult, ...(hookExecRes ? { hookExecutionResult: hookExecRes } : {}) };
57749
-
57750
57762
  }
57751
57763
 
57752
57764
  /**
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  ],
7
7
  "homepage": "https://github.com/HotPocketDev/evernode-js-client",
8
8
  "license": "SEE LICENSE IN https://raw.githubusercontent.com/EvernodeXRPL/evernode-resources/main/license/evernode-license.pdf",
9
- "version": "0.6.34",
9
+ "version": "0.6.36",
10
10
  "dependencies": {
11
11
  "elliptic": "6.5.4",
12
12
  "libsodium-wrappers": "0.7.10",
Binary file
Binary file