evernode-js-client 0.6.42 → 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,6 +65068,8 @@ 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) {
@@ -65082,10 +65084,6 @@ class XrplApi {
65082
65084
  console.log(errorCode + ': ' + errorMessage);
65083
65085
  });
65084
65086
 
65085
- client.on('connected', async () => {
65086
- await this.#setXrplClient(client)
65087
- });
65088
-
65089
65087
  client.on('disconnected', async (code) => {
65090
65088
  this.#events.emit(XrplApiEvents.DISCONNECTED, code);
65091
65089
 
@@ -65182,51 +65180,50 @@ class XrplApi {
65182
65180
  });
65183
65181
  }
65184
65182
 
65185
- async #attemptFallbackServerReconnect(maxRounds, attemptsPerServer = 3) {
65183
+ async #attemptFallbackServerReconnect(maxAttempts = null) {
65186
65184
  if (!this.#fallbackServers || this.#fallbackServers?.length == 0)
65187
65185
  return;
65188
65186
 
65189
65187
  await this.#acquireClient();
65190
65188
 
65191
- const fallbackServers = this.#fallbackServers;
65192
- let round = 0;
65193
- while (!this.#isPermanentlyDisconnected && !this.#isPrimaryServerConnected && !this.#isFallbackServerConnected && (!maxRounds || round < maxRounds)) { // Keep attempting until consumer calls disconnect() manually or if the primary server is disconnected.
65194
- ++round;
65195
- serverIterator:
65196
- for (let serverIndex in fallbackServers) {
65197
- const server = fallbackServers[serverIndex];
65198
- for (let attempt = 0; attempt < attemptsPerServer;) {
65199
- if (this.#isPrimaryServerConnected || this.#isPermanentlyDisconnected) {
65200
- 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;
65201
65200
  }
65202
- ++attempt;
65203
- const client = new xrpl.Client(server, this.#xrplClientOptions);
65204
- try {
65205
- if (!this.#isPrimaryServerConnected) {
65206
- await this.#handleClientConnect(client);
65207
- this.#isFallbackServerConnected = true;
65208
- }
65209
- 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();
65210
65210
  }
65211
- catch (e) {
65212
- this.#releaseClient();
65213
- console.log(`Error occurred while connecting to fallback server ${server}`);
65214
- await new Promise(resolve => setTimeout(resolve, 1000));
65215
- if (client.isConnected()) {
65216
- console.log('Connection closure already handled');
65217
- await client.disconnect();
65218
- }
65219
65211
 
65220
- if (!this.#isPermanentlyDisconnected) {
65221
- if (!maxRounds || round < maxRounds)
65222
- console.log(`Fallback server ${server} connection attempt ${attempt} failed. Retrying in ${2 * round}s...`);
65223
- else
65224
- return { error: `Fallback server ${server} connection max attempts failed.`, exception: e };
65225
- 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 };
65226
65218
  }
65219
+
65220
+ await new Promise(resolve => setTimeout(resolve, delaySec * 1000));
65227
65221
  }
65228
65222
  }
65229
65223
  }
65224
+
65225
+ if (maxAttempts && attempt >= maxAttempts)
65226
+ return { error: Object.values(errors) };
65230
65227
  }
65231
65228
 
65232
65229
  return {};
@@ -65278,9 +65275,9 @@ class XrplApi {
65278
65275
  }
65279
65276
  else {
65280
65277
  if (this.#primaryServer) {
65281
- res = await Promise.all([this.#attemptPrimaryServerReconnect(1), this.#attemptFallbackServerReconnect(1, 1)]);
65278
+ res = await Promise.all([this.#attemptPrimaryServerReconnect(1), this.#attemptFallbackServerReconnect(1)]);
65282
65279
  } else {
65283
- res = [await this.#attemptFallbackServerReconnect(1, 1)];
65280
+ res = [await this.#attemptFallbackServerReconnect(1)];
65284
65281
  }
65285
65282
  }
65286
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.42",
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