evernode-js-client 0.6.49 → 0.6.50

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +42 -40
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -65484,7 +65484,6 @@ const { TransactionHelper } = __nccwpck_require__(7071);
65484
65484
  const { XrplApiEvents } = __nccwpck_require__(3307);
65485
65485
  const { XrplAccount } = __nccwpck_require__(9329);
65486
65486
  const { XrplHelpers } = __nccwpck_require__(3189);
65487
- const { UtilHelpers } = __nccwpck_require__(6687);
65488
65487
 
65489
65488
  const MAX_PAGE_LIMIT = 400;
65490
65489
  const API_REQ_TYPE = {
@@ -65535,7 +65534,7 @@ class XrplApi {
65535
65534
  }
65536
65535
 
65537
65536
  async #acquireClient() {
65538
- while (!(this.#isPrimaryServerConnected || this.#isFallbackServerConnected) && this.#isClientAcquired || this.#isConnectionAcquired) {
65537
+ while (!(this.#isPrimaryServerConnected || this.#isFallbackServerConnected) && this.#isClientAcquired) {
65539
65538
  await new Promise((resolve) => setTimeout(resolve, 100));
65540
65539
  }
65541
65540
  this.#isClientAcquired = true;
@@ -65546,7 +65545,7 @@ class XrplApi {
65546
65545
  }
65547
65546
 
65548
65547
  async #acquireConnection() {
65549
- while (this.#isClientAcquired) {
65548
+ while (this.#isConnectionAcquired) {
65550
65549
  await new Promise((resolve) => setTimeout(resolve, 100));
65551
65550
  }
65552
65551
  this.#isConnectionAcquired = true;
@@ -65581,8 +65580,6 @@ class XrplApi {
65581
65580
 
65582
65581
  if (!FUNCTIONING_SERVER_STATES.includes(serverState))
65583
65582
  throw "Client might have functioning issues."
65584
-
65585
- await this.#setXrplClient(client);
65586
65583
  }
65587
65584
 
65588
65585
  async #initEventListeners(client) {
@@ -65597,6 +65594,10 @@ class XrplApi {
65597
65594
  console.log(errorCode + ': ' + errorMessage);
65598
65595
  });
65599
65596
 
65597
+ client.on('connected', async () => {
65598
+ await this.#setXrplClient(client)
65599
+ });
65600
+
65600
65601
  client.on('disconnected', async (code) => {
65601
65602
  this.#events.emit(XrplApiEvents.DISCONNECTED, code);
65602
65603
 
@@ -65698,50 +65699,51 @@ class XrplApi {
65698
65699
  });
65699
65700
  }
65700
65701
 
65701
- async #attemptFallbackServerReconnect(maxAttempts = null) {
65702
+ async #attemptFallbackServerReconnect(maxRounds, attemptsPerServer = 3) {
65702
65703
  if (!this.#fallbackServers || this.#fallbackServers?.length == 0)
65703
65704
  return;
65704
65705
 
65705
65706
  await this.#acquireClient();
65706
65707
 
65707
- let errors = {};
65708
- let attempt = 0;
65709
- retryIterator:
65710
- while (!this.#isPermanentlyDisconnected && !this.#isPrimaryServerConnected && !this.#isFallbackServerConnected) { // Keep attempting until consumer calls disconnect() manually or if the primary server is disconnected.
65711
- ++attempt;
65712
- for (const server of this.#fallbackServers) {
65713
- const client = new xrpl.Client(server, this.#xrplClientOptions);
65714
- try {
65715
- if (!this.#isPrimaryServerConnected) {
65716
- await this.#handleClientConnect(client);
65717
- this.#isFallbackServerConnected = true;
65708
+ const fallbackServers = this.#fallbackServers;
65709
+ let round = 0;
65710
+ while (!this.#isPermanentlyDisconnected && !this.#isPrimaryServerConnected && !this.#isFallbackServerConnected && (!maxRounds || round < maxRounds)) { // Keep attempting until consumer calls disconnect() manually or if the primary server is disconnected.
65711
+ ++round;
65712
+ serverIterator:
65713
+ for (let serverIndex in fallbackServers) {
65714
+ const server = fallbackServers[serverIndex];
65715
+ for (let attempt = 0; attempt < attemptsPerServer;) {
65716
+ if (this.#isPrimaryServerConnected || this.#isPermanentlyDisconnected) {
65717
+ break serverIterator;
65718
65718
  }
65719
- break retryIterator;
65720
- }
65721
- catch (e) {
65722
- this.#releaseClient();
65723
- console.log(`Error occurred while connecting to fallback server ${server}`);
65724
- await new Promise(resolve => setTimeout(resolve, 1000));
65725
- if (client.isConnected()) {
65726
- console.log('Connection closure already handled');
65727
- await client.disconnect();
65719
+ ++attempt;
65720
+ const client = new xrpl.Client(server, this.#xrplClientOptions);
65721
+ try {
65722
+ if (!this.#isPrimaryServerConnected) {
65723
+ await this.#handleClientConnect(client);
65724
+ this.#isFallbackServerConnected = true;
65725
+ }
65726
+ break serverIterator;
65728
65727
  }
65729
-
65730
- if (!this.#isPermanentlyDisconnected) {
65731
- const delaySec = 2 * attempt; // Retry with backoff delay.
65732
- if (!maxAttempts || attempt < maxAttempts)
65733
- console.log(`Fallback server ${server} connection attempt ${attempt} failed. Retrying in ${delaySec}s...`);
65734
- else {
65735
- errors[server] = { error: `Fallback server ${server} connection max attempts failed.`, exception: e };
65728
+ catch (e) {
65729
+ this.#releaseClient();
65730
+ console.log(`Error occurred while connecting to fallback server ${server}`);
65731
+ await new Promise(resolve => setTimeout(resolve, 1000));
65732
+ if (client.isConnected()) {
65733
+ console.log('Connection closure already handled');
65734
+ await client.disconnect();
65736
65735
  }
65737
65736
 
65738
- await new Promise(resolve => setTimeout(resolve, delaySec * 1000));
65737
+ if (!this.#isPermanentlyDisconnected) {
65738
+ if (!maxRounds || round < maxRounds)
65739
+ console.log(`Fallback server ${server} connection attempt ${attempt} failed. Retrying in ${2 * round}s...`);
65740
+ else
65741
+ return { error: `Fallback server ${server} connection max attempts failed.`, exception: e };
65742
+ await new Promise(resolve => setTimeout(resolve, 2 * round * 1000));
65743
+ }
65739
65744
  }
65740
65745
  }
65741
65746
  }
65742
-
65743
- if (maxAttempts && attempt >= maxAttempts)
65744
- return { error: Object.values(errors) };
65745
65747
  }
65746
65748
 
65747
65749
  return {};
@@ -65793,9 +65795,9 @@ class XrplApi {
65793
65795
  }
65794
65796
  else {
65795
65797
  if (this.#primaryServer) {
65796
- res = await Promise.all([this.#attemptPrimaryServerReconnect(1), this.#attemptFallbackServerReconnect(1)]);
65798
+ res = await Promise.all([this.#attemptPrimaryServerReconnect(1), this.#attemptFallbackServerReconnect(1, 1)]);
65797
65799
  } else {
65798
- res = [await this.#attemptFallbackServerReconnect(1)];
65800
+ res = [await this.#attemptFallbackServerReconnect(1, 1)];
65799
65801
  }
65800
65802
  }
65801
65803
 
@@ -65925,7 +65927,7 @@ class XrplApi {
65925
65927
  const info = await this.getAccountInfo(address);
65926
65928
  const accountFlags = xrpl.parseAccountRootFlags(info.Flags);
65927
65929
  const regularKey = info.RegularKey;
65928
- const derivedPubKeyAddress = UtilHelpers.deriveAddress(publicKey);
65930
+ const derivedPubKeyAddress = kp.deriveAddress(publicKey);
65929
65931
 
65930
65932
  // If the master key is disabled the derived pubkey address should be the regular key.
65931
65933
  // Otherwise it could be account address or the regular key
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.49",
9
+ "version": "0.6.50",
10
10
  "dependencies": {
11
11
  "elliptic": "6.5.4",
12
12
  "libsodium-wrappers": "0.7.10",