@bithomp/xrpl-api 3.2.15 → 3.2.16

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.
@@ -1,3 +1,4 @@
1
- import { FormattedIssuedCurrencyAmount, FormattedIssuedMPTAmount } from "../../types";
2
- declare function parseDeliveredAmount(tx: any): FormattedIssuedCurrencyAmount | FormattedIssuedMPTAmount | undefined;
1
+ import { IssuedCurrencyAmount, FormattedIssuedCurrencyAmount, FormattedIssuedMPTAmount } from "../../types";
2
+ import { BalanceChanges } from "./balance_changes";
3
+ declare function parseDeliveredAmount(tx: any, balanceChanges: BalanceChanges): IssuedCurrencyAmount | FormattedIssuedCurrencyAmount | FormattedIssuedMPTAmount | undefined;
3
4
  export { parseDeliveredAmount };
@@ -4,41 +4,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseDeliveredAmount = parseDeliveredAmount;
7
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
8
+ const client_1 = require("../../client");
7
9
  const import_1 = require("../ledger/import");
8
10
  const amount_1 = __importDefault(require("../ledger/amount"));
9
- const utils_1 = require("../utils");
10
11
  const balance_changes_1 = require("./balance_changes");
11
- function parseDeliveredAmount(tx) {
12
- if (!["Import", "Payment"].includes(tx.TransactionType) || tx.meta.TransactionResult !== "tesSUCCESS") {
12
+ function parseDeliveredAmount(tx, balanceChanges) {
13
+ if (tx.meta.TransactionResult !== "tesSUCCESS") {
13
14
  return undefined;
14
15
  }
15
- if (tx.meta.delivered_amount && tx.meta.delivered_amount === "unavailable") {
16
- return undefined;
16
+ if (tx.TransactionType === "Payment") {
17
+ const txBalanceChanges = balanceChanges || (0, balance_changes_1.parseBalanceChanges)(tx.meta, (0, client_1.getNativeCurrency)());
18
+ if (txBalanceChanges) {
19
+ const account = tx.Destination;
20
+ const changes = txBalanceChanges[account];
21
+ if (changes) {
22
+ const positives = changes.filter((change) => change.value[0] !== "-");
23
+ if (positives.length === 1) {
24
+ return positives[0];
25
+ }
26
+ }
27
+ }
28
+ }
29
+ else if (tx.TransactionType === "CheckCash") {
30
+ const txBalanceChanges = balanceChanges || (0, balance_changes_1.parseBalanceChanges)(tx.meta, (0, client_1.getNativeCurrency)());
31
+ if (txBalanceChanges) {
32
+ const account = tx.Account;
33
+ const changes = txBalanceChanges[account];
34
+ if (changes) {
35
+ const positives = changes.filter((change) => change.value[0] !== "-");
36
+ if (positives.length === 1) {
37
+ return positives[0];
38
+ }
39
+ }
40
+ }
41
+ }
42
+ else if (tx.TransactionType === "Import") {
43
+ const txBalanceChanges = balanceChanges || (0, balance_changes_1.parseBalanceChanges)(tx.meta, (0, client_1.getNativeCurrency)());
44
+ const blob = (0, import_1.parseImportBlob)(tx.Blob);
45
+ if (typeof blob === "object") {
46
+ const account = blob.transaction.tx.Account;
47
+ const balanceChange = txBalanceChanges[account];
48
+ if (balanceChange && balanceChange.length === 1) {
49
+ return {
50
+ currency: balanceChange[0].currency,
51
+ value: new bignumber_js_1.default(balanceChange[0].value).abs().toString(),
52
+ };
53
+ }
54
+ }
17
55
  }
18
- if (tx.meta.delivered_amount) {
56
+ if (tx.meta.delivered_amount && tx.meta.delivered_amount !== "unavailable") {
19
57
  return (0, amount_1.default)(tx.meta.delivered_amount);
20
58
  }
21
59
  if (tx.meta.DeliveredAmount) {
22
60
  return (0, amount_1.default)(tx.meta.DeliveredAmount);
23
61
  }
24
- if (tx.Amount && !(0, utils_1.isPartialPayment)(tx)) {
25
- return (0, amount_1.default)(tx.Amount);
26
- }
27
- if (tx.TransactionType === "Import") {
28
- const balanceChanges = (0, balance_changes_1.parseBalanceChanges)(tx.meta);
29
- const blob = (0, import_1.parseImportBlob)(tx.Blob);
30
- if (typeof blob === "string") {
31
- return undefined;
32
- }
33
- const account = blob.transaction.tx.Account;
34
- const balanceChange = balanceChanges[account];
35
- if (!balanceChange || balanceChange.length !== 1) {
36
- return undefined;
37
- }
38
- return {
39
- currency: balanceChange[0].currency,
40
- value: balanceChange[0].value,
41
- };
42
- }
43
62
  return undefined;
44
63
  }
@@ -34,11 +34,12 @@ function parseOutcome(tx, nativeCurrency, definitions) {
34
34
  if (!metadata) {
35
35
  return undefined;
36
36
  }
37
+ const balanceChanges = getBalanceChanges(tx, nativeCurrency || (0, client_1.getNativeCurrency)());
37
38
  return (0, common_1.removeUndefined)({
38
39
  result: tx.meta.TransactionResult,
39
40
  timestamp: (0, utils_1.parseTimestamp)(tx.date),
40
41
  fee: (0, common_1.dropsToXrp)(tx.Fee),
41
- balanceChanges: getBalanceChanges(tx, nativeCurrency || (0, client_1.getNativeCurrency)()),
42
+ balanceChanges,
42
43
  lockedBalanceChanges: getLockedBalanceChanges(tx),
43
44
  orderbookChanges: getOrderbookChanges(tx),
44
45
  channelChanges: getChannelChanges(tx),
@@ -60,7 +61,7 @@ function parseOutcome(tx, nativeCurrency, definitions) {
60
61
  ledgerIndex: tx.ledger_index || tx.inLedger,
61
62
  ledgerVersion: tx.ledger_index || tx.inLedger,
62
63
  indexInLedger: tx.meta.TransactionIndex,
63
- deliveredAmount: (0, index_1.parseDeliveredAmount)(tx),
64
+ deliveredAmount: (0, index_1.parseDeliveredAmount)(tx, balanceChanges),
64
65
  });
65
66
  }
66
67
  function getBalanceChanges(tx, nativeCurrency) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bithomp/xrpl-api",
3
- "version": "3.2.15",
3
+ "version": "3.2.16",
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",
@@ -52,7 +52,7 @@
52
52
  "lib/**/*"
53
53
  ],
54
54
  "dependencies": {
55
- "axios": "^1.7.9",
55
+ "axios": "^1.8.1",
56
56
  "base-x": "^5.0.0",
57
57
  "bignumber.js": "^9.1.2",
58
58
  "elliptic": "^6.6.1",
@@ -62,26 +62,26 @@
62
62
  "xrpl": "^4.2.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@eslint/eslintrc": "^3.2.0",
65
+ "@eslint/eslintrc": "^3.3.0",
66
66
  "@types/chai": "^5.0.1",
67
67
  "@types/chai-as-promised": "^8.0.1",
68
68
  "@types/lodash": "^4.17.15",
69
69
  "@types/mocha": "^10.0.10",
70
70
  "@types/nconf": "^0.10.7",
71
- "@types/node": "^22.13.4",
72
- "@typescript-eslint/eslint-plugin": "^8.24.1",
73
- "@typescript-eslint/parser": "^8.24.1",
71
+ "@types/node": "^22.13.5",
72
+ "@typescript-eslint/eslint-plugin": "^8.25.0",
73
+ "@typescript-eslint/parser": "^8.25.0",
74
74
  "chai": "^4.5.0",
75
75
  "chai-as-promised": "^7.1.2",
76
- "eslint": "^9.20.1",
77
- "eslint-config-prettier": "^10.0.1",
76
+ "eslint": "^9.21.0",
77
+ "eslint-config-prettier": "^10.0.2",
78
78
  "eslint-plugin-chai-friendly": "^1.0.1",
79
79
  "eslint-plugin-import": "^2.31.0",
80
80
  "eslint-plugin-n": "^17.15.1",
81
81
  "eslint-plugin-promise": "^7.2.1",
82
82
  "mocha": "^11.1.0",
83
83
  "nconf": "^0.12.1",
84
- "ts-jest": "^29.2.5",
84
+ "ts-jest": "^29.2.6",
85
85
  "ts-node": "^10.9.2",
86
86
  "typescript": "^5.7.3"
87
87
  }