@bithomp/xrpl-api 3.4.4 → 3.4.6

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.
@@ -16,6 +16,7 @@ exports.getConstructorName = getConstructorName;
16
16
  const lodash_1 = __importDefault(require("lodash"));
17
17
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
18
18
  const errors_1 = require("./errors");
19
+ const index_1 = require("./index");
19
20
  function signum(num) {
20
21
  return num === 0 ? 0 : num > 0 ? 1 : -1;
21
22
  }
@@ -87,7 +88,7 @@ function dropsToXrp(drops) {
87
88
  if (!drops.match(/^-?[0-9]+$/)) {
88
89
  throw new errors_1.ValidationError(`dropsToXrp: failed sanity check - value '${drops}', does not match (^-?[0-9]+$).`);
89
90
  }
90
- return new bignumber_js_1.default(drops).dividedBy(1000000.0).toString(10);
91
+ return new bignumber_js_1.default(drops).dividedBy(index_1.dropsInXRP).toString(10);
91
92
  }
92
93
  function xrpToDrops(xrp) {
93
94
  if (typeof xrp === "string") {
@@ -110,7 +111,7 @@ function xrpToDrops(xrp) {
110
111
  if (fraction.length > 6) {
111
112
  throw new errors_1.ValidationError(`xrpToDrops: value '${xrp}' has too many decimal places.`);
112
113
  }
113
- return new bignumber_js_1.default(xrp).times(1000000.0).integerValue(bignumber_js_1.default.ROUND_FLOOR).toString(10);
114
+ return new bignumber_js_1.default(xrp).times(index_1.dropsInXRP).integerValue(bignumber_js_1.default.ROUND_FLOOR).toString(10);
114
115
  }
115
116
  function removeUndefined(obj) {
116
117
  return lodash_1.default.omitBy(obj, (value) => value == null);
@@ -32,7 +32,7 @@ declare class Connection extends EventEmitter {
32
32
  types: string[];
33
33
  latency: LatencyInfo[];
34
34
  readonly logger?: any;
35
- readonly timeout?: number;
35
+ readonly timeout: number;
36
36
  readonly connectionTimeout: number;
37
37
  readonly hash?: string;
38
38
  private onlineSince;
@@ -49,6 +49,7 @@ declare class Connection extends EventEmitter {
49
49
  connect(): Promise<void>;
50
50
  disconnect(): Promise<void>;
51
51
  request(request: Request, options?: any): Promise<Response | any>;
52
+ _request(request: Request, options?: any): Promise<Response | any>;
52
53
  submit(transaction: string): Promise<Response | any>;
53
54
  isConnected(): boolean;
54
55
  getOnlinePeriodMs(): number | null;
package/lib/connection.js CHANGED
@@ -45,7 +45,7 @@ const common_1 = require("./common");
45
45
  const utils_1 = require("./common/utils");
46
46
  const XRPLConnection = __importStar(require("xrpl/dist/npm/client/connection"));
47
47
  const RECONNECT_TIMEOUT = 1000 * 5;
48
- const LEDGER_CLOSED_TIMEOUT = 1000 * 15;
48
+ const LEDGER_CLOSED_TIMEOUT = 1000 * 20;
49
49
  const SERVER_INFO_UPDATE_INTERVAL = 1000 * 60 * 5;
50
50
  const AVAILABLE_LEDGER_INDEX_WINDOW = 1000;
51
51
  exports.DEFAULT_API_VERSION = xrpl_1.RIPPLED_API_V1;
@@ -64,7 +64,7 @@ class Connection extends events_1.EventEmitter {
64
64
  this.updateTypes();
65
65
  this.client = null;
66
66
  this.logger = options.logger;
67
- this.timeout = options.timeout;
67
+ this.timeout = options.timeout || LEDGER_CLOSED_TIMEOUT;
68
68
  this.connectionTimeout = options.connectionTimeout || RECONNECT_TIMEOUT;
69
69
  this.hash = crypto_1.default.createHash("sha256").update(url).digest("hex");
70
70
  if (typeof options.networkID === "number") {
@@ -112,6 +112,22 @@ class Connection extends events_1.EventEmitter {
112
112
  clearTimeout(this.connectionTimer);
113
113
  }
114
114
  async request(request, options) {
115
+ const result = await this._request(request, options);
116
+ if (result?.error === "timeout") {
117
+ const timeouts = this.latency.filter((info) => info.delta >= this.timeout).length;
118
+ if (timeouts >= 3) {
119
+ this.logger?.debug({
120
+ service: "Bithomp::XRPL::Connection",
121
+ function: "request",
122
+ url: this.url,
123
+ error: `Too many timeouts (${timeouts}) in last ${this.latency.length} requests, reconnecting...`,
124
+ });
125
+ this.reconnect();
126
+ }
127
+ }
128
+ return result;
129
+ }
130
+ async _request(request, options) {
115
131
  try {
116
132
  if (options?.skip_subscription_update !== true &&
117
133
  (request.command === "subscribe" || request.command === "unsubscribe")) {
@@ -137,7 +153,7 @@ class Connection extends events_1.EventEmitter {
137
153
  return response;
138
154
  }
139
155
  catch (err) {
140
- this.updateLatency(RECONNECT_TIMEOUT);
156
+ this.updateLatency(err.name === "TimeoutError" ? this.timeout : this.connectionTimeout);
141
157
  this.logger?.debug({
142
158
  service: "Bithomp::XRPL::Connection",
143
159
  function: "request",
@@ -160,7 +176,6 @@ class Connection extends events_1.EventEmitter {
160
176
  return await this.request({ command: "submit", tx_blob: transaction });
161
177
  }
162
178
  catch (err) {
163
- this.updateLatency(1000);
164
179
  this.logger?.debug({
165
180
  service: "Bithomp::XRPL::Connection",
166
181
  function: "submit",
@@ -333,12 +333,21 @@ function counterpartyFilter(options, transaction) {
333
333
  if (transaction.tx.Destination === options.counterparty) {
334
334
  return true;
335
335
  }
336
+ if (transaction.tx.Delegate === options.counterparty) {
337
+ return true;
338
+ }
336
339
  if (transaction.tx.Amount?.issuer === options.counterparty) {
337
340
  return true;
338
341
  }
339
342
  if (transaction.tx.SendMax?.issuer === options.counterparty) {
340
343
  return true;
341
344
  }
345
+ if (typeof transaction.tx.TakerGets === "object" && transaction.tx.TakerGets?.issuer === options.counterparty) {
346
+ return true;
347
+ }
348
+ if (typeof transaction.tx.TakerPays === "object" && transaction.tx.TakerPays?.issuer === options.counterparty) {
349
+ return true;
350
+ }
342
351
  if (transaction.tx.LimitAmount?.issuer === options.counterparty) {
343
352
  return true;
344
353
  }
@@ -48,7 +48,6 @@ function parseNFTokenBurn(tx) {
48
48
  signer: (0, regular_key_1.parseSignerRegularKey)(tx),
49
49
  delegate: (0, delegate_1.parseDelegate)(tx),
50
50
  source: (0, source_1.parseSource)(tx),
51
- account: tx.Account,
52
51
  nftokenID: tx.NFTokenID,
53
52
  emittedDetails: (0, emit_details_1.parseEmittedDetails)(tx),
54
53
  memos: (0, memos_1.parseMemos)(tx),
@@ -23,7 +23,6 @@ export interface NFTokenOfferFlagsKeysInterface {
23
23
  sellToken?: boolean;
24
24
  }
25
25
  export type FormattedNFTokenBurnSpecification = {
26
- account: string;
27
26
  nftokenID: string;
28
27
  } & FormattedBaseSpecification;
29
28
  export type FormattedNFTokenMintSpecification = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bithomp/xrpl-api",
3
- "version": "3.4.4",
3
+ "version": "3.4.6",
4
4
  "description": "A Bithomp JavaScript/TypeScript library for interacting with the XRP Ledger",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -43,7 +43,7 @@
43
43
  "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
44
44
  "lint": "eslint",
45
45
  "prepare": "npm run build",
46
- "prepublishOnly": "npm test && npm run lint",
46
+ "-prepublishOnly": "npm test && npm run lint",
47
47
  "preversion": "npm run lint",
48
48
  "version": "npm run format && git add -A src",
49
49
  "postversion": "git push && git push --tags"
@@ -72,9 +72,9 @@
72
72
  "@types/node": "^22.15.21",
73
73
  "@typescript-eslint/eslint-plugin": "^8.38.0",
74
74
  "@typescript-eslint/parser": "^8.38.0",
75
- "chai": "^4.5.0",
76
- "chai-as-promised": "^7.1.2",
77
- "eslint": "^9.32.0",
75
+ "chai": "^6.0.1",
76
+ "chai-as-promised": "^8.0.2",
77
+ "eslint": "^9.34.0",
78
78
  "eslint-config-prettier": "^10.1.8",
79
79
  "eslint-plugin-chai-friendly": "^1.1.0",
80
80
  "eslint-plugin-import": "^2.32.0",