evernode-js-client 0.6.35 → 0.6.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +61 -26
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -53838,6 +53838,12 @@ class HostClient extends BaseEvernodeClient {
|
|
|
53838
53838
|
* @returns Transaction result.
|
|
53839
53839
|
*/
|
|
53840
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
|
+
|
|
53841
53847
|
let data;
|
|
53842
53848
|
// Prepare voteInfo
|
|
53843
53849
|
if (Object.keys(voteInfo).length > 1) {
|
|
@@ -57218,7 +57224,7 @@ class XrplApi {
|
|
|
57218
57224
|
}
|
|
57219
57225
|
|
|
57220
57226
|
async #acquireClient() {
|
|
57221
|
-
while (this.#
|
|
57227
|
+
while (!(this.#isPrimaryServerConnected || this.#isFallbackServerConnected) && this.#isClientAcquired) {
|
|
57222
57228
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
57223
57229
|
}
|
|
57224
57230
|
this.#isClientAcquired = true;
|
|
@@ -57229,7 +57235,7 @@ class XrplApi {
|
|
|
57229
57235
|
}
|
|
57230
57236
|
|
|
57231
57237
|
async #acquireConnection() {
|
|
57232
|
-
while (this.#
|
|
57238
|
+
while (this.#isConnectionAcquired) {
|
|
57233
57239
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
57234
57240
|
}
|
|
57235
57241
|
this.#isConnectionAcquired = true;
|
|
@@ -57240,16 +57246,15 @@ class XrplApi {
|
|
|
57240
57246
|
}
|
|
57241
57247
|
|
|
57242
57248
|
async #setXrplClient(client) {
|
|
57243
|
-
await this.#acquireClient();
|
|
57244
57249
|
try {
|
|
57245
|
-
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.
|
|
57246
57251
|
await this.#client.removeAllListeners();
|
|
57252
|
+
await this.#client.disconnect();
|
|
57253
|
+
}
|
|
57247
57254
|
|
|
57248
57255
|
this.#client = client;
|
|
57249
|
-
this.#releaseClient();
|
|
57250
57256
|
}
|
|
57251
57257
|
catch (e) {
|
|
57252
|
-
this.#releaseClient();
|
|
57253
57258
|
console.log("Error occurred in Client initiation:", e)
|
|
57254
57259
|
}
|
|
57255
57260
|
}
|
|
@@ -57349,9 +57354,14 @@ class XrplApi {
|
|
|
57349
57354
|
}
|
|
57350
57355
|
|
|
57351
57356
|
async #attemptFallbackServerReconnect(maxRounds, attemptsPerServer = 3) {
|
|
57357
|
+
if (!this.#fallbackServers || this.#fallbackServers?.length == 0)
|
|
57358
|
+
return;
|
|
57359
|
+
|
|
57360
|
+
await this.#acquireClient();
|
|
57361
|
+
|
|
57352
57362
|
const fallbackServers = this.#fallbackServers;
|
|
57353
57363
|
let round = 0;
|
|
57354
|
-
while (
|
|
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.
|
|
57355
57365
|
++round;
|
|
57356
57366
|
serverIterator:
|
|
57357
57367
|
for (let serverIndex in fallbackServers) {
|
|
@@ -57361,8 +57371,8 @@ class XrplApi {
|
|
|
57361
57371
|
break serverIterator;
|
|
57362
57372
|
}
|
|
57363
57373
|
++attempt;
|
|
57374
|
+
const client = new xrpl.Client(server, this.#xrplClientOptions);
|
|
57364
57375
|
try {
|
|
57365
|
-
const client = new xrpl.Client(server, this.#xrplClientOptions);
|
|
57366
57376
|
if (!this.#isPrimaryServerConnected) {
|
|
57367
57377
|
await this.#handleClientConnect(client);
|
|
57368
57378
|
this.#isFallbackServerConnected = true;
|
|
@@ -57370,63 +57380,86 @@ class XrplApi {
|
|
|
57370
57380
|
break serverIterator;
|
|
57371
57381
|
}
|
|
57372
57382
|
catch (e) {
|
|
57373
|
-
|
|
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
|
+
|
|
57374
57391
|
if (!this.#isPermanentlyDisconnected) {
|
|
57375
57392
|
if (!maxRounds || round < maxRounds)
|
|
57376
57393
|
console.log(`Fallback server ${server} connection attempt ${attempt} failed. Retrying in ${2 * round}s...`);
|
|
57377
57394
|
else
|
|
57378
|
-
|
|
57395
|
+
return { error: `Fallback server ${server} connection max attempts failed.`, exception: e };
|
|
57379
57396
|
await new Promise(resolve => setTimeout(resolve, 2 * round * 1000));
|
|
57380
57397
|
}
|
|
57381
57398
|
}
|
|
57382
57399
|
}
|
|
57383
57400
|
}
|
|
57384
|
-
|
|
57385
57401
|
}
|
|
57402
|
+
|
|
57403
|
+
return {};
|
|
57386
57404
|
}
|
|
57387
57405
|
|
|
57388
57406
|
async #attemptPrimaryServerReconnect(maxAttempts = null) {
|
|
57407
|
+
await this.#acquireClient();
|
|
57408
|
+
|
|
57389
57409
|
let attempt = 0;
|
|
57390
|
-
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.
|
|
57391
57411
|
++attempt;
|
|
57412
|
+
const client = new xrpl.Client(this.#primaryServer, this.#xrplClientOptions);
|
|
57392
57413
|
try {
|
|
57393
|
-
const client = new xrpl.Client(this.#primaryServer, this.#xrplClientOptions);
|
|
57394
57414
|
await this.#handleClientConnect(client);
|
|
57395
|
-
this.#isFallbackServerConnected = false;
|
|
57396
57415
|
this.#isPrimaryServerConnected = true;
|
|
57397
57416
|
break;
|
|
57398
57417
|
}
|
|
57399
57418
|
catch (e) {
|
|
57400
|
-
|
|
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
|
+
|
|
57401
57427
|
if (!this.#isPermanentlyDisconnected) {
|
|
57402
57428
|
const delaySec = 2 * attempt; // Retry with backoff delay.
|
|
57403
57429
|
if (!maxAttempts || attempt < maxAttempts)
|
|
57404
57430
|
console.log(`Primary server ${this.#primaryServer} attempt ${attempt} failed. Retrying in ${delaySec}s...`);
|
|
57405
57431
|
else
|
|
57406
|
-
|
|
57432
|
+
return { error: `Primary server ${this.#primaryServer} connection max attempts failed.`, exception: e };
|
|
57407
57433
|
await new Promise(resolve => setTimeout(resolve, delaySec * 1000));
|
|
57408
57434
|
}
|
|
57409
57435
|
}
|
|
57410
57436
|
}
|
|
57437
|
+
|
|
57438
|
+
return {};
|
|
57411
57439
|
}
|
|
57412
57440
|
|
|
57413
57441
|
async #connectXrplClient(reconnect = false) {
|
|
57442
|
+
let res = [];
|
|
57414
57443
|
if (reconnect) {
|
|
57415
57444
|
if (this.#primaryServer) {
|
|
57416
|
-
Promise.all([this.#
|
|
57445
|
+
res = await Promise.all([this.#attemptPrimaryServerReconnect(), this.#attemptFallbackServerReconnect()]);
|
|
57417
57446
|
} else {
|
|
57418
|
-
this.#attemptFallbackServerReconnect();
|
|
57447
|
+
res = [await this.#attemptFallbackServerReconnect()];
|
|
57419
57448
|
}
|
|
57420
57449
|
}
|
|
57421
57450
|
else {
|
|
57422
57451
|
if (this.#primaryServer) {
|
|
57423
|
-
Promise.all([this.#
|
|
57452
|
+
res = await Promise.all([this.#attemptPrimaryServerReconnect(1), this.#attemptFallbackServerReconnect(1, 1)]);
|
|
57424
57453
|
} else {
|
|
57425
|
-
this.#attemptFallbackServerReconnect(1, 1);
|
|
57454
|
+
res = [await this.#attemptFallbackServerReconnect(1, 1)];
|
|
57426
57455
|
}
|
|
57427
57456
|
}
|
|
57428
57457
|
|
|
57458
|
+
if (res.filter(r => r && !r.error).length == 0)
|
|
57459
|
+
throw res.filter(r => r && r.error).map(r => r.error);
|
|
57460
|
+
|
|
57429
57461
|
await this.#waitForConnection();
|
|
57462
|
+
this.#releaseClient();
|
|
57430
57463
|
|
|
57431
57464
|
// After connection established, check again whether maintainConnections has become false.
|
|
57432
57465
|
// This is in case the consumer has called disconnect() while connection is being established.
|
|
@@ -57501,24 +57534,27 @@ class XrplApi {
|
|
|
57501
57534
|
|
|
57502
57535
|
async connect() {
|
|
57503
57536
|
this.#isPermanentlyDisconnected = false;
|
|
57504
|
-
|
|
57537
|
+
|
|
57538
|
+
if (!this.#client || !this.#client.isConnected()) {
|
|
57539
|
+
await this.#connectXrplClient();
|
|
57540
|
+
}
|
|
57505
57541
|
const definitions = await this.#handleClientRequest({ command: 'server_definitions' })
|
|
57506
57542
|
this.xrplHelper = new XrplHelpers(definitions.result);
|
|
57507
57543
|
}
|
|
57508
57544
|
|
|
57509
57545
|
async disconnect() {
|
|
57510
|
-
await this.#
|
|
57546
|
+
await this.#acquireConnection();
|
|
57511
57547
|
|
|
57512
57548
|
try {
|
|
57513
57549
|
this.#isPermanentlyDisconnected = true;
|
|
57514
57550
|
|
|
57515
|
-
if (this.#client.isConnected()) {
|
|
57551
|
+
if (this.#client && this.#client.isConnected()) {
|
|
57516
57552
|
await this.#client.disconnect().catch(console.error);
|
|
57517
57553
|
}
|
|
57518
|
-
this.#
|
|
57554
|
+
this.#releaseConnection();
|
|
57519
57555
|
}
|
|
57520
57556
|
catch (e) {
|
|
57521
|
-
this.#
|
|
57557
|
+
this.#releaseConnection();
|
|
57522
57558
|
throw e;
|
|
57523
57559
|
}
|
|
57524
57560
|
}
|
|
@@ -57723,7 +57759,6 @@ class XrplApi {
|
|
|
57723
57759
|
return { ...txResult, ...(hookExecRes ? { hookExecutionResult: hookExecRes } : {}) };
|
|
57724
57760
|
else
|
|
57725
57761
|
throw { ...txResult, ...(hookExecRes ? { hookExecutionResult: hookExecRes } : {}) };
|
|
57726
|
-
|
|
57727
57762
|
}
|
|
57728
57763
|
|
|
57729
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.
|
|
9
|
+
"version": "0.6.36",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"elliptic": "6.5.4",
|
|
12
12
|
"libsodium-wrappers": "0.7.10",
|