@bithomp/xrpl-api 3.7.18 → 3.7.20

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.
@@ -49,6 +49,7 @@ const DEFAULT_LIMIT = 200;
49
49
  const MAX_LIMIT_WITH_FILTER = 20;
50
50
  const MAX_LIMIT_WITH_TAG = 3;
51
51
  const LIMIT_INCREASE_COUNT = 10;
52
+ const DEFAULT_TIMEOUT = 15000;
52
53
  async function getTransactions(account, options = { limit: DEFAULT_LIMIT }) {
53
54
  const { hash, marker } = (0, utils_1.parseMarker)(options.marker);
54
55
  options.marker = marker;
@@ -137,11 +138,17 @@ async function getTransactions(account, options = { limit: DEFAULT_LIMIT }) {
137
138
  result.bithompHash = connection.hash;
138
139
  return result;
139
140
  }
140
- async function findTransactionsExt(account, options = { limit: DEFAULT_LIMIT, timeout: 15000 }) {
141
+ async function findTransactionsExt(account, options = { limit: DEFAULT_LIMIT, timeout: DEFAULT_TIMEOUT }) {
141
142
  let transactions = [];
142
143
  let accountTransactionsError = null;
143
144
  const timeStart = new Date();
144
145
  const loadOptions = { ...options };
146
+ if (!loadOptions.limit || loadOptions.limit <= 0) {
147
+ loadOptions.limit = DEFAULT_LIMIT;
148
+ }
149
+ if (!loadOptions.timeout || loadOptions.timeout <= 0) {
150
+ loadOptions.timeout = DEFAULT_TIMEOUT;
151
+ }
145
152
  const formatted = loadOptions.legacy === true || loadOptions.formatted === true;
146
153
  loadOptions.binary = false;
147
154
  applyLimitOptions(loadOptions);
@@ -265,12 +272,12 @@ async function findTransactions(account, options = { limit: DEFAULT_LIMIT, timeo
265
272
  }
266
273
  function applyLimitOptions(options) {
267
274
  if (options.sourceTag > 0 || options.destinationTag > 0) {
268
- if (options.limit > MAX_LIMIT_WITH_TAG) {
275
+ if (!options.limit || options.limit > MAX_LIMIT_WITH_TAG) {
269
276
  options.limit = MAX_LIMIT_WITH_TAG;
270
277
  }
271
278
  }
272
279
  else if (options.types || options.initiated || options.counterparty) {
273
- if (options.limit > MAX_LIMIT_WITH_FILTER) {
280
+ if (!options.limit || options.limit > MAX_LIMIT_WITH_FILTER) {
274
281
  options.limit = MAX_LIMIT_WITH_FILTER;
275
282
  }
276
283
  }
@@ -1,8 +1,13 @@
1
1
  import { XrplDefinitionsBase } from "ripple-binary-codec";
2
2
  import { Connection } from "../connection";
3
+ import { ErrorResponse } from "../models/base_model";
3
4
  export interface GetFeeOptions {
4
5
  connection?: Connection;
5
6
  tx?: any;
6
7
  definitions?: XrplDefinitionsBase;
7
8
  }
9
+ export interface GetFeeDataResult {
10
+ fee: string | null;
11
+ }
12
+ export declare function getFeeData(options?: GetFeeOptions): Promise<GetFeeDataResult | ErrorResponse>;
8
13
  export declare function getFee(options?: GetFeeOptions): Promise<string | null>;
package/lib/ledger/fee.js CHANGED
@@ -36,12 +36,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getFeeData = getFeeData;
39
40
  exports.getFee = getFee;
40
41
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
41
42
  const ripple_binary_codec_1 = require("ripple-binary-codec");
42
43
  const Client = __importStar(require("../client"));
43
44
  const common_1 = require("../common");
44
- async function getFee(options = {}) {
45
+ async function getFeeData(options = {}) {
45
46
  const connection = options.connection || Client.findConnection();
46
47
  if (!connection) {
47
48
  throw new Error("There is no connection");
@@ -57,13 +58,42 @@ async function getFee(options = {}) {
57
58
  command: "fee",
58
59
  tx_blob: txBlob,
59
60
  });
61
+ if (!response) {
62
+ return {
63
+ status: "error",
64
+ error: "invalidResponse",
65
+ };
66
+ }
67
+ if (response.error) {
68
+ const { error, error_code, error_message, error_exception, status, validated } = response;
69
+ return (0, common_1.removeUndefined)({
70
+ error,
71
+ error_code,
72
+ error_message,
73
+ error_exception,
74
+ status,
75
+ validated,
76
+ });
77
+ }
60
78
  const openLedgerFee = response?.result?.drops?.open_ledger_fee;
61
79
  if (!openLedgerFee) {
62
- return null;
80
+ return {
81
+ status: "error",
82
+ error: "No open_ledger_fee data in response",
83
+ };
63
84
  }
64
85
  const fee = new bignumber_js_1.default(openLedgerFee)
65
86
  .multipliedBy(Client.feeCushion)
66
87
  .dividedBy(common_1.dropsInXRP)
67
88
  .decimalPlaces(6, bignumber_js_1.default.ROUND_UP);
68
- return fee.toString();
89
+ return {
90
+ fee: fee.toString(),
91
+ };
92
+ }
93
+ async function getFee(options = {}) {
94
+ const response = await getFeeData(options);
95
+ if ("fee" in response) {
96
+ return response.fee;
97
+ }
98
+ return null;
69
99
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bithomp/xrpl-api",
3
- "version": "3.7.18",
3
+ "version": "3.7.20",
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",
@@ -62,15 +62,15 @@
62
62
  "xrpl": "4.4.3"
63
63
  },
64
64
  "devDependencies": {
65
- "@eslint/eslintrc": "^3.3.1",
65
+ "@eslint/eslintrc": "^3.3.3",
66
66
  "@types/chai": "^5.2.3",
67
67
  "@types/chai-as-promised": "^8.0.2",
68
- "@types/lodash": "^4.17.20",
68
+ "@types/lodash": "^4.17.21",
69
69
  "@types/mocha": "^10.0.10",
70
70
  "@types/nconf": "^0.10.7",
71
71
  "@types/node": "^22.15.21",
72
- "@typescript-eslint/eslint-plugin": "^8.47.0",
73
- "@typescript-eslint/parser": "^8.47.0",
72
+ "@typescript-eslint/eslint-plugin": "^8.48.0",
73
+ "@typescript-eslint/parser": "^8.48.0",
74
74
  "chai": "^6.2.1",
75
75
  "chai-as-promised": "^8.0.2",
76
76
  "eslint": "^9.39.1",