@bithomp/xrpl-api 3.6.16 → 3.6.18
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.
|
@@ -15,6 +15,7 @@ export interface BalanceChanges {
|
|
|
15
15
|
}
|
|
16
16
|
interface ParseBalanceChangesOptions {
|
|
17
17
|
adjustBalancesForNativeEscrow?: boolean;
|
|
18
|
+
adjustBalancesForPaymentChannel?: boolean;
|
|
18
19
|
}
|
|
19
20
|
declare function parseBalanceChanges(metadata: TransactionMetadata, nativeCurrency?: string, tx?: any, options?: ParseBalanceChangesOptions): BalanceChanges;
|
|
20
21
|
declare function parseFinalBalances(metadata: TransactionMetadata, nativeCurrency?: string): {
|
|
@@ -13,7 +13,9 @@ const utils_1 = require("../utils");
|
|
|
13
13
|
const mptoken_1 = require("../../models/mptoken");
|
|
14
14
|
const mptoken_normalize_1 = require("../mptoken_normalize");
|
|
15
15
|
const amount_1 = __importDefault(require("../ledger/amount"));
|
|
16
|
+
const channel_changes_1 = require("./channel_changes");
|
|
16
17
|
const ESCROW_TYPES = ["EscrowFinish", "EscrowCreate", "EscrowCancel"];
|
|
18
|
+
const PAYMENT_CHANNEL_TYPES = ["PaymentChannelClaim", "PaymentChannelCreate", "PaymentChannelFund"];
|
|
17
19
|
function groupByAddress(balanceChanges) {
|
|
18
20
|
const grouped = lodash_1.default.groupBy(balanceChanges, function (node) {
|
|
19
21
|
return node.address;
|
|
@@ -70,7 +72,9 @@ function parseFinalBalance(node) {
|
|
|
70
72
|
return parseValue(node.finalFields.Balance);
|
|
71
73
|
}
|
|
72
74
|
else if (node.entryType === "MPToken") {
|
|
73
|
-
|
|
75
|
+
if (node.finalFields.MPTAmount) {
|
|
76
|
+
return parseValue(node.finalFields.MPTAmount);
|
|
77
|
+
}
|
|
74
78
|
}
|
|
75
79
|
else if (node.entryType === "MPTokenIssuance") {
|
|
76
80
|
if (node.newFields.MaximumAmount) {
|
|
@@ -217,6 +221,45 @@ function adjustBalancesForNativeEscrow(balanceChanges, metadata, nativeCurrency,
|
|
|
217
221
|
adjustBalancesChanges(balanceChanges, source, [{ currency: amount.currency, value: `-${amount.value}` }]);
|
|
218
222
|
}
|
|
219
223
|
}
|
|
224
|
+
function adjustBalancesForPaymentChannel(balanceChanges, metadata, nativeCurrency, tx) {
|
|
225
|
+
const channelChanges = (0, channel_changes_1.parseChannelChanges)(metadata);
|
|
226
|
+
if (!channelChanges) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (!channelChanges.source?.address) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (tx.TransactionType === "PaymentChannelCreate") {
|
|
233
|
+
adjustBalancesChanges(balanceChanges, channelChanges.source.address, [
|
|
234
|
+
{ currency: channelChanges.amount.currency, value: channelChanges.amount.value },
|
|
235
|
+
]);
|
|
236
|
+
}
|
|
237
|
+
else if (tx.TransactionType === "PaymentChannelFund") {
|
|
238
|
+
if (channelChanges.amountChange) {
|
|
239
|
+
adjustBalancesChanges(balanceChanges, channelChanges.source.address, [
|
|
240
|
+
{ currency: channelChanges.amountChange.currency, value: channelChanges.amountChange.value },
|
|
241
|
+
]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else if (tx.TransactionType === "PaymentChannelClaim") {
|
|
245
|
+
if (tx.Account === channelChanges.source.address && channelChanges.amountChange) {
|
|
246
|
+
adjustBalancesChanges(balanceChanges, channelChanges.source.address, [
|
|
247
|
+
{ currency: channelChanges.amountChange.currency, value: channelChanges.amountChange.value },
|
|
248
|
+
]);
|
|
249
|
+
}
|
|
250
|
+
else if (channelChanges.status === "deleted") {
|
|
251
|
+
const unlockedAmount = new bignumber_js_1.default(channelChanges.amount.value).minus(new bignumber_js_1.default(channelChanges?.balance?.value || "0"));
|
|
252
|
+
adjustBalancesChanges(balanceChanges, channelChanges.source.address, [
|
|
253
|
+
{ currency: channelChanges.amount.currency, value: `-${unlockedAmount.toString()}` },
|
|
254
|
+
]);
|
|
255
|
+
}
|
|
256
|
+
else if (channelChanges.balanceChange) {
|
|
257
|
+
adjustBalancesChanges(balanceChanges, channelChanges.source.address, [
|
|
258
|
+
{ currency: channelChanges.balanceChange.currency, value: channelChanges.balanceChange.value },
|
|
259
|
+
]);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
220
263
|
function adjustBalancesChanges(balanceChanges, address, changes) {
|
|
221
264
|
const existingChanges = balanceChanges[address] || [];
|
|
222
265
|
const change = existingChanges.find((c) => c.currency === changes[0].currency && c.issuer === changes[0].issuer);
|
|
@@ -242,10 +285,13 @@ function parseBalanceChanges(metadata, nativeCurrency, tx, options) {
|
|
|
242
285
|
(0, mptoken_normalize_1.normalizeMPTokensPreviousFields)(metadata, tx);
|
|
243
286
|
}
|
|
244
287
|
const balanceChanges = parseQuantities(metadata, computeBalanceChange, nativeCurrency);
|
|
245
|
-
if (tx &&
|
|
246
|
-
if (
|
|
288
|
+
if (tx && tx.TransactionType && options) {
|
|
289
|
+
if (options.adjustBalancesForNativeEscrow && ESCROW_TYPES.includes(tx.TransactionType)) {
|
|
247
290
|
adjustBalancesForNativeEscrow(balanceChanges, metadata, nativeCurrency, tx);
|
|
248
291
|
}
|
|
292
|
+
else if (options.adjustBalancesForPaymentChannel && PAYMENT_CHANNEL_TYPES.includes(tx.TransactionType)) {
|
|
293
|
+
adjustBalancesForPaymentChannel(balanceChanges, metadata, nativeCurrency, tx);
|
|
294
|
+
}
|
|
249
295
|
}
|
|
250
296
|
return balanceChanges;
|
|
251
297
|
}
|
|
@@ -39,8 +39,8 @@ function summarizePaymentChannel(node) {
|
|
|
39
39
|
if (prev.Amount) {
|
|
40
40
|
summary.channelAmountChangeDrops = new bignumber_js_1.default(final.Amount).minus(new bignumber_js_1.default(prev.Amount || 0)).toString(10);
|
|
41
41
|
summary.amountChange = (0, amount_1.default)(prev.Amount);
|
|
42
|
-
summary.amountChange.value = new bignumber_js_1.default(summary.
|
|
43
|
-
.minus(new bignumber_js_1.default(summary.
|
|
42
|
+
summary.amountChange.value = new bignumber_js_1.default(summary.amount.value)
|
|
43
|
+
.minus(new bignumber_js_1.default(summary.amountChange.value))
|
|
44
44
|
.toString(10);
|
|
45
45
|
}
|
|
46
46
|
if (prev.Balance) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bithomp/xrpl-api",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.18",
|
|
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
|
-
"
|
|
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"
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@typescript-eslint/parser": "^8.46.1",
|
|
75
75
|
"chai": "^6.2.0",
|
|
76
76
|
"chai-as-promised": "^8.0.2",
|
|
77
|
-
"eslint": "^9.
|
|
77
|
+
"eslint": "^9.38.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",
|