evernode-js-client 0.6.39 → 0.6.41
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.
|
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.
|
|
9192
|
+
module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi1.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.
|
|
38324
|
+
module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi.node");
|
|
38325
38325
|
} catch (e) {
|
|
38326
38326
|
module.exports = __nccwpck_require__(9372);
|
|
38327
38327
|
}
|
|
@@ -59814,9 +59814,13 @@ class BaseEvernodeClient {
|
|
|
59814
59814
|
else if (!tx)
|
|
59815
59815
|
console.log('handleEvernodeEvent: Invalid transaction.');
|
|
59816
59816
|
else {
|
|
59817
|
-
|
|
59818
|
-
|
|
59819
|
-
this.
|
|
59817
|
+
try {
|
|
59818
|
+
const ev = await this.extractEvernodeEvent(tx);
|
|
59819
|
+
if (ev && this.#watchEvents.find(e => e === ev.name))
|
|
59820
|
+
this.events.emit(ev.name, ev.data);
|
|
59821
|
+
} catch (e) {
|
|
59822
|
+
console.log("Error occurred while handling Evernode events", e)
|
|
59823
|
+
}
|
|
59820
59824
|
}
|
|
59821
59825
|
}
|
|
59822
59826
|
|
|
@@ -60989,7 +60993,7 @@ const VOTE_VALIDATION_ERR = "VOTE_VALIDATION_ERR";
|
|
|
60989
60993
|
const IPV6_FAMILY = 6;
|
|
60990
60994
|
|
|
60991
60995
|
const MAX_HOST_LEDGER_OFFSET = 30;
|
|
60992
|
-
const TX_RETRY_INTERVAL =
|
|
60996
|
+
const TX_RETRY_INTERVAL = 10000;
|
|
60993
60997
|
|
|
60994
60998
|
class HostClient extends BaseEvernodeClient {
|
|
60995
60999
|
|
|
@@ -63572,17 +63576,19 @@ class StateHelpers {
|
|
|
63572
63576
|
}
|
|
63573
63577
|
}
|
|
63574
63578
|
else if (Buffer.from(HookStateKeys.REWARD_INFO, 'hex').compare(stateKey) === 0) {
|
|
63579
|
+
let value = {
|
|
63580
|
+
epoch: stateData.readUInt8(EPOCH_OFFSET),
|
|
63581
|
+
savedMoment: stateData.readUInt32LE(SAVED_MOMENT_OFFSET),
|
|
63582
|
+
prevMomentActiveHostCount: stateData.readUInt32LE(PREV_MOMENT_ACTIVE_HOST_COUNT_OFFSET),
|
|
63583
|
+
curMomentActiveHostCount: stateData.readUInt32LE(CUR_MOMENT_ACTIVE_HOST_COUNT_OFFSET),
|
|
63584
|
+
epochPool: XflHelpers.toString(stateData.readBigInt64LE(EPOCH_POOL_OFFSET)),
|
|
63585
|
+
};
|
|
63586
|
+
if (stateData.length > HOST_MAX_LEASE_AMOUNT_OFFSET)
|
|
63587
|
+
value.hostMaxLeaseAmount = XflHelpers.toString(stateData.readBigInt64LE(HOST_MAX_LEASE_AMOUNT_OFFSET));
|
|
63575
63588
|
return {
|
|
63576
63589
|
type: this.StateTypes.SIGLETON,
|
|
63577
63590
|
key: hexKey,
|
|
63578
|
-
value:
|
|
63579
|
-
epoch: stateData.readUInt8(EPOCH_OFFSET),
|
|
63580
|
-
savedMoment: stateData.readUInt32LE(SAVED_MOMENT_OFFSET),
|
|
63581
|
-
prevMomentActiveHostCount: stateData.readUInt32LE(PREV_MOMENT_ACTIVE_HOST_COUNT_OFFSET),
|
|
63582
|
-
curMomentActiveHostCount: stateData.readUInt32LE(CUR_MOMENT_ACTIVE_HOST_COUNT_OFFSET),
|
|
63583
|
-
epochPool: XflHelpers.toString(stateData.readBigInt64LE(EPOCH_POOL_OFFSET)),
|
|
63584
|
-
hostMaxLeaseAmount: XflHelpers.toString(stateData.readBigInt64LE(HOST_MAX_LEASE_AMOUNT_OFFSET))
|
|
63585
|
-
}
|
|
63591
|
+
value: value
|
|
63586
63592
|
}
|
|
63587
63593
|
}
|
|
63588
63594
|
else if (Buffer.from(HookStateKeys.MAX_TOLERABLE_DOWNTIME, 'hex').compare(stateKey) === 0) {
|
|
@@ -64977,7 +64983,13 @@ const API_REQ_TYPE = {
|
|
|
64977
64983
|
TRANSACTIONS: 'transactions'
|
|
64978
64984
|
}
|
|
64979
64985
|
|
|
64980
|
-
const
|
|
64986
|
+
const RESPONSE_WATCH_TIMEOUT = 1000
|
|
64987
|
+
const NETWORK_MODES = {
|
|
64988
|
+
INSUFFICIENT_NETWORK_MODE: 'InsufficientNetworkMode'
|
|
64989
|
+
}
|
|
64990
|
+
|
|
64991
|
+
const FUNCTIONING_SERVER_STATES = ['full', 'validating', 'proposing']
|
|
64992
|
+
const LEDGER_DESYNC_TIME = 20000
|
|
64981
64993
|
|
|
64982
64994
|
class XrplApi {
|
|
64983
64995
|
|
|
@@ -65050,6 +65062,12 @@ class XrplApi {
|
|
|
65050
65062
|
|
|
65051
65063
|
if (!client.isConnected())
|
|
65052
65064
|
await client.connect();
|
|
65065
|
+
|
|
65066
|
+
const resp = await client.request({ command: 'server_state', ledger_index: "current" });
|
|
65067
|
+
const serverState = resp?.result?.state?.server_state;
|
|
65068
|
+
|
|
65069
|
+
if (!FUNCTIONING_SERVER_STATES.includes(serverState))
|
|
65070
|
+
throw "Client might have functioning issues."
|
|
65053
65071
|
}
|
|
65054
65072
|
|
|
65055
65073
|
async #initEventListeners(client) {
|
|
@@ -65085,56 +65103,75 @@ class XrplApi {
|
|
|
65085
65103
|
}
|
|
65086
65104
|
});
|
|
65087
65105
|
|
|
65106
|
+
let ledgerTimeout;
|
|
65107
|
+
|
|
65088
65108
|
client.on('ledgerClosed', (ledger) => {
|
|
65109
|
+
if (ledgerTimeout) {
|
|
65110
|
+
clearTimeout(ledgerTimeout);
|
|
65111
|
+
}
|
|
65112
|
+
|
|
65113
|
+
ledgerTimeout = setTimeout(async () => {
|
|
65114
|
+
let serverState = await this.getServerState();
|
|
65115
|
+
|
|
65116
|
+
if (!FUNCTIONING_SERVER_STATES.includes(serverState)) {
|
|
65117
|
+
this.#events.emit(XrplApiEvents.SERVER_DESYNCED, { "event_type": "on_alert", "server_state": serverState });
|
|
65118
|
+
}
|
|
65119
|
+
clearTimeout(ledgerTimeout);
|
|
65120
|
+
}, LEDGER_DESYNC_TIME);
|
|
65121
|
+
|
|
65089
65122
|
this.ledgerIndex = ledger.ledger_index;
|
|
65090
65123
|
this.#events.emit(XrplApiEvents.LEDGER, ledger);
|
|
65091
65124
|
});
|
|
65092
65125
|
|
|
65093
65126
|
client.on("transaction", async (data) => {
|
|
65094
|
-
|
|
65095
|
-
|
|
65096
|
-
|
|
65097
|
-
|
|
65098
|
-
|
|
65099
|
-
const
|
|
65100
|
-
|
|
65101
|
-
|
|
65102
|
-
|
|
65103
|
-
|
|
65104
|
-
|
|
65105
|
-
|
|
65106
|
-
|
|
65107
|
-
|
|
65108
|
-
|
|
65109
|
-
|
|
65110
|
-
|
|
65127
|
+
try {
|
|
65128
|
+
if (data.validated) {
|
|
65129
|
+
// NFTokenAcceptOffer transactions does not contain a Destination. So we check whether the accepted offer is created by which subscribed account
|
|
65130
|
+
if (data.transaction.TransactionType === 'URITokenBuy') {
|
|
65131
|
+
// We take all the offers created by subscribed accounts in previous ledger until we get the respective offer.
|
|
65132
|
+
for (const subscription of this.#addressSubscriptions) {
|
|
65133
|
+
const acc = new XrplAccount(subscription.address, null, { xrplApi: this });
|
|
65134
|
+
// Here we access the offers that were there in this account based on the given ledger index.
|
|
65135
|
+
const offers = await acc.getURITokens({ ledger_index: data.ledger_index - 1 });
|
|
65136
|
+
// Filter out the matching URI token offer for the scenario.
|
|
65137
|
+
const offer = offers.find(o => o.index === data.transaction.URITokenID && o.Amount);
|
|
65138
|
+
// When we find the respective offer. We populate the destination and offer info and then we break the loop.
|
|
65139
|
+
if (offer) {
|
|
65140
|
+
// We populate some sell offer properties to the transaction to be sent with the event.
|
|
65141
|
+
data.transaction.Destination = subscription.address;
|
|
65142
|
+
// Replace the offer with the found offer object.
|
|
65143
|
+
data.transaction.URITokenSellOffer = offer;
|
|
65144
|
+
break;
|
|
65145
|
+
}
|
|
65111
65146
|
}
|
|
65112
65147
|
}
|
|
65113
|
-
}
|
|
65114
|
-
|
|
65115
|
-
const matches = this.#addressSubscriptions.filter(s => s.address === data.transaction.Destination); // Only incoming transactions.
|
|
65116
|
-
if (matches.length > 0) {
|
|
65117
|
-
const tx = {
|
|
65118
|
-
LedgerHash: data.ledger_hash,
|
|
65119
|
-
LedgerIndex: data.ledger_index,
|
|
65120
|
-
...data.transaction
|
|
65121
|
-
};
|
|
65122
65148
|
|
|
65123
|
-
|
|
65124
|
-
|
|
65125
|
-
|
|
65126
|
-
|
|
65127
|
-
|
|
65128
|
-
|
|
65129
|
-
|
|
65130
|
-
|
|
65131
|
-
|
|
65132
|
-
|
|
65133
|
-
|
|
65134
|
-
|
|
65135
|
-
|
|
65149
|
+
const matches = this.#addressSubscriptions.filter(s => s.address === data.transaction.Destination); // Only incoming transactions.
|
|
65150
|
+
if (matches.length > 0) {
|
|
65151
|
+
const tx = {
|
|
65152
|
+
LedgerHash: data.ledger_hash,
|
|
65153
|
+
LedgerIndex: data.ledger_index,
|
|
65154
|
+
...data.transaction
|
|
65155
|
+
};
|
|
65156
|
+
|
|
65157
|
+
if (data.meta?.delivered_amount)
|
|
65158
|
+
tx.DeliveredAmount = data.meta.delivered_amount;
|
|
65159
|
+
|
|
65160
|
+
// Create an object copy. Otherwise xrpl client will mutate the transaction object,
|
|
65161
|
+
const eventName = tx.TransactionType.toLowerCase();
|
|
65162
|
+
// Emit the event only for successful transactions, Otherwise emit error.
|
|
65163
|
+
if (data.engine_result === "tesSUCCESS") {
|
|
65164
|
+
tx.Memos = TransactionHelper.deserializeMemos(tx.Memos);
|
|
65165
|
+
tx.HookParameters = TransactionHelper.deserializeHookParams(tx.HookParameters);
|
|
65166
|
+
matches.forEach(s => s.handler(eventName, tx));
|
|
65167
|
+
}
|
|
65168
|
+
else {
|
|
65169
|
+
matches.forEach(s => s.handler(eventName, null, data.engine_result_message));
|
|
65170
|
+
}
|
|
65136
65171
|
}
|
|
65137
65172
|
}
|
|
65173
|
+
} catch (e) {
|
|
65174
|
+
console.log("Error occurred while listening to transactions.", e)
|
|
65138
65175
|
}
|
|
65139
65176
|
});
|
|
65140
65177
|
}
|
|
@@ -65296,6 +65333,9 @@ class XrplApi {
|
|
|
65296
65333
|
}
|
|
65297
65334
|
catch (e) {
|
|
65298
65335
|
this.#releaseConnection();
|
|
65336
|
+
if (e?.data?.error_message === NETWORK_MODES.INSUFFICIENT_NETWORK_MODE) {
|
|
65337
|
+
this.#events.emit(XrplApiEvents.SERVER_DESYNCED, { "event_type": "on_error", "error_code": e.data?.error_code, "error_message": e.data.error_message });
|
|
65338
|
+
}
|
|
65299
65339
|
throw e;
|
|
65300
65340
|
}
|
|
65301
65341
|
}
|
|
@@ -65385,6 +65425,11 @@ class XrplApi {
|
|
|
65385
65425
|
}
|
|
65386
65426
|
}
|
|
65387
65427
|
|
|
65428
|
+
async getServerState(ledgerIdx = "current") {
|
|
65429
|
+
const resp = (await this.#handleClientRequest({ command: 'server_state', ledger_index: ledgerIdx }));
|
|
65430
|
+
return resp?.result?.state?.server_state;
|
|
65431
|
+
}
|
|
65432
|
+
|
|
65388
65433
|
async getAccountInfo(address) {
|
|
65389
65434
|
const resp = (await this.#handleClientRequest({ command: 'account_info', account: address }));
|
|
65390
65435
|
return resp?.result?.account_data;
|
|
@@ -65511,7 +65556,7 @@ class XrplApi {
|
|
|
65511
65556
|
if (lastLedger == null)
|
|
65512
65557
|
throw 'Transaction must contain a LastLedgerSequence value for reliable submission.';
|
|
65513
65558
|
|
|
65514
|
-
await new Promise(r => setTimeout(r,
|
|
65559
|
+
await new Promise(r => setTimeout(r, RESPONSE_WATCH_TIMEOUT));
|
|
65515
65560
|
|
|
65516
65561
|
const latestLedger = await this.#getLedgerIndex();
|
|
65517
65562
|
|
|
@@ -65643,7 +65688,8 @@ const XrplApiEvents = {
|
|
|
65643
65688
|
NFT_OFFER_CREATE: 'nftokencreateoffer',
|
|
65644
65689
|
NFT_OFFER_ACCEPT: 'nftokenacceptoffer',
|
|
65645
65690
|
URI_TOKEN_CREATE_SELL_OFFER: 'uritokencreateselloffer', // For Transfers
|
|
65646
|
-
URI_TOKEN_BUY: 'uritokenbuy' // For Acquires
|
|
65691
|
+
URI_TOKEN_BUY: 'uritokenbuy', // For Acquires
|
|
65692
|
+
SERVER_DESYNCED: 'desynced'
|
|
65647
65693
|
}
|
|
65648
65694
|
|
|
65649
65695
|
const XrplConstants = {
|
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.41",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"elliptic": "6.5.4",
|
|
12
12
|
"libsodium-wrappers": "0.7.10",
|
|
Binary file
|
|
Binary file
|