evernode-js-client 0.6.48 → 0.6.50
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +95 -71
- package/package.json +1 -1
package/index.js
CHANGED
@@ -61222,7 +61222,7 @@ class HostClient extends BaseEvernodeClient {
|
|
61222
61222
|
*/
|
61223
61223
|
async getLeaseByIndex(index) {
|
61224
61224
|
const token = await EvernodeHelpers.getLeaseByIndex(this.xrplApi, index);
|
61225
|
-
if (token
|
61225
|
+
if (token?.Issuer !== this.xrplAcc.address)
|
61226
61226
|
return null;
|
61227
61227
|
return token;
|
61228
61228
|
}
|
@@ -62335,10 +62335,10 @@ class TenantClient extends BaseEvernodeClient {
|
|
62335
62335
|
super(xrpAddress, xrpSecret, Object.values(TenantEvents), false, options);
|
62336
62336
|
}
|
62337
62337
|
|
62338
|
-
async prepareAccount() {
|
62338
|
+
async prepareAccount(options = {}) {
|
62339
62339
|
try {
|
62340
62340
|
if (!await this.xrplAcc.getMessageKey())
|
62341
|
-
await this.xrplAcc.setAccountFields({ MessageKey: this.accKeyPair.publicKey });
|
62341
|
+
await this.xrplAcc.setAccountFields({ MessageKey: this.accKeyPair.publicKey }, options);
|
62342
62342
|
}
|
62343
62343
|
catch (err) {
|
62344
62344
|
console.log("Error in preparing user xrpl account for Evernode.", err);
|
@@ -62464,21 +62464,29 @@ class TenantClient extends BaseEvernodeClient {
|
|
62464
62464
|
|
62465
62465
|
let relevantTx = null;
|
62466
62466
|
while (!rejected && !relevantTx) {
|
62467
|
-
|
62468
|
-
|
62469
|
-
t
|
62470
|
-
|
62471
|
-
|
62472
|
-
|
62473
|
-
|
62474
|
-
|
62475
|
-
|
62476
|
-
|
62477
|
-
|
62478
|
-
|
62479
|
-
|
62467
|
+
try {
|
62468
|
+
const txList = await this.xrplAcc.getAccountTrx(tx.details.ledger_index);
|
62469
|
+
for (let t of txList) {
|
62470
|
+
t.tx.Memos = TransactionHelper.deserializeMemos(t.tx?.Memos);
|
62471
|
+
t.tx.HookParameters = TransactionHelper.deserializeHookParams(t.tx?.HookParameters);
|
62472
|
+
|
62473
|
+
if (t.meta?.delivered_amount)
|
62474
|
+
t.tx.DeliveredAmount = t.meta.delivered_amount;
|
62475
|
+
|
62476
|
+
const res = await this.extractEvernodeEvent(t.tx);
|
62477
|
+
if ((res?.name === EvernodeEvents.AcquireSuccess || res?.name === EvernodeEvents.AcquireError) && res?.data?.acquireRefId === tx.id) {
|
62478
|
+
clearTimeout(failTimeout);
|
62479
|
+
relevantTx = res;
|
62480
|
+
break;
|
62481
|
+
}
|
62480
62482
|
}
|
62481
62483
|
}
|
62484
|
+
catch (e) {
|
62485
|
+
rejected = true;
|
62486
|
+
clearTimeout(failTimeout);
|
62487
|
+
reject({ error: ErrorCodes.ACQUIRE_ERR, reason: 'UNKNOWN', acquireRefId: tx.id });
|
62488
|
+
break;
|
62489
|
+
}
|
62482
62490
|
await new Promise(resolveSleep => setTimeout(resolveSleep, 2000));
|
62483
62491
|
}
|
62484
62492
|
|
@@ -62579,21 +62587,29 @@ class TenantClient extends BaseEvernodeClient {
|
|
62579
62587
|
|
62580
62588
|
let relevantTx = null;
|
62581
62589
|
while (!rejected && !relevantTx) {
|
62582
|
-
|
62583
|
-
|
62584
|
-
t
|
62585
|
-
|
62586
|
-
|
62587
|
-
|
62588
|
-
|
62589
|
-
|
62590
|
-
|
62591
|
-
|
62592
|
-
|
62593
|
-
|
62594
|
-
|
62590
|
+
try {
|
62591
|
+
const txList = await this.xrplAcc.getAccountTrx(tx.details.ledger_index);
|
62592
|
+
for (let t of txList) {
|
62593
|
+
t.tx.Memos = TransactionHelper.deserializeMemos(t.tx.Memos);
|
62594
|
+
t.tx.HookParameters = TransactionHelper.deserializeHookParams(t.tx?.HookParameters);
|
62595
|
+
|
62596
|
+
if (t.meta?.delivered_amount)
|
62597
|
+
t.tx.DeliveredAmount = t.meta.delivered_amount;
|
62598
|
+
|
62599
|
+
const res = await this.extractEvernodeEvent(t.tx);
|
62600
|
+
if ((res?.name === TenantEvents.ExtendSuccess || res?.name === TenantEvents.ExtendError) && res?.data?.extendRefId === tx.id) {
|
62601
|
+
clearTimeout(failTimeout);
|
62602
|
+
relevantTx = res;
|
62603
|
+
break;
|
62604
|
+
}
|
62595
62605
|
}
|
62596
62606
|
}
|
62607
|
+
catch (e) {
|
62608
|
+
rejected = true;
|
62609
|
+
clearTimeout(failTimeout);
|
62610
|
+
reject({ error: ErrorCodes.EXTEND_ERR, reason: 'UNKNOWN', extendRefId: tx.id });
|
62611
|
+
break;
|
62612
|
+
}
|
62597
62613
|
await new Promise(resolveSleep => setTimeout(resolveSleep, 1000));
|
62598
62614
|
}
|
62599
62615
|
|
@@ -62608,7 +62624,8 @@ class TenantClient extends BaseEvernodeClient {
|
|
62608
62624
|
reject({
|
62609
62625
|
error: ErrorCodes.EXTEND_ERR,
|
62610
62626
|
transaction: relevantTx?.data.transaction,
|
62611
|
-
reason: relevantTx?.data.reason
|
62627
|
+
reason: relevantTx?.data.reason,
|
62628
|
+
extendRefId: relevantTx?.data.extendRefId
|
62612
62629
|
});
|
62613
62630
|
}
|
62614
62631
|
}
|
@@ -65467,7 +65484,6 @@ const { TransactionHelper } = __nccwpck_require__(7071);
|
|
65467
65484
|
const { XrplApiEvents } = __nccwpck_require__(3307);
|
65468
65485
|
const { XrplAccount } = __nccwpck_require__(9329);
|
65469
65486
|
const { XrplHelpers } = __nccwpck_require__(3189);
|
65470
|
-
const { UtilHelpers } = __nccwpck_require__(6687);
|
65471
65487
|
|
65472
65488
|
const MAX_PAGE_LIMIT = 400;
|
65473
65489
|
const API_REQ_TYPE = {
|
@@ -65518,7 +65534,7 @@ class XrplApi {
|
|
65518
65534
|
}
|
65519
65535
|
|
65520
65536
|
async #acquireClient() {
|
65521
|
-
while (!(this.#isPrimaryServerConnected || this.#isFallbackServerConnected) && this.#isClientAcquired
|
65537
|
+
while (!(this.#isPrimaryServerConnected || this.#isFallbackServerConnected) && this.#isClientAcquired) {
|
65522
65538
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
65523
65539
|
}
|
65524
65540
|
this.#isClientAcquired = true;
|
@@ -65529,7 +65545,7 @@ class XrplApi {
|
|
65529
65545
|
}
|
65530
65546
|
|
65531
65547
|
async #acquireConnection() {
|
65532
|
-
while (this.#
|
65548
|
+
while (this.#isConnectionAcquired) {
|
65533
65549
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
65534
65550
|
}
|
65535
65551
|
this.#isConnectionAcquired = true;
|
@@ -65564,8 +65580,6 @@ class XrplApi {
|
|
65564
65580
|
|
65565
65581
|
if (!FUNCTIONING_SERVER_STATES.includes(serverState))
|
65566
65582
|
throw "Client might have functioning issues."
|
65567
|
-
|
65568
|
-
await this.#setXrplClient(client);
|
65569
65583
|
}
|
65570
65584
|
|
65571
65585
|
async #initEventListeners(client) {
|
@@ -65580,6 +65594,10 @@ class XrplApi {
|
|
65580
65594
|
console.log(errorCode + ': ' + errorMessage);
|
65581
65595
|
});
|
65582
65596
|
|
65597
|
+
client.on('connected', async () => {
|
65598
|
+
await this.#setXrplClient(client)
|
65599
|
+
});
|
65600
|
+
|
65583
65601
|
client.on('disconnected', async (code) => {
|
65584
65602
|
this.#events.emit(XrplApiEvents.DISCONNECTED, code);
|
65585
65603
|
|
@@ -65613,7 +65631,12 @@ class XrplApi {
|
|
65613
65631
|
this.#events.emit(XrplApiEvents.SERVER_DESYNCED, { "event_type": "on_alert", "server_state": serverState });
|
65614
65632
|
}
|
65615
65633
|
} catch (e) {
|
65616
|
-
|
65634
|
+
if (e.name === 'TimeoutError') {
|
65635
|
+
console.error("Server timeout detected.");
|
65636
|
+
this.#events.emit(XrplApiEvents.DISCONNECTED, 408);
|
65637
|
+
}
|
65638
|
+
else
|
65639
|
+
console.error("Error occurred while listening to server de-syncs.", e);
|
65617
65640
|
} finally {
|
65618
65641
|
clearTimeout(ledgerTimeout);
|
65619
65642
|
}
|
@@ -65676,50 +65699,51 @@ class XrplApi {
|
|
65676
65699
|
});
|
65677
65700
|
}
|
65678
65701
|
|
65679
|
-
async #attemptFallbackServerReconnect(
|
65702
|
+
async #attemptFallbackServerReconnect(maxRounds, attemptsPerServer = 3) {
|
65680
65703
|
if (!this.#fallbackServers || this.#fallbackServers?.length == 0)
|
65681
65704
|
return;
|
65682
65705
|
|
65683
65706
|
await this.#acquireClient();
|
65684
65707
|
|
65685
|
-
|
65686
|
-
let
|
65687
|
-
|
65688
|
-
|
65689
|
-
|
65690
|
-
for (
|
65691
|
-
const
|
65692
|
-
|
65693
|
-
if (
|
65694
|
-
|
65695
|
-
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;
|
65696
65718
|
}
|
65697
|
-
|
65698
|
-
|
65699
|
-
|
65700
|
-
|
65701
|
-
|
65702
|
-
|
65703
|
-
|
65704
|
-
|
65705
|
-
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;
|
65706
65727
|
}
|
65707
|
-
|
65708
|
-
|
65709
|
-
|
65710
|
-
|
65711
|
-
|
65712
|
-
|
65713
|
-
|
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();
|
65714
65735
|
}
|
65715
65736
|
|
65716
|
-
|
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
|
+
}
|
65717
65744
|
}
|
65718
65745
|
}
|
65719
65746
|
}
|
65720
|
-
|
65721
|
-
if (maxAttempts && attempt >= maxAttempts)
|
65722
|
-
return { error: Object.values(errors) };
|
65723
65747
|
}
|
65724
65748
|
|
65725
65749
|
return {};
|
@@ -65771,9 +65795,9 @@ class XrplApi {
|
|
65771
65795
|
}
|
65772
65796
|
else {
|
65773
65797
|
if (this.#primaryServer) {
|
65774
|
-
res = await Promise.all([this.#attemptPrimaryServerReconnect(1), this.#attemptFallbackServerReconnect(1)]);
|
65798
|
+
res = await Promise.all([this.#attemptPrimaryServerReconnect(1), this.#attemptFallbackServerReconnect(1, 1)]);
|
65775
65799
|
} else {
|
65776
|
-
res = [await this.#attemptFallbackServerReconnect(1)];
|
65800
|
+
res = [await this.#attemptFallbackServerReconnect(1, 1)];
|
65777
65801
|
}
|
65778
65802
|
}
|
65779
65803
|
|
@@ -65903,7 +65927,7 @@ class XrplApi {
|
|
65903
65927
|
const info = await this.getAccountInfo(address);
|
65904
65928
|
const accountFlags = xrpl.parseAccountRootFlags(info.Flags);
|
65905
65929
|
const regularKey = info.RegularKey;
|
65906
|
-
const derivedPubKeyAddress =
|
65930
|
+
const derivedPubKeyAddress = kp.deriveAddress(publicKey);
|
65907
65931
|
|
65908
65932
|
// If the master key is disabled the derived pubkey address should be the regular key.
|
65909
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.
|
9
|
+
"version": "0.6.50",
|
10
10
|
"dependencies": {
|
11
11
|
"elliptic": "6.5.4",
|
12
12
|
"libsodium-wrappers": "0.7.10",
|