evernode-js-client 0.6.41 → 0.6.43

Sign up to get free protection for your applications and to get access to all the features.
Binary file
package/index.js CHANGED
@@ -9189,7 +9189,7 @@ module.exports = { mask, unmask };
9189
9189
 
9190
9190
 
9191
9191
  try {
9192
- module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi1.node");
9192
+ module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi.node");
9193
9193
  } catch (e) {
9194
9194
  module.exports = __nccwpck_require__(2567);
9195
9195
  }
@@ -38321,7 +38321,7 @@ module.exports = isValidUTF8;
38321
38321
 
38322
38322
 
38323
38323
  try {
38324
- module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi.node");
38324
+ module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi1.node");
38325
38325
  } catch (e) {
38326
38326
  module.exports = __nccwpck_require__(9372);
38327
38327
  }
@@ -60240,7 +60240,7 @@ class BaseEvernodeClient {
60240
60240
  * Get the hosts registered in Evernode.
60241
60241
  * @returns The list of hosts.
60242
60242
  */
60243
- async getAllHostsFromLedger(skipGetDomain = false) {
60243
+ async getAllHostsFromLedger(getDomain = true) {
60244
60244
  const states = await this.getHookStates();
60245
60245
  let hosts = {};
60246
60246
 
@@ -60260,7 +60260,7 @@ class BaseEvernodeClient {
60260
60260
  const curMomentStartIdx = await this.getMomentStartIndex();
60261
60261
  await Promise.all((hostList).map(async host => {
60262
60262
  const hostAcc = new XrplAccount(host.address, null, { xrplApi: this.xrplApi });
60263
- if (!skipGetDomain) {
60263
+ if (getDomain) {
60264
60264
  host.domain = await hostAcc.getDomain();
60265
60265
  }
60266
60266
  host.active = (host.lastHeartbeatIndex > (this.config.hostHeartbeatFreq * this.config.momentSize) ?
@@ -65022,7 +65022,7 @@ class XrplApi {
65022
65022
  }
65023
65023
 
65024
65024
  async #acquireClient() {
65025
- while (!(this.#isPrimaryServerConnected || this.#isFallbackServerConnected) && this.#isClientAcquired) {
65025
+ while (!(this.#isPrimaryServerConnected || this.#isFallbackServerConnected) && this.#isClientAcquired || this.#isConnectionAcquired) {
65026
65026
  await new Promise((resolve) => setTimeout(resolve, 100));
65027
65027
  }
65028
65028
  this.#isClientAcquired = true;
@@ -65033,7 +65033,7 @@ class XrplApi {
65033
65033
  }
65034
65034
 
65035
65035
  async #acquireConnection() {
65036
- while (this.#isConnectionAcquired) {
65036
+ while (this.#isClientAcquired) {
65037
65037
  await new Promise((resolve) => setTimeout(resolve, 100));
65038
65038
  }
65039
65039
  this.#isConnectionAcquired = true;
@@ -65068,10 +65068,13 @@ class XrplApi {
65068
65068
 
65069
65069
  if (!FUNCTIONING_SERVER_STATES.includes(serverState))
65070
65070
  throw "Client might have functioning issues."
65071
+
65072
+ await this.#setXrplClient(client);
65071
65073
  }
65072
65074
 
65073
65075
  async #initEventListeners(client) {
65074
65076
  // First remove all the listeners.
65077
+ let ledgerTimeout;
65075
65078
  try {
65076
65079
  await client.removeAllListeners();
65077
65080
  }
@@ -65081,10 +65084,6 @@ class XrplApi {
65081
65084
  console.log(errorCode + ': ' + errorMessage);
65082
65085
  });
65083
65086
 
65084
- client.on('connected', async () => {
65085
- await this.#setXrplClient(client)
65086
- });
65087
-
65088
65087
  client.on('disconnected', async (code) => {
65089
65088
  this.#events.emit(XrplApiEvents.DISCONNECTED, code);
65090
65089
 
@@ -65101,9 +65100,10 @@ class XrplApi {
65101
65100
  console.log("Error occurred while re-initializing", e)
65102
65101
  }
65103
65102
  }
65103
+ if (ledgerTimeout)
65104
+ clearTimeout(ledgerTimeout);
65104
65105
  });
65105
65106
 
65106
- let ledgerTimeout;
65107
65107
 
65108
65108
  client.on('ledgerClosed', (ledger) => {
65109
65109
  if (ledgerTimeout) {
@@ -65111,12 +65111,16 @@ class XrplApi {
65111
65111
  }
65112
65112
 
65113
65113
  ledgerTimeout = setTimeout(async () => {
65114
- let serverState = await this.getServerState();
65115
-
65116
- if (!FUNCTIONING_SERVER_STATES.includes(serverState)) {
65117
- this.#events.emit(XrplApiEvents.SERVER_DESYNCED, { "event_type": "on_alert", "server_state": serverState });
65114
+ try {
65115
+ let serverState = await this.getServerState();
65116
+ if (!FUNCTIONING_SERVER_STATES.includes(serverState)) {
65117
+ this.#events.emit(XrplApiEvents.SERVER_DESYNCED, { "event_type": "on_alert", "server_state": serverState });
65118
+ }
65119
+ } catch (e) {
65120
+ console.log("Error occurred while listening to server de-syncs.", e)
65121
+ } finally {
65122
+ clearTimeout(ledgerTimeout);
65118
65123
  }
65119
- clearTimeout(ledgerTimeout);
65120
65124
  }, LEDGER_DESYNC_TIME);
65121
65125
 
65122
65126
  this.ledgerIndex = ledger.ledger_index;
@@ -65176,51 +65180,50 @@ class XrplApi {
65176
65180
  });
65177
65181
  }
65178
65182
 
65179
- async #attemptFallbackServerReconnect(maxRounds, attemptsPerServer = 3) {
65183
+ async #attemptFallbackServerReconnect(maxAttempts = null) {
65180
65184
  if (!this.#fallbackServers || this.#fallbackServers?.length == 0)
65181
65185
  return;
65182
65186
 
65183
65187
  await this.#acquireClient();
65184
65188
 
65185
- const fallbackServers = this.#fallbackServers;
65186
- let round = 0;
65187
- while (!this.#isPermanentlyDisconnected && !this.#isPrimaryServerConnected && !this.#isFallbackServerConnected && (!maxRounds || round < maxRounds)) { // Keep attempting until consumer calls disconnect() manually or if the primary server is disconnected.
65188
- ++round;
65189
- serverIterator:
65190
- for (let serverIndex in fallbackServers) {
65191
- const server = fallbackServers[serverIndex];
65192
- for (let attempt = 0; attempt < attemptsPerServer;) {
65193
- if (this.#isPrimaryServerConnected || this.#isPermanentlyDisconnected) {
65194
- break serverIterator;
65189
+ let errors = {};
65190
+ let attempt = 0;
65191
+ retryIterator:
65192
+ while (!this.#isPermanentlyDisconnected && !this.#isPrimaryServerConnected && !this.#isFallbackServerConnected) { // Keep attempting until consumer calls disconnect() manually or if the primary server is disconnected.
65193
+ ++attempt;
65194
+ for (const server of this.#fallbackServers) {
65195
+ const client = new xrpl.Client(server, this.#xrplClientOptions);
65196
+ try {
65197
+ if (!this.#isPrimaryServerConnected) {
65198
+ await this.#handleClientConnect(client);
65199
+ this.#isFallbackServerConnected = true;
65195
65200
  }
65196
- ++attempt;
65197
- const client = new xrpl.Client(server, this.#xrplClientOptions);
65198
- try {
65199
- if (!this.#isPrimaryServerConnected) {
65200
- await this.#handleClientConnect(client);
65201
- this.#isFallbackServerConnected = true;
65202
- }
65203
- break serverIterator;
65201
+ break retryIterator;
65202
+ }
65203
+ catch (e) {
65204
+ this.#releaseClient();
65205
+ console.log(`Error occurred while connecting to fallback server ${server}`);
65206
+ await new Promise(resolve => setTimeout(resolve, 1000));
65207
+ if (client.isConnected()) {
65208
+ console.log('Connection closure already handled');
65209
+ await client.disconnect();
65204
65210
  }
65205
- catch (e) {
65206
- this.#releaseClient();
65207
- console.log(`Error occurred while connecting to fallback server ${server}`);
65208
- await new Promise(resolve => setTimeout(resolve, 1000));
65209
- if (client.isConnected()) {
65210
- console.log('Connection closure already handled');
65211
- await client.disconnect();
65212
- }
65213
65211
 
65214
- if (!this.#isPermanentlyDisconnected) {
65215
- if (!maxRounds || round < maxRounds)
65216
- console.log(`Fallback server ${server} connection attempt ${attempt} failed. Retrying in ${2 * round}s...`);
65217
- else
65218
- return { error: `Fallback server ${server} connection max attempts failed.`, exception: e };
65219
- await new Promise(resolve => setTimeout(resolve, 2 * round * 1000));
65212
+ if (!this.#isPermanentlyDisconnected) {
65213
+ const delaySec = 2 * attempt; // Retry with backoff delay.
65214
+ if (!maxAttempts || attempt < maxAttempts)
65215
+ console.log(`Fallback server ${server} connection attempt ${attempt} failed. Retrying in ${delaySec}s...`);
65216
+ else {
65217
+ errors[server] = { error: `Fallback server ${server} connection max attempts failed.`, exception: e };
65220
65218
  }
65219
+
65220
+ await new Promise(resolve => setTimeout(resolve, delaySec * 1000));
65221
65221
  }
65222
65222
  }
65223
65223
  }
65224
+
65225
+ if (maxAttempts && attempt >= maxAttempts)
65226
+ return { error: Object.values(errors) };
65224
65227
  }
65225
65228
 
65226
65229
  return {};
@@ -65272,9 +65275,9 @@ class XrplApi {
65272
65275
  }
65273
65276
  else {
65274
65277
  if (this.#primaryServer) {
65275
- res = await Promise.all([this.#attemptPrimaryServerReconnect(1), this.#attemptFallbackServerReconnect(1, 1)]);
65278
+ res = await Promise.all([this.#attemptPrimaryServerReconnect(1), this.#attemptFallbackServerReconnect(1)]);
65276
65279
  } else {
65277
- res = [await this.#attemptFallbackServerReconnect(1, 1)];
65280
+ res = [await this.#attemptFallbackServerReconnect(1)];
65278
65281
  }
65279
65282
  }
65280
65283
 
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.41",
9
+ "version": "0.6.43",
10
10
  "dependencies": {
11
11
  "elliptic": "6.5.4",
12
12
  "libsodium-wrappers": "0.7.10",
Binary file
Binary file