@bithomp/xrpl-api 3.2.14 → 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.
package/README.md CHANGED
@@ -168,7 +168,7 @@ const vl = await BithompXRPL.Client.createVLv2(vk, sk, [publishBlob, publishBlob
168
168
 
169
169
  // vl will contain the signed validator list with
170
170
  // {
171
- // "blobs-v2": "...",
171
+ // "blobs_v2": "...",
172
172
  // "manifest": "...", // signed with vk.privateKey and sk.privateKey
173
173
  // "version": 2,
174
174
  // "public_key": "..." // vk.publicKey
@@ -107,7 +107,7 @@ async function createVLv2(masterKey, ephemeralKey, publishBlobs) {
107
107
  MasterPrivateKey: masterKey.privateKey,
108
108
  });
109
109
  return {
110
- "blobs-v2": blobs,
110
+ "blobs_v2": blobs,
111
111
  manifest: globalManifest,
112
112
  public_key: masterKey.publicKey,
113
113
  version: 2,
@@ -4,7 +4,7 @@ export interface VLInterface {
4
4
  public_key?: string;
5
5
  manifest?: string;
6
6
  blob?: string;
7
- "blobs-v2"?: VLBlobInfoInterface[];
7
+ blobs_v2?: VLBlobInfoInterface[];
8
8
  signature?: string;
9
9
  }
10
10
  export interface ParsedVLInterface {
package/lib/models/vl.js CHANGED
@@ -102,10 +102,13 @@ function parseVL(vl) {
102
102
  }
103
103
  }
104
104
  else if (decoded.version === 2) {
105
- const blobs = vl["blobs-v2"];
105
+ const blobs = (vl["blobs-v2"] || vl["blobs_v2"]);
106
106
  if (!decoded.blobs) {
107
107
  decoded.blobs = [];
108
108
  }
109
+ if (!blobs) {
110
+ return decoded;
111
+ }
109
112
  for (const blobInfo of blobs) {
110
113
  const blob = decodeVLBlob(blobInfo.blob);
111
114
  error = isValidVLBlob(blob);
@@ -188,7 +191,10 @@ function isValidVL(vl) {
188
191
  }
189
192
  }
190
193
  else if (vl.version === 2) {
191
- const blobs = vl["blobs-v2"];
194
+ const blobs = (vl["blobs-v2"] || vl["blobs_v2"]);
195
+ if (!blobs) {
196
+ return "blobs_v2 missing from vl";
197
+ }
192
198
  for (const blobInfo of blobs) {
193
199
  const blob = decodeVLBlob(blobInfo.blob);
194
200
  error = isValidVLBlob(blob);
@@ -226,17 +232,18 @@ function isValidVLFormat(vl) {
226
232
  }
227
233
  }
228
234
  else if (version === 2) {
235
+ const blobs = (vl["blobs-v2"] || vl["blobs_v2"]);
229
236
  if (blob !== undefined) {
230
237
  error = "Blob should not be present in vl version 2";
231
238
  }
232
- else if (vl["blobs-v2"] === undefined) {
233
- error = "blobs-v2 missing from vl";
239
+ else if (blobs === undefined) {
240
+ error = "blobs_v2 missing from vl";
234
241
  }
235
- else if (!Array.isArray(vl["blobs-v2"])) {
236
- error = "blobs-v2 should be an array";
242
+ else if (!Array.isArray(blobs)) {
243
+ error = "blobs_v2 should be an array";
237
244
  }
238
- else if (vl["blobs-v2"].length === 0) {
239
- error = "blobs-v2 should not be empty";
245
+ else if (blobs.length === 0) {
246
+ error = "blobs_v2 should not be empty";
240
247
  }
241
248
  }
242
249
  else {
@@ -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.14",
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
  }