evernode-js-client 0.6.19 → 0.6.21-definition-1.0
Sign up to get free protection for your applications and to get access to all the features.
Binary file
|
package/index.js
CHANGED
@@ -9149,7 +9149,7 @@ module.exports = { mask, unmask };
|
|
9149
9149
|
|
9150
9150
|
|
9151
9151
|
try {
|
9152
|
-
module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.
|
9152
|
+
module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi1.node");
|
9153
9153
|
} catch (e) {
|
9154
9154
|
module.exports = __nccwpck_require__(2567);
|
9155
9155
|
}
|
@@ -33340,7 +33340,7 @@ module.exports = isValidUTF8;
|
|
33340
33340
|
|
33341
33341
|
|
33342
33342
|
try {
|
33343
|
-
module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.
|
33343
|
+
module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi.node");
|
33344
33344
|
} catch (e) {
|
33345
33345
|
module.exports = __nccwpck_require__(9372);
|
33346
33346
|
}
|
@@ -51832,7 +51832,7 @@ const { XrplApi } = __nccwpck_require__(1850);
|
|
51832
51832
|
const { XrplAccount } = __nccwpck_require__(9329);
|
51833
51833
|
const { XrplApiEvents, XrplConstants } = __nccwpck_require__(3307);
|
51834
51834
|
const { EvernodeEvents, EventTypes, MemoFormats, EvernodeConstants, HookStateKeys, HookParamKeys, RegExp } = __nccwpck_require__(9849);
|
51835
|
-
const {
|
51835
|
+
const { Defaults } = __nccwpck_require__(8262);
|
51836
51836
|
const { EncryptionHelper } = __nccwpck_require__(4832);
|
51837
51837
|
const { EventEmitter } = __nccwpck_require__(6170);
|
51838
51838
|
const { UtilHelpers } = __nccwpck_require__(6687);
|
@@ -51861,10 +51861,10 @@ class BaseEvernodeClient {
|
|
51861
51861
|
constructor(xrpAddress, xrpSecret, watchEvents, autoSubscribe = false, options = {}) {
|
51862
51862
|
|
51863
51863
|
this.connected = false;
|
51864
|
-
this.governorAddress = options.governorAddress ||
|
51864
|
+
this.governorAddress = options.governorAddress || Defaults.values.governorAddress;
|
51865
51865
|
|
51866
|
-
this.xrplApi = options.xrplApi ||
|
51867
|
-
if (!options.xrplApi && !
|
51866
|
+
this.xrplApi = options.xrplApi || Defaults.values.xrplApi || new XrplApi(options.rippledServer);
|
51867
|
+
if (!options.xrplApi && !Defaults.values.xrplApi)
|
51868
51868
|
this.#ownsXrplApi = true;
|
51869
51869
|
|
51870
51870
|
this.xrplAcc = new XrplAccount(xrpAddress, xrpSecret, { xrplApi: this.xrplApi });
|
@@ -53036,7 +53036,7 @@ module.exports = {
|
|
53036
53036
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
53037
53037
|
|
53038
53038
|
const { BaseEvernodeClient } = __nccwpck_require__(6263);
|
53039
|
-
const {
|
53039
|
+
const { Defaults } = __nccwpck_require__(8262);
|
53040
53040
|
const { EvernodeEvents } = __nccwpck_require__(9849);
|
53041
53041
|
|
53042
53042
|
const GovernorEvents = {
|
@@ -53055,7 +53055,7 @@ const GovernorEvents = {
|
|
53055
53055
|
|
53056
53056
|
class GovernorClient extends BaseEvernodeClient {
|
53057
53057
|
constructor(options = {}) {
|
53058
|
-
super((options.governorAddress ||
|
53058
|
+
super((options.governorAddress || Defaults.values.governorAddress), null, Object.values(GovernorEvents), false, options);
|
53059
53059
|
}
|
53060
53060
|
}
|
53061
53061
|
|
@@ -53223,7 +53223,6 @@ const { XflHelpers } = __nccwpck_require__(3243);
|
|
53223
53223
|
const { EvernodeHelpers } = __nccwpck_require__(2523);
|
53224
53224
|
const { StateHelpers } = __nccwpck_require__(3860);
|
53225
53225
|
const { TransactionHelper } = __nccwpck_require__(7071);
|
53226
|
-
const { UtilHelpers } = __nccwpck_require__(6687);
|
53227
53226
|
|
53228
53227
|
const OFFER_WAIT_TIMEOUT = 60;
|
53229
53228
|
|
@@ -53258,7 +53257,6 @@ const HOST_UPDATE_PARAM_SIZE = 123;
|
|
53258
53257
|
|
53259
53258
|
const VOTE_VALIDATION_ERR = "VOTE_VALIDATION_ERR";
|
53260
53259
|
|
53261
|
-
const IPV4_FAMILY = 4;
|
53262
53260
|
const IPV6_FAMILY = 6;
|
53263
53261
|
|
53264
53262
|
class HostClient extends BaseEvernodeClient {
|
@@ -53343,12 +53341,6 @@ class HostClient extends BaseEvernodeClient {
|
|
53343
53341
|
*/
|
53344
53342
|
async offerLease(leaseIndex, leaseAmount, tosHash, outboundIPAddress = null) {
|
53345
53343
|
|
53346
|
-
// If Outbound IP address is not specified resolve the IPV4 address of host using domain.
|
53347
|
-
if (!outboundIPAddress) {
|
53348
|
-
const domain = await this.xrplAcc.getDomain();
|
53349
|
-
outboundIPAddress = await UtilHelpers.resolveIP(domain, { family: 4 });
|
53350
|
-
}
|
53351
|
-
|
53352
53344
|
// <prefix><version tag ("LTV"+uint8)><lease index (uint16)><half of tos hash><lease amount (int64)><identifier (uint32)><ip data>
|
53353
53345
|
// Lengths of sub sections.
|
53354
53346
|
const prefixLen = EvernodeConstants.LEASE_TOKEN_PREFIX_HEX.length / 2;
|
@@ -53358,7 +53350,7 @@ class HostClient extends BaseEvernodeClient {
|
|
53358
53350
|
const halfToSLen = tosHash.length / 4;
|
53359
53351
|
const leaseAmountLen = 8;
|
53360
53352
|
const identifierLen = 4;
|
53361
|
-
const ipDataLen =
|
53353
|
+
const ipDataLen = 17;
|
53362
53354
|
|
53363
53355
|
// Offsets of sub sections
|
53364
53356
|
const versionPrefixOffset = prefixLen;
|
@@ -53379,7 +53371,7 @@ class HostClient extends BaseEvernodeClient {
|
|
53379
53371
|
uriBuf.writeBigInt64BE(XflHelpers.getXfl(leaseAmount.toString()), leaseAmountOffset);
|
53380
53372
|
uriBuf.writeUInt32BE((await this.xrplAcc.getSequence()), identifierOffset);
|
53381
53373
|
|
53382
|
-
if (
|
53374
|
+
if (outboundIPAddress) {
|
53383
53375
|
if (outboundIPAddress.includes(":")) {
|
53384
53376
|
uriBuf.writeUInt8(IPV6_FAMILY, ipDataOffset);
|
53385
53377
|
const ipBuf = Buffer.from(outboundIPAddress.split(':').map(v => {
|
@@ -53392,17 +53384,7 @@ class HostClient extends BaseEvernodeClient {
|
|
53392
53384
|
|
53393
53385
|
ipBuf.copy(uriBuf, ipDataOffset + 1, 0, ipDataLen);
|
53394
53386
|
} else {
|
53395
|
-
|
53396
|
-
|
53397
|
-
const ipBuf = Buffer.from(outboundIPAddress.split('.').map(v => {
|
53398
|
-
const bytes = [];
|
53399
|
-
bytes.push(parseInt(v));
|
53400
|
-
return bytes;
|
53401
|
-
}).flat());
|
53402
|
-
|
53403
|
-
|
53404
|
-
// Last 4 bytes of 17 byte buffer.
|
53405
|
-
ipBuf.copy(uriBuf, (ipDataOffset + 1) + 12, 0, 4);
|
53387
|
+
throw "Invalid outbound IP address was provided";
|
53406
53388
|
}
|
53407
53389
|
}
|
53408
53390
|
|
@@ -54373,16 +54355,22 @@ module.exports = {
|
|
54373
54355
|
/***/ }),
|
54374
54356
|
|
54375
54357
|
/***/ 8262:
|
54376
|
-
/***/ ((module) => {
|
54358
|
+
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
54359
|
+
|
54360
|
+
const DefinitionsPath = './resources/definitions.json';
|
54361
|
+
|
54362
|
+
const Definitions = __nccwpck_require__(4626);
|
54377
54363
|
|
54378
54364
|
const DefaultValues = {
|
54379
|
-
governorAddress: 'rGVHr1PrfL93UAjyw3DWZoi9adz2sLp2yL',
|
54380
|
-
rippledServer: 'wss://hooks-testnet-v3.xrpl-labs.com',
|
54381
54365
|
xrplApi: null,
|
54382
|
-
stateIndexId: 'evernodeindex',
|
54383
|
-
networkID: 21338
|
54384
54366
|
}
|
54385
54367
|
|
54368
|
+
const RequiredInfoKeys = [
|
54369
|
+
"governorAddress",
|
54370
|
+
"stateIndexId",
|
54371
|
+
"networkID"
|
54372
|
+
]
|
54373
|
+
|
54386
54374
|
const HookTypes = {
|
54387
54375
|
governor: 'GOVERNOR',
|
54388
54376
|
registry: 'REGISTRY',
|
@@ -54390,6 +54378,17 @@ const HookTypes = {
|
|
54390
54378
|
}
|
54391
54379
|
|
54392
54380
|
class Defaults {
|
54381
|
+
/**
|
54382
|
+
* Load defaults from the public definitions json.
|
54383
|
+
* @param {string} network Network to choose the info.
|
54384
|
+
*/
|
54385
|
+
static useNetwork(network) {
|
54386
|
+
if (!Definitions[network])
|
54387
|
+
throw 'Invalid network';
|
54388
|
+
|
54389
|
+
this.set(Definitions[network]);
|
54390
|
+
}
|
54391
|
+
|
54393
54392
|
/**
|
54394
54393
|
* Override Evernode default configs.
|
54395
54394
|
* @param {object} newDefaults Configurations to override `{ governorAddress: '{string} governor xrpl address', rippledServer: '{string} rippled server url', xrplApi: '{XrplApi} xrpl instance', stateIndexId: '{string} firestore index', networkID: '{number} rippled network id' }`
|
@@ -54402,13 +54401,18 @@ class Defaults {
|
|
54402
54401
|
* Read Evernode default configs.
|
54403
54402
|
* @returns The Object of Evernode configs
|
54404
54403
|
*/
|
54405
|
-
static get() {
|
54404
|
+
static get values() {
|
54405
|
+
var notFound = RequiredInfoKeys.find(k => !DefaultValues[k]);
|
54406
|
+
if (notFound)
|
54407
|
+
throw `Value for ${notFound} is not set.`;
|
54408
|
+
else if (!DefaultValues.rippledServer && (!DefaultValues.fallbackRippledServers || !DefaultValues.fallbackRippledServers.length))
|
54409
|
+
throw 'Either rippledServer or fallbackRippledServers required.';
|
54410
|
+
|
54406
54411
|
return { ...DefaultValues };
|
54407
54412
|
}
|
54408
54413
|
}
|
54409
54414
|
|
54410
54415
|
module.exports = {
|
54411
|
-
DefaultValues,
|
54412
54416
|
Defaults,
|
54413
54417
|
HookTypes
|
54414
54418
|
}
|
@@ -55093,7 +55097,7 @@ module.exports = {
|
|
55093
55097
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
55094
55098
|
|
55095
55099
|
const https = __nccwpck_require__(5687);
|
55096
|
-
const {
|
55100
|
+
const { Defaults } = __nccwpck_require__(8262);
|
55097
55101
|
|
55098
55102
|
const FirestoreOperations = {
|
55099
55103
|
EQUAL: 'EQUAL',
|
@@ -55105,8 +55109,8 @@ class FirestoreHandler {
|
|
55105
55109
|
#collectionPrefix = null;
|
55106
55110
|
|
55107
55111
|
constructor(options = {}) {
|
55108
|
-
this.#projectId = options.stateIndexId ||
|
55109
|
-
this.#collectionPrefix = options.collectionPrefix ||
|
55112
|
+
this.#projectId = options.stateIndexId || Defaults.values.stateIndexId;
|
55113
|
+
this.#collectionPrefix = options.collectionPrefix || Defaults.values.governorAddress;
|
55110
55114
|
}
|
55111
55115
|
|
55112
55116
|
/**
|
@@ -56263,7 +56267,6 @@ const { XflHelpers } = __nccwpck_require__(3243);
|
|
56263
56267
|
const { EvernodeConstants } = __nccwpck_require__(9849);
|
56264
56268
|
const { TransactionHelper } = __nccwpck_require__(7071);
|
56265
56269
|
const { EvernodeHelpers } = __nccwpck_require__(2523);
|
56266
|
-
const dns = __nccwpck_require__(604);
|
56267
56270
|
|
56268
56271
|
// Utility helper functions.
|
56269
56272
|
class UtilHelpers {
|
@@ -56299,10 +56302,8 @@ class UtilHelpers {
|
|
56299
56302
|
halfTos: uriBuf.slice(halfTosHashOffset, halfTosHashOffset + halfToSLen),
|
56300
56303
|
leaseAmount: parseFloat(XflHelpers.toString(uriBuf.readBigInt64BE(leaseAmountOffset))),
|
56301
56304
|
identifier: uriBuf.length > identifierOffset ? uriBuf.readUInt32BE(identifierOffset) : null,
|
56302
|
-
outboundIP: uriBuf.length > ipDataOffset
|
56303
|
-
|
56304
|
-
? { family: 4, address: uriBuf.slice((ipDataOffset + 13), (ipDataOffset + 13) + ipDataLen).map(b => b.toString()).join('.') }
|
56305
|
-
: { family: 6, address: uriBuf.slice(ipDataOffset + 1, ipDataOffset + 1 + ipDataLen).toString('hex').toUpperCase().replace(/(.{4})(?!$)/g, "$1:") }
|
56305
|
+
outboundIP: (uriBuf.length > ipDataOffset && (uriBuf.readUint8(ipDataOffset) == 6))
|
56306
|
+
? { family: 6, address: uriBuf.slice(ipDataOffset + 1, ipDataOffset + 1 + ipDataLen).toString('hex').toUpperCase().replace(/(.{4})(?!$)/g, "$1:") }
|
56306
56307
|
: null
|
56307
56308
|
}
|
56308
56309
|
}
|
@@ -56317,17 +56318,6 @@ class UtilHelpers {
|
|
56317
56318
|
}
|
56318
56319
|
}
|
56319
56320
|
|
56320
|
-
static async resolveIP(domain, options) {
|
56321
|
-
return new Promise((resolve, reject) => {
|
56322
|
-
dns.lookup(domain, options, (err, address) => {
|
56323
|
-
if (err) {
|
56324
|
-
reject(null);
|
56325
|
-
} else {
|
56326
|
-
resolve(address);
|
56327
|
-
}
|
56328
|
-
});
|
56329
|
-
});
|
56330
|
-
}
|
56331
56321
|
}
|
56332
56322
|
|
56333
56323
|
module.exports = {
|
@@ -56482,7 +56472,7 @@ const crypto = __nccwpck_require__(6113);
|
|
56482
56472
|
const { XrplConstants, XrplTransactionTypes } = __nccwpck_require__(3307);
|
56483
56473
|
const { TransactionHelper } = __nccwpck_require__(7071);
|
56484
56474
|
const { EventEmitter } = __nccwpck_require__(6170);
|
56485
|
-
const {
|
56475
|
+
const { Defaults } = __nccwpck_require__(8262);
|
56486
56476
|
|
56487
56477
|
class XrplAccount {
|
56488
56478
|
|
@@ -56496,7 +56486,7 @@ class XrplAccount {
|
|
56496
56486
|
|
56497
56487
|
this.address = address;
|
56498
56488
|
this.secret = secret;
|
56499
|
-
this.xrplApi = options.xrplApi ||
|
56489
|
+
this.xrplApi = options.xrplApi || Defaults.values.xrplApi;
|
56500
56490
|
|
56501
56491
|
if (!this.xrplApi)
|
56502
56492
|
throw "XrplAccount: xrplApi not specified.";
|
@@ -57218,7 +57208,7 @@ class XrplAccount {
|
|
57218
57208
|
Sequence: options.sequence || await this.getSequence(),
|
57219
57209
|
SigningPubKey: '', // This field is required for fee calculation.
|
57220
57210
|
Fee: '0', // This field is required for fee calculation.
|
57221
|
-
NetworkID:
|
57211
|
+
NetworkID: Defaults.values.networkID
|
57222
57212
|
}
|
57223
57213
|
|
57224
57214
|
Object.assign(tx, txOptions);
|
@@ -57276,11 +57266,11 @@ module.exports = {
|
|
57276
57266
|
const xrpl = __nccwpck_require__(4666);
|
57277
57267
|
const kp = __nccwpck_require__(8150);
|
57278
57268
|
const { EventEmitter } = __nccwpck_require__(6170);
|
57279
|
-
const {
|
57269
|
+
const { Defaults } = __nccwpck_require__(8262);
|
57280
57270
|
const { TransactionHelper } = __nccwpck_require__(7071);
|
57281
57271
|
const { XrplApiEvents } = __nccwpck_require__(3307);
|
57282
57272
|
const { XrplAccount } = __nccwpck_require__(9329);
|
57283
|
-
const {XrplHelpers} = __nccwpck_require__(3189)
|
57273
|
+
const { XrplHelpers } = __nccwpck_require__(3189)
|
57284
57274
|
|
57285
57275
|
const MAX_PAGE_LIMIT = 400;
|
57286
57276
|
const API_REQ_TYPE = {
|
@@ -57296,29 +57286,58 @@ const LEDGER_CLOSE_TIME = 1000
|
|
57296
57286
|
|
57297
57287
|
class XrplApi {
|
57298
57288
|
|
57299
|
-
#
|
57289
|
+
#primaryServer;
|
57290
|
+
#fallbackServers;
|
57300
57291
|
#client;
|
57301
57292
|
#events = new EventEmitter();
|
57302
57293
|
#addressSubscriptions = [];
|
57303
57294
|
#initialConnectCalled = false;
|
57304
57295
|
#isPermanentlyDisconnected = false;
|
57296
|
+
#isClientLocked = false;
|
57297
|
+
#isPrimaryServerConnected = false;
|
57298
|
+
#isFallbackServerConnected = false;
|
57299
|
+
#isAttemptingConnection = false;
|
57300
|
+
#xrplClientOptions;
|
57305
57301
|
#autoReconnect;
|
57306
57302
|
|
57307
|
-
constructor(rippledServer =
|
57308
|
-
|
57309
|
-
|
57303
|
+
constructor(rippledServer = '-', options = {}) {
|
57304
|
+
if (rippledServer == '-') {
|
57305
|
+
this.#primaryServer = null;
|
57306
|
+
} else {
|
57307
|
+
this.#primaryServer = rippledServer || Defaults.values.rippledServer;
|
57308
|
+
}
|
57309
|
+
this.#fallbackServers = options.fallbackRippledServers || Defaults.values.fallbackRippledServers || [];
|
57310
|
+
|
57311
|
+
if (!this.#primaryServer && (!this.#fallbackServers || !this.#fallbackServers.length))
|
57312
|
+
throw 'Either primaryServer or fallbackServers required.';
|
57313
|
+
|
57314
|
+
this.#xrplClientOptions = options.xrplClientOptions;
|
57315
|
+
const initServer = this.#primaryServer || this.#fallbackServers[0];
|
57316
|
+
const client = new xrpl.Client(initServer, this.#xrplClientOptions);
|
57317
|
+
this.#initXrplClient(client);
|
57310
57318
|
this.#autoReconnect = options.autoReconnect ?? true;
|
57311
57319
|
}
|
57312
57320
|
|
57313
|
-
async #
|
57314
|
-
|
57321
|
+
async #setClient(client, removeCurrentClient = false) {
|
57322
|
+
while (this.#isClientLocked) {
|
57323
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
57324
|
+
}
|
57325
|
+
if (removeCurrentClient) {
|
57326
|
+
this.#isClientLocked = true;
|
57315
57327
|
this.#client.removeAllListeners(); // Remove existing event listeners to avoid them getting called from the old client object.
|
57316
57328
|
await this.#client.disconnect();
|
57317
|
-
this.#
|
57329
|
+
this.#isClientLocked = false;
|
57330
|
+
}
|
57331
|
+
this.#client = client;
|
57332
|
+
}
|
57333
|
+
|
57334
|
+
async #initXrplClient(client) {
|
57335
|
+
if (this.#client) { // If the client already exists, clean it up.
|
57336
|
+
await this.#setClient(null, true);
|
57318
57337
|
}
|
57319
57338
|
|
57320
57339
|
try {
|
57321
|
-
this.#client
|
57340
|
+
await this.#setClient(client);
|
57322
57341
|
}
|
57323
57342
|
catch (e) {
|
57324
57343
|
console.log("Error occurred in Client initiation:", e)
|
@@ -57330,10 +57349,10 @@ class XrplApi {
|
|
57330
57349
|
|
57331
57350
|
this.#client.on('disconnected', (code) => {
|
57332
57351
|
if (this.#autoReconnect && !this.#isPermanentlyDisconnected) {
|
57333
|
-
console.log(`Connection failure for ${this.#
|
57352
|
+
console.log(`Connection failure for ${this.#client.url} (code:${code})`);
|
57334
57353
|
console.log("Re-initializing xrpl client.");
|
57335
57354
|
try {
|
57336
|
-
this.#initXrplClient().then(() => this.#connectXrplClient(true));
|
57355
|
+
this.#initXrplClient(this.#client).then(() => this.#connectXrplClient(true));
|
57337
57356
|
}
|
57338
57357
|
catch (e) {
|
57339
57358
|
console.log("Error occurred while re-initializing", e)
|
@@ -57391,40 +57410,113 @@ class XrplApi {
|
|
57391
57410
|
});
|
57392
57411
|
}
|
57393
57412
|
|
57394
|
-
async #
|
57413
|
+
async #attemptFallbackServerReconnect(maxRounds, attemptsPerServer = 3) {
|
57414
|
+
const fallbackServers = this.#fallbackServers;
|
57415
|
+
let round = 0;
|
57416
|
+
while (fallbackServers?.length > 0 && !this.#isPermanentlyDisconnected && !this.#isPrimaryServerConnected && !this.#isFallbackServerConnected && (!maxRounds || round < maxRounds)) { // Keep attempting until consumer calls disconnect() manually or if the primary server is disconnected.
|
57417
|
+
++round;
|
57418
|
+
serverIterator:
|
57419
|
+
for (let serverIndex in fallbackServers) {
|
57420
|
+
const server = fallbackServers[serverIndex];
|
57421
|
+
for (let attempt = 0; attempt < attemptsPerServer;) {
|
57422
|
+
if (this.#isPrimaryServerConnected || this.#isPermanentlyDisconnected) {
|
57423
|
+
break serverIterator;
|
57424
|
+
}
|
57425
|
+
console.log(`Fallback server ${server} reconnection attempt ${++attempt}`);
|
57426
|
+
try {
|
57427
|
+
while (this.#isAttemptingConnection) {
|
57428
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
57429
|
+
}
|
57430
|
+
this.#isAttemptingConnection = true;
|
57431
|
+
const client = new xrpl.Client(server, this.#xrplClientOptions);
|
57432
|
+
if (!this.#isPrimaryServerConnected) {
|
57433
|
+
await this.#handleClientConnect(client);
|
57434
|
+
await this.#initXrplClient(client);
|
57435
|
+
this.#isFallbackServerConnected = true;
|
57436
|
+
console.log(`Successfully connected to the fallback server ${server}`)
|
57437
|
+
}
|
57438
|
+
this.#isAttemptingConnection = false;
|
57439
|
+
break serverIterator;
|
57440
|
+
}
|
57441
|
+
catch (e) {
|
57442
|
+
console.log(`Error occurred while connecting to fallback server ${server}`, e)
|
57443
|
+
this.#isAttemptingConnection = false;
|
57444
|
+
if (!this.#isPermanentlyDisconnected) {
|
57445
|
+
if (!maxRounds || round < maxRounds)
|
57446
|
+
console.log(`Fallback server ${server} connection attempt ${attempt} failed. Retrying in ${2 * round}s...`);
|
57447
|
+
else
|
57448
|
+
console.log(`Fallback server ${server} connection attempt failed.`);
|
57449
|
+
await new Promise(resolve => setTimeout(resolve, 2 * round * 1000));
|
57450
|
+
}
|
57451
|
+
}
|
57452
|
+
}
|
57453
|
+
}
|
57395
57454
|
|
57396
|
-
|
57397
|
-
|
57398
|
-
|
57399
|
-
|
57400
|
-
|
57401
|
-
|
57402
|
-
|
57455
|
+
}
|
57456
|
+
}
|
57457
|
+
|
57458
|
+
async #attemptPrimaryServerReconnect() {
|
57459
|
+
let attempt = 0;
|
57460
|
+
while (!this.#isPermanentlyDisconnected && !this.#isPrimaryServerConnected) { // Keep attempting until consumer calls disconnect() manually.
|
57461
|
+
console.log(`Primary server reconnection attempt ${++attempt}`);
|
57462
|
+
try {
|
57463
|
+
const client = new xrpl.Client(this.#primaryServer, this.#xrplClientOptions);
|
57464
|
+
while (this.#isAttemptingConnection) {
|
57465
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
57403
57466
|
}
|
57404
|
-
|
57405
|
-
|
57406
|
-
|
57407
|
-
|
57408
|
-
|
57409
|
-
|
57410
|
-
|
57467
|
+
this.#isAttemptingConnection = true;
|
57468
|
+
await this.#handleClientConnect(client);
|
57469
|
+
await this.#initXrplClient(client);
|
57470
|
+
this.#isFallbackServerConnected = false;
|
57471
|
+
this.#isPrimaryServerConnected = true;
|
57472
|
+
console.log("Successfully connected to the primary server");
|
57473
|
+
this.#isAttemptingConnection = false;
|
57474
|
+
break;
|
57475
|
+
}
|
57476
|
+
catch (e) {
|
57477
|
+
console.log("Error occurred while re-connecting to the primary server", e)
|
57478
|
+
this.#isAttemptingConnection = false;
|
57479
|
+
if (!this.#isPermanentlyDisconnected) {
|
57480
|
+
const delaySec = 2 * attempt; // Retry with backoff delay.
|
57481
|
+
console.log(`Attempt ${attempt} failed. Retrying in ${delaySec}s...`);
|
57482
|
+
await new Promise(resolve => setTimeout(resolve, delaySec * 1000));
|
57411
57483
|
}
|
57412
57484
|
}
|
57413
57485
|
}
|
57486
|
+
}
|
57487
|
+
|
57488
|
+
async #connectXrplClient(reconnect = false) {
|
57489
|
+
if (reconnect) {
|
57490
|
+
if (this.#primaryServer) {
|
57491
|
+
Promise.all([this.#attemptFallbackServerReconnect(), this.#attemptPrimaryServerReconnect()]);
|
57492
|
+
} else {
|
57493
|
+
this.#attemptFallbackServerReconnect();
|
57494
|
+
}
|
57495
|
+
await this.#waitForReconnection();
|
57496
|
+
}
|
57414
57497
|
else {
|
57415
57498
|
// Single attempt and throw error. Used for initial connect() call.
|
57416
|
-
|
57499
|
+
try {
|
57500
|
+
await this.#handleClientConnect();
|
57501
|
+
this.#isPrimaryServerConnected = true;
|
57502
|
+
} catch {
|
57503
|
+
await this.#attemptFallbackServerReconnect(1, 1);
|
57504
|
+
if (this.#isFallbackServerConnected)
|
57505
|
+
await this.#attemptPrimaryServerReconnect();
|
57506
|
+
}
|
57417
57507
|
}
|
57418
57508
|
|
57419
57509
|
// After connection established, check again whether maintainConnections has become false.
|
57420
57510
|
// This is in case the consumer has called disconnect() while connection is being established.
|
57421
57511
|
if (!this.#isPermanentlyDisconnected) {
|
57512
|
+
this.#isClientLocked = true;
|
57422
57513
|
this.ledgerIndex = await this.#client.getLedgerIndex();
|
57514
|
+
this.#isClientLocked = false;
|
57423
57515
|
this.#subscribeToStream('ledger');
|
57424
57516
|
|
57425
57517
|
// Re-subscribe to existing account address subscriptions (in case this is a reconnect)
|
57426
57518
|
if (this.#addressSubscriptions.length > 0)
|
57427
|
-
await this.#
|
57519
|
+
await this.#handleClientRequest({ command: 'subscribe', accounts: this.#addressSubscriptions.map(s => s.address) });
|
57428
57520
|
}
|
57429
57521
|
else {
|
57430
57522
|
await this.disconnect();
|
@@ -57444,7 +57536,7 @@ class XrplApi {
|
|
57444
57536
|
requestObj.marker = resp?.result?.marker;
|
57445
57537
|
else
|
57446
57538
|
delete requestObj.marker;
|
57447
|
-
resp = (await this.#
|
57539
|
+
resp = (await this.#handleClientRequest(requestObj));
|
57448
57540
|
if (resp?.result && resp?.result[requestType])
|
57449
57541
|
res.push(...resp.result[requestType]);
|
57450
57542
|
if (count)
|
@@ -57454,6 +57546,23 @@ class XrplApi {
|
|
57454
57546
|
return res;
|
57455
57547
|
}
|
57456
57548
|
|
57549
|
+
async #handleClientRequest(request = {}) {
|
57550
|
+
while (this.#isAttemptingConnection) {
|
57551
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
57552
|
+
}
|
57553
|
+
this.#isClientLocked = true;
|
57554
|
+
const response = await this.#client.request(request);
|
57555
|
+
|
57556
|
+
this.#isClientLocked = false;
|
57557
|
+
return response;
|
57558
|
+
}
|
57559
|
+
|
57560
|
+
async #handleClientConnect(client = this.#client) {
|
57561
|
+
this.#isClientLocked = true;
|
57562
|
+
await client.connect();
|
57563
|
+
this.#isClientLocked = false;
|
57564
|
+
}
|
57565
|
+
|
57457
57566
|
on(event, handler) {
|
57458
57567
|
this.#events.on(event, handler);
|
57459
57568
|
}
|
@@ -57466,23 +57575,34 @@ class XrplApi {
|
|
57466
57575
|
this.#events.off(event, handler);
|
57467
57576
|
}
|
57468
57577
|
|
57578
|
+
async #waitForReconnection() {
|
57579
|
+
while (!(this.#isPrimaryServerConnected || this.#isFallbackServerConnected)) {
|
57580
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
57581
|
+
}
|
57582
|
+
return true;
|
57583
|
+
}
|
57584
|
+
|
57469
57585
|
async connect() {
|
57470
57586
|
if (this.#initialConnectCalled) {
|
57471
57587
|
return
|
57472
57588
|
}
|
57473
|
-
this.#initialConnectCalled = true
|
57474
|
-
this.#isPermanentlyDisconnected = false
|
57589
|
+
this.#initialConnectCalled = true;
|
57590
|
+
this.#isPermanentlyDisconnected = false;
|
57475
57591
|
await this.#connectXrplClient();
|
57476
|
-
const definitions = await this.#
|
57592
|
+
const definitions = await this.#handleClientRequest({ command: 'server_definitions' })
|
57477
57593
|
this.xrplHelper = new XrplHelpers(definitions.result);
|
57478
57594
|
}
|
57479
57595
|
|
57480
57596
|
async disconnect() {
|
57481
57597
|
this.#initialConnectCalled = false;
|
57482
|
-
this.#isPermanentlyDisconnected = true
|
57598
|
+
this.#isPermanentlyDisconnected = true;
|
57483
57599
|
|
57484
57600
|
if (this.#client.isConnected()) {
|
57601
|
+
this.#isClientLocked = true;
|
57485
57602
|
await this.#client.disconnect().catch(console.error);
|
57603
|
+
this.#isClientLocked = false;
|
57604
|
+
this.#isPrimaryServerConnected = false;
|
57605
|
+
this.#isFallbackServerConnected = false;
|
57486
57606
|
}
|
57487
57607
|
}
|
57488
57608
|
|
@@ -57502,7 +57622,7 @@ class XrplApi {
|
|
57502
57622
|
|
57503
57623
|
async isAccountExists(address) {
|
57504
57624
|
try {
|
57505
|
-
await this.#
|
57625
|
+
await this.#handleClientRequest({ command: 'account_info', account: address });
|
57506
57626
|
return true;
|
57507
57627
|
}
|
57508
57628
|
catch (e) {
|
@@ -57512,12 +57632,12 @@ class XrplApi {
|
|
57512
57632
|
}
|
57513
57633
|
|
57514
57634
|
async getAccountInfo(address) {
|
57515
|
-
const resp = (await this.#
|
57635
|
+
const resp = (await this.#handleClientRequest({ command: 'account_info', account: address }));
|
57516
57636
|
return resp?.result?.account_data;
|
57517
57637
|
}
|
57518
57638
|
|
57519
57639
|
async getServerDefinition() {
|
57520
|
-
const resp = (await this.#
|
57640
|
+
const resp = (await this.#handleClientRequest({ command: 'server_definitions' }));
|
57521
57641
|
return resp?.result;
|
57522
57642
|
}
|
57523
57643
|
|
@@ -57561,7 +57681,7 @@ class XrplApi {
|
|
57561
57681
|
|
57562
57682
|
async getLedgerEntry(index, options) {
|
57563
57683
|
try {
|
57564
|
-
const resp = (await this.#
|
57684
|
+
const resp = (await this.#handleClientRequest({ command: 'ledger_entry', index: index, ledger_index: "validated", ...options }));
|
57565
57685
|
return resp?.result?.node;
|
57566
57686
|
|
57567
57687
|
} catch (e) {
|
@@ -57572,13 +57692,13 @@ class XrplApi {
|
|
57572
57692
|
}
|
57573
57693
|
|
57574
57694
|
async getTxnInfo(txnHash, options) {
|
57575
|
-
const resp = (await this.#
|
57695
|
+
const resp = (await this.#handleClientRequest({ command: 'tx', transaction: txnHash, binary: false, ...options }));
|
57576
57696
|
return resp?.result;
|
57577
57697
|
}
|
57578
57698
|
|
57579
57699
|
async subscribeToAddress(address, handler) {
|
57580
57700
|
this.#addressSubscriptions.push({ address: address, handler: handler });
|
57581
|
-
await this.#
|
57701
|
+
await this.#handleClientRequest({ command: 'subscribe', accounts: [address] });
|
57582
57702
|
}
|
57583
57703
|
|
57584
57704
|
async unsubscribeFromAddress(address, handler) {
|
@@ -57587,16 +57707,16 @@ class XrplApi {
|
|
57587
57707
|
if (sub.address === address && sub.handler === handler)
|
57588
57708
|
this.#addressSubscriptions.splice(i, 1);
|
57589
57709
|
}
|
57590
|
-
await this.#
|
57710
|
+
await this.#handleClientRequest({ command: 'unsubscribe', accounts: [address] });
|
57591
57711
|
}
|
57592
57712
|
|
57593
57713
|
async getTransactionFee(txBlob) {
|
57594
|
-
const fees = await this.#
|
57714
|
+
const fees = await this.#handleClientRequest({ command: 'fee', tx_blob: txBlob });
|
57595
57715
|
return fees?.result?.drops?.base_fee;
|
57596
57716
|
}
|
57597
57717
|
|
57598
57718
|
async #subscribeToStream(streamName) {
|
57599
|
-
await this.#
|
57719
|
+
await this.#handleClientRequest({ command: 'subscribe', streams: [streamName] });
|
57600
57720
|
}
|
57601
57721
|
|
57602
57722
|
/**
|
@@ -57612,7 +57732,9 @@ class XrplApi {
|
|
57612
57732
|
|
57613
57733
|
await new Promise(r => setTimeout(r, LEDGER_CLOSE_TIME));
|
57614
57734
|
|
57735
|
+
this.#isClientLocked = true;
|
57615
57736
|
const latestLedger = await this.#client.getLedgerIndex();
|
57737
|
+
this.#isClientLocked = false;
|
57616
57738
|
|
57617
57739
|
if (lastLedger < latestLedger) {
|
57618
57740
|
throw `The latest ledger sequence ${latestLedger} is greater than the transaction's LastLedgerSequence (${lastLedger}).\n` +
|
@@ -57679,7 +57801,7 @@ class XrplApi {
|
|
57679
57801
|
*/
|
57680
57802
|
async submitMultisignedAndWait(tx) {
|
57681
57803
|
tx.SigningPubKey = "";
|
57682
|
-
const submissionResult = await this.#
|
57804
|
+
const submissionResult = await this.#handleClientRequest({ command: 'submit_multisigned', tx_json: tx });
|
57683
57805
|
return await this.#prepareResponse(tx, submissionResult);
|
57684
57806
|
}
|
57685
57807
|
|
@@ -57690,7 +57812,7 @@ class XrplApi {
|
|
57690
57812
|
*/
|
57691
57813
|
async submitMultisigned(tx) {
|
57692
57814
|
tx.SigningPubKey = "";
|
57693
|
-
return await this.#
|
57815
|
+
return await this.#handleClientRequest({ command: 'submit_multisigned', tx_json: tx });
|
57694
57816
|
}
|
57695
57817
|
|
57696
57818
|
/**
|
@@ -57699,7 +57821,7 @@ class XrplApi {
|
|
57699
57821
|
* @returns response object of the validated transaction.
|
57700
57822
|
*/
|
57701
57823
|
async submitAndWait(tx, tx_blob) {
|
57702
|
-
const submissionResult = await this.#
|
57824
|
+
const submissionResult = await this.#handleClientRequest({ command: 'submit', tx_blob: tx_blob });
|
57703
57825
|
return await this.#prepareResponse(tx, submissionResult);
|
57704
57826
|
}
|
57705
57827
|
|
@@ -57709,7 +57831,7 @@ class XrplApi {
|
|
57709
57831
|
* @returns response object of the submitted transaction.
|
57710
57832
|
*/
|
57711
57833
|
async submit(tx_blob) {
|
57712
|
-
return await this.#
|
57834
|
+
return await this.#handleClientRequest({ command: 'submit', tx_blob: tx_blob });
|
57713
57835
|
}
|
57714
57836
|
|
57715
57837
|
/**
|
@@ -57809,6 +57931,14 @@ module.exports = {
|
|
57809
57931
|
XrplHelpers
|
57810
57932
|
}
|
57811
57933
|
|
57934
|
+
/***/ }),
|
57935
|
+
|
57936
|
+
/***/ 4626:
|
57937
|
+
/***/ ((module) => {
|
57938
|
+
|
57939
|
+
module.exports = eval("require")("./resources/definitions.json");
|
57940
|
+
|
57941
|
+
|
57812
57942
|
/***/ }),
|
57813
57943
|
|
57814
57944
|
/***/ 9491:
|
@@ -57891,14 +58021,6 @@ module.exports = require("node:crypto");
|
|
57891
58021
|
|
57892
58022
|
/***/ }),
|
57893
58023
|
|
57894
|
-
/***/ 604:
|
57895
|
-
/***/ ((module) => {
|
57896
|
-
|
57897
|
-
"use strict";
|
57898
|
-
module.exports = require("node:dns");
|
57899
|
-
|
57900
|
-
/***/ }),
|
57901
|
-
|
57902
58024
|
/***/ 2037:
|
57903
58025
|
/***/ ((module) => {
|
57904
58026
|
|
package/package.json
CHANGED
Binary file
|
Binary file
|