evernode-js-client 0.6.40 → 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.napi.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.napi1.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
- const ev = await this.extractEvernodeEvent(tx);
59818
- if (ev && this.#watchEvents.find(e => e === ev.name))
59819
- this.events.emit(ev.name, ev.data);
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 = 3000;
60996
+ const TX_RETRY_INTERVAL = 10000;
60993
60997
 
60994
60998
  class HostClient extends BaseEvernodeClient {
60995
60999
 
@@ -64979,7 +64983,13 @@ const API_REQ_TYPE = {
64979
64983
  TRANSACTIONS: 'transactions'
64980
64984
  }
64981
64985
 
64982
- const LEDGER_CLOSE_TIME = 1000
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
64983
64993
 
64984
64994
  class XrplApi {
64985
64995
 
@@ -65052,6 +65062,12 @@ class XrplApi {
65052
65062
 
65053
65063
  if (!client.isConnected())
65054
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."
65055
65071
  }
65056
65072
 
65057
65073
  async #initEventListeners(client) {
@@ -65087,56 +65103,75 @@ class XrplApi {
65087
65103
  }
65088
65104
  });
65089
65105
 
65106
+ let ledgerTimeout;
65107
+
65090
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
+
65091
65122
  this.ledgerIndex = ledger.ledger_index;
65092
65123
  this.#events.emit(XrplApiEvents.LEDGER, ledger);
65093
65124
  });
65094
65125
 
65095
65126
  client.on("transaction", async (data) => {
65096
- if (data.validated) {
65097
- // NFTokenAcceptOffer transactions does not contain a Destination. So we check whether the accepted offer is created by which subscribed account
65098
- if (data.transaction.TransactionType === 'URITokenBuy') {
65099
- // We take all the offers created by subscribed accounts in previous ledger until we get the respective offer.
65100
- for (const subscription of this.#addressSubscriptions) {
65101
- const acc = new XrplAccount(subscription.address, null, { xrplApi: this });
65102
- // Here we access the offers that were there in this account based on the given ledger index.
65103
- const offers = await acc.getURITokens({ ledger_index: data.ledger_index - 1 });
65104
- // Filter out the matching URI token offer for the scenario.
65105
- const offer = offers.find(o => o.index === data.transaction.URITokenID && o.Amount);
65106
- // When we find the respective offer. We populate the destination and offer info and then we break the loop.
65107
- if (offer) {
65108
- // We populate some sell offer properties to the transaction to be sent with the event.
65109
- data.transaction.Destination = subscription.address;
65110
- // Replace the offer with the found offer object.
65111
- data.transaction.URITokenSellOffer = offer;
65112
- break;
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
+ }
65113
65146
  }
65114
65147
  }
65115
- }
65116
65148
 
65117
- const matches = this.#addressSubscriptions.filter(s => s.address === data.transaction.Destination); // Only incoming transactions.
65118
- if (matches.length > 0) {
65119
- const tx = {
65120
- LedgerHash: data.ledger_hash,
65121
- LedgerIndex: data.ledger_index,
65122
- ...data.transaction
65123
- };
65124
-
65125
- if (data.meta?.delivered_amount)
65126
- tx.DeliveredAmount = data.meta.delivered_amount;
65127
-
65128
- // Create an object copy. Otherwise xrpl client will mutate the transaction object,
65129
- const eventName = tx.TransactionType.toLowerCase();
65130
- // Emit the event only for successful transactions, Otherwise emit error.
65131
- if (data.engine_result === "tesSUCCESS") {
65132
- tx.Memos = TransactionHelper.deserializeMemos(tx.Memos);
65133
- tx.HookParameters = TransactionHelper.deserializeHookParams(tx.HookParameters);
65134
- matches.forEach(s => s.handler(eventName, tx));
65135
- }
65136
- else {
65137
- matches.forEach(s => s.handler(eventName, null, data.engine_result_message));
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
+ }
65138
65171
  }
65139
65172
  }
65173
+ } catch (e) {
65174
+ console.log("Error occurred while listening to transactions.", e)
65140
65175
  }
65141
65176
  });
65142
65177
  }
@@ -65298,6 +65333,9 @@ class XrplApi {
65298
65333
  }
65299
65334
  catch (e) {
65300
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
+ }
65301
65339
  throw e;
65302
65340
  }
65303
65341
  }
@@ -65387,6 +65425,11 @@ class XrplApi {
65387
65425
  }
65388
65426
  }
65389
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
+
65390
65433
  async getAccountInfo(address) {
65391
65434
  const resp = (await this.#handleClientRequest({ command: 'account_info', account: address }));
65392
65435
  return resp?.result?.account_data;
@@ -65513,7 +65556,7 @@ class XrplApi {
65513
65556
  if (lastLedger == null)
65514
65557
  throw 'Transaction must contain a LastLedgerSequence value for reliable submission.';
65515
65558
 
65516
- await new Promise(r => setTimeout(r, LEDGER_CLOSE_TIME));
65559
+ await new Promise(r => setTimeout(r, RESPONSE_WATCH_TIMEOUT));
65517
65560
 
65518
65561
  const latestLedger = await this.#getLedgerIndex();
65519
65562
 
@@ -65645,7 +65688,8 @@ const XrplApiEvents = {
65645
65688
  NFT_OFFER_CREATE: 'nftokencreateoffer',
65646
65689
  NFT_OFFER_ACCEPT: 'nftokenacceptoffer',
65647
65690
  URI_TOKEN_CREATE_SELL_OFFER: 'uritokencreateselloffer', // For Transfers
65648
- URI_TOKEN_BUY: 'uritokenbuy' // For Acquires
65691
+ URI_TOKEN_BUY: 'uritokenbuy', // For Acquires
65692
+ SERVER_DESYNCED: 'desynced'
65649
65693
  }
65650
65694
 
65651
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.40",
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