@bithomp/xrpl-api 3.6.14 → 3.6.15
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.
|
@@ -13,7 +13,10 @@ export interface AddressBalanceChangeQuantity {
|
|
|
13
13
|
export interface BalanceChanges {
|
|
14
14
|
[key: string]: BalanceChangeQuantity[];
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
interface ParseBalanceChangesOptions {
|
|
17
|
+
adjustBalancesForNativeEscrow?: boolean;
|
|
18
|
+
}
|
|
19
|
+
declare function parseBalanceChanges(metadata: TransactionMetadata, nativeCurrency?: string, tx?: any, options?: ParseBalanceChangesOptions): BalanceChanges;
|
|
17
20
|
declare function parseFinalBalances(metadata: TransactionMetadata, nativeCurrency?: string): {
|
|
18
21
|
[x: string]: BalanceChangeQuantity[];
|
|
19
22
|
};
|
|
@@ -12,6 +12,8 @@ const client_1 = require("../../client");
|
|
|
12
12
|
const utils_1 = require("../utils");
|
|
13
13
|
const mptoken_1 = require("../../models/mptoken");
|
|
14
14
|
const mptoken_normalize_1 = require("../mptoken_normalize");
|
|
15
|
+
const amount_1 = __importDefault(require("../ledger/amount"));
|
|
16
|
+
const ESCROW_TYPES = ["EscrowFinish", "EscrowCreate", "EscrowCancel"];
|
|
15
17
|
function groupByAddress(balanceChanges) {
|
|
16
18
|
const grouped = lodash_1.default.groupBy(balanceChanges, function (node) {
|
|
17
19
|
return node.address;
|
|
@@ -188,11 +190,64 @@ function parseQuantities(metadata, valueParser, nativeCurrency) {
|
|
|
188
190
|
});
|
|
189
191
|
return groupByAddress(lodash_1.default.compact(lodash_1.default.flatten(values)));
|
|
190
192
|
}
|
|
191
|
-
function
|
|
193
|
+
function adjustBalancesForNativeEscrow(balanceChanges, metadata, nativeCurrency, tx) {
|
|
194
|
+
let escrow;
|
|
195
|
+
if (tx.TransactionType === "EscrowCreate") {
|
|
196
|
+
escrow = metadata.AffectedNodes.find((node) => node.CreatedNode?.LedgerEntryType === "Escrow");
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
escrow = metadata.AffectedNodes.find((node) => node.DeletedNode?.LedgerEntryType === "Escrow");
|
|
200
|
+
}
|
|
201
|
+
if (!escrow) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const fields = escrow.CreatedNode?.NewFields || escrow.DeletedNode?.FinalFields;
|
|
205
|
+
if (!fields || !fields.Amount) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const amount = (0, amount_1.default)(fields.Amount);
|
|
209
|
+
if (!amount || amount.currency !== (nativeCurrency || common_1.MAINNET_NATIVE_CURRENCY) || !amount.value) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const source = fields.Account;
|
|
213
|
+
if (tx.TransactionType === "EscrowCreate") {
|
|
214
|
+
adjustBalancesChanges(balanceChanges, source, [{ currency: amount.currency, value: amount.value }]);
|
|
215
|
+
}
|
|
216
|
+
else if (tx.TransactionType === "EscrowFinish" || tx.TransactionType === "EscrowCancel") {
|
|
217
|
+
adjustBalancesChanges(balanceChanges, source, [{ currency: amount.currency, value: `-${amount.value}` }]);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function adjustBalancesChanges(balanceChanges, address, changes) {
|
|
221
|
+
const existingChanges = balanceChanges[address] || [];
|
|
222
|
+
const change = existingChanges.find((c) => c.currency === changes[0].currency && c.issuer === changes[0].issuer);
|
|
223
|
+
if (change) {
|
|
224
|
+
const newValue = new bignumber_js_1.default(change.value).plus(new bignumber_js_1.default(changes[0].value));
|
|
225
|
+
if (newValue.isZero()) {
|
|
226
|
+
balanceChanges[address] = existingChanges.filter((c) => c !== change);
|
|
227
|
+
if (balanceChanges[address].length === 0) {
|
|
228
|
+
delete balanceChanges[address];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
change.value = newValue.toString();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
existingChanges.push(changes[0]);
|
|
237
|
+
balanceChanges[address] = existingChanges;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function parseBalanceChanges(metadata, nativeCurrency, tx, options) {
|
|
192
241
|
if (tx && nativeCurrency === common_1.MAINNET_NATIVE_CURRENCY && metadata.TransactionResult === "tesSUCCESS") {
|
|
193
242
|
(0, mptoken_normalize_1.normalizeMPTokensPreviousFields)(metadata, tx);
|
|
194
243
|
}
|
|
195
|
-
|
|
244
|
+
const balanceChanges = parseQuantities(metadata, computeBalanceChange, nativeCurrency);
|
|
245
|
+
if (tx && options && options.adjustBalancesForNativeEscrow) {
|
|
246
|
+
if (tx.TransactionType && ESCROW_TYPES.includes(tx.TransactionType)) {
|
|
247
|
+
adjustBalancesForNativeEscrow(balanceChanges, metadata, nativeCurrency, tx);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return balanceChanges;
|
|
196
251
|
}
|
|
197
252
|
function parseFinalBalances(metadata, nativeCurrency) {
|
|
198
253
|
return parseQuantities(metadata, parseFinalBalance, nativeCurrency);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bithomp/xrpl-api",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.15",
|
|
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"
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"@types/mocha": "^10.0.10",
|
|
71
71
|
"@types/nconf": "^0.10.7",
|
|
72
72
|
"@types/node": "^22.15.21",
|
|
73
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
74
|
-
"@typescript-eslint/parser": "^8.
|
|
73
|
+
"@typescript-eslint/eslint-plugin": "^8.46.1",
|
|
74
|
+
"@typescript-eslint/parser": "^8.46.1",
|
|
75
75
|
"chai": "^6.2.0",
|
|
76
76
|
"chai-as-promised": "^8.0.2",
|
|
77
77
|
"eslint": "^9.37.0",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"eslint-plugin-promise": "^7.2.1",
|
|
83
83
|
"mocha": "^11.7.4",
|
|
84
84
|
"nconf": "^0.13.0",
|
|
85
|
-
"ts-jest": "^29.4.
|
|
85
|
+
"ts-jest": "^29.4.5",
|
|
86
86
|
"ts-node": "^10.9.2",
|
|
87
87
|
"typescript": "^5.9.3"
|
|
88
88
|
}
|