evernode-js-client 0.6.40 → 0.6.42

Sign up to get free protection for your applications and to get access to all the features.
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,10 +65062,17 @@ 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) {
65058
65074
  // First remove all the listeners.
65075
+ let ledgerTimeout;
65059
65076
  try {
65060
65077
  await client.removeAllListeners();
65061
65078
  }
@@ -65085,58 +65102,82 @@ class XrplApi {
65085
65102
  console.log("Error occurred while re-initializing", e)
65086
65103
  }
65087
65104
  }
65105
+ if (ledgerTimeout)
65106
+ clearTimeout(ledgerTimeout);
65088
65107
  });
65089
65108
 
65109
+
65090
65110
  client.on('ledgerClosed', (ledger) => {
65111
+ if (ledgerTimeout) {
65112
+ clearTimeout(ledgerTimeout);
65113
+ }
65114
+
65115
+ ledgerTimeout = setTimeout(async () => {
65116
+ try {
65117
+ let serverState = await this.getServerState();
65118
+ if (!FUNCTIONING_SERVER_STATES.includes(serverState)) {
65119
+ this.#events.emit(XrplApiEvents.SERVER_DESYNCED, { "event_type": "on_alert", "server_state": serverState });
65120
+ }
65121
+ } catch (e) {
65122
+ console.log("Error occurred while listening to server de-syncs.", e)
65123
+ } finally {
65124
+ clearTimeout(ledgerTimeout);
65125
+ }
65126
+ }, LEDGER_DESYNC_TIME);
65127
+
65091
65128
  this.ledgerIndex = ledger.ledger_index;
65092
65129
  this.#events.emit(XrplApiEvents.LEDGER, ledger);
65093
65130
  });
65094
65131
 
65095
65132
  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;
65133
+ try {
65134
+ if (data.validated) {
65135
+ // NFTokenAcceptOffer transactions does not contain a Destination. So we check whether the accepted offer is created by which subscribed account
65136
+ if (data.transaction.TransactionType === 'URITokenBuy') {
65137
+ // We take all the offers created by subscribed accounts in previous ledger until we get the respective offer.
65138
+ for (const subscription of this.#addressSubscriptions) {
65139
+ const acc = new XrplAccount(subscription.address, null, { xrplApi: this });
65140
+ // Here we access the offers that were there in this account based on the given ledger index.
65141
+ const offers = await acc.getURITokens({ ledger_index: data.ledger_index - 1 });
65142
+ // Filter out the matching URI token offer for the scenario.
65143
+ const offer = offers.find(o => o.index === data.transaction.URITokenID && o.Amount);
65144
+ // When we find the respective offer. We populate the destination and offer info and then we break the loop.
65145
+ if (offer) {
65146
+ // We populate some sell offer properties to the transaction to be sent with the event.
65147
+ data.transaction.Destination = subscription.address;
65148
+ // Replace the offer with the found offer object.
65149
+ data.transaction.URITokenSellOffer = offer;
65150
+ break;
65151
+ }
65113
65152
  }
65114
65153
  }
65115
- }
65116
-
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
65154
 
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));
65155
+ const matches = this.#addressSubscriptions.filter(s => s.address === data.transaction.Destination); // Only incoming transactions.
65156
+ if (matches.length > 0) {
65157
+ const tx = {
65158
+ LedgerHash: data.ledger_hash,
65159
+ LedgerIndex: data.ledger_index,
65160
+ ...data.transaction
65161
+ };
65162
+
65163
+ if (data.meta?.delivered_amount)
65164
+ tx.DeliveredAmount = data.meta.delivered_amount;
65165
+
65166
+ // Create an object copy. Otherwise xrpl client will mutate the transaction object,
65167
+ const eventName = tx.TransactionType.toLowerCase();
65168
+ // Emit the event only for successful transactions, Otherwise emit error.
65169
+ if (data.engine_result === "tesSUCCESS") {
65170
+ tx.Memos = TransactionHelper.deserializeMemos(tx.Memos);
65171
+ tx.HookParameters = TransactionHelper.deserializeHookParams(tx.HookParameters);
65172
+ matches.forEach(s => s.handler(eventName, tx));
65173
+ }
65174
+ else {
65175
+ matches.forEach(s => s.handler(eventName, null, data.engine_result_message));
65176
+ }
65138
65177
  }
65139
65178
  }
65179
+ } catch (e) {
65180
+ console.log("Error occurred while listening to transactions.", e)
65140
65181
  }
65141
65182
  });
65142
65183
  }
@@ -65298,6 +65339,9 @@ class XrplApi {
65298
65339
  }
65299
65340
  catch (e) {
65300
65341
  this.#releaseConnection();
65342
+ if (e?.data?.error_message === NETWORK_MODES.INSUFFICIENT_NETWORK_MODE) {
65343
+ this.#events.emit(XrplApiEvents.SERVER_DESYNCED, { "event_type": "on_error", "error_code": e.data?.error_code, "error_message": e.data.error_message });
65344
+ }
65301
65345
  throw e;
65302
65346
  }
65303
65347
  }
@@ -65387,6 +65431,11 @@ class XrplApi {
65387
65431
  }
65388
65432
  }
65389
65433
 
65434
+ async getServerState(ledgerIdx = "current") {
65435
+ const resp = (await this.#handleClientRequest({ command: 'server_state', ledger_index: ledgerIdx }));
65436
+ return resp?.result?.state?.server_state;
65437
+ }
65438
+
65390
65439
  async getAccountInfo(address) {
65391
65440
  const resp = (await this.#handleClientRequest({ command: 'account_info', account: address }));
65392
65441
  return resp?.result?.account_data;
@@ -65513,7 +65562,7 @@ class XrplApi {
65513
65562
  if (lastLedger == null)
65514
65563
  throw 'Transaction must contain a LastLedgerSequence value for reliable submission.';
65515
65564
 
65516
- await new Promise(r => setTimeout(r, LEDGER_CLOSE_TIME));
65565
+ await new Promise(r => setTimeout(r, RESPONSE_WATCH_TIMEOUT));
65517
65566
 
65518
65567
  const latestLedger = await this.#getLedgerIndex();
65519
65568
 
@@ -65645,7 +65694,8 @@ const XrplApiEvents = {
65645
65694
  NFT_OFFER_CREATE: 'nftokencreateoffer',
65646
65695
  NFT_OFFER_ACCEPT: 'nftokenacceptoffer',
65647
65696
  URI_TOKEN_CREATE_SELL_OFFER: 'uritokencreateselloffer', // For Transfers
65648
- URI_TOKEN_BUY: 'uritokenbuy' // For Acquires
65697
+ URI_TOKEN_BUY: 'uritokenbuy', // For Acquires
65698
+ SERVER_DESYNCED: 'desynced'
65649
65699
  }
65650
65700
 
65651
65701
  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.42",
10
10
  "dependencies": {
11
11
  "elliptic": "6.5.4",
12
12
  "libsodium-wrappers": "0.7.10",
Binary file
Binary file