@bithomp/xrpl-api 3.6.9 → 3.6.14
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/lib/ledger/account_tx.js +4 -2
- package/lib/ledger/transaction.js +4 -2
- package/lib/parse/index.d.ts +1 -0
- package/lib/parse/index.js +3 -1
- package/lib/parse/mptoken_normalize.d.ts +5 -0
- package/lib/parse/mptoken_normalize.js +215 -0
- package/lib/parse/outcome/balance_changes.d.ts +1 -1
- package/lib/parse/outcome/balance_changes.js +33 -23
- package/lib/parse/outcome/delivered_amount.js +3 -3
- package/lib/parse/outcome/locked_balance_changes.d.ts +5 -6
- package/lib/parse/outcome/locked_balance_changes.js +25 -2
- package/lib/parse/outcome/mptoken_changes.js +13 -0
- package/lib/parse/outcome/mptoken_issuance_changes.js +22 -1
- package/lib/parse/outcome.js +4 -1
- package/package.json +1 -1
package/lib/ledger/account_tx.js
CHANGED
|
@@ -102,7 +102,8 @@ async function getTransactions(account, options = { limit: DEFAULT_LIMIT }) {
|
|
|
102
102
|
if (options.balanceChanges === true || options.specification === true) {
|
|
103
103
|
for (const transaction of result.transactions) {
|
|
104
104
|
if (options.balanceChanges === true) {
|
|
105
|
-
|
|
105
|
+
const tx = transaction.tx || transaction;
|
|
106
|
+
transaction.balanceChanges = (0, balance_changes_1.parseBalanceChanges)(transaction.meta, Client.getNativeCurrency(), tx);
|
|
106
107
|
}
|
|
107
108
|
if (options.specification === true) {
|
|
108
109
|
const details = (0, transaction_1.getAccountTxDetails)(transaction, options.includeRawTransactions);
|
|
@@ -184,7 +185,8 @@ async function findTransactionsExt(account, options = { limit: DEFAULT_LIMIT, ti
|
|
|
184
185
|
if (formatted !== true && (loadOptions.balanceChanges === true || loadOptions.specification === true)) {
|
|
185
186
|
for (const newTransaction of newTransactions) {
|
|
186
187
|
if (loadOptions.balanceChanges === true) {
|
|
187
|
-
|
|
188
|
+
const tx = newTransaction.tx || newTransaction;
|
|
189
|
+
newTransaction.balanceChanges = (0, balance_changes_1.parseBalanceChanges)(newTransaction.meta, Client.getNativeCurrency(), tx);
|
|
188
190
|
}
|
|
189
191
|
if (loadOptions.specification === true) {
|
|
190
192
|
const details = (0, transaction_1.getAccountTxDetails)(newTransaction, options.includeRawTransactions);
|
|
@@ -91,7 +91,8 @@ async function getTransaction(transaction, options = {}) {
|
|
|
91
91
|
return (0, transaction_1.getTxDetails)(result, options.includeRawTransaction === true, Client.getNativeCurrency(), options.definitions);
|
|
92
92
|
}
|
|
93
93
|
if (options.balanceChanges === true && typeof result.meta === "object") {
|
|
94
|
-
result.
|
|
94
|
+
const tx = result.tx || result.tx_json || result;
|
|
95
|
+
result.balanceChanges = (0, balance_changes_1.parseBalanceChanges)(result.meta, Client.getNativeCurrency(), tx);
|
|
95
96
|
}
|
|
96
97
|
if (options.specification === true) {
|
|
97
98
|
const details = (0, transaction_1.getTxDetails)(result, options.includeRawTransaction, Client.getNativeCurrency(), options.definitions);
|
|
@@ -174,7 +175,8 @@ async function getTransactionByCTID(ctid, options = {}) {
|
|
|
174
175
|
return (0, transaction_1.getTxDetails)(result, options.includeRawTransaction === true, Client.getNativeCurrency(), options.definitions);
|
|
175
176
|
}
|
|
176
177
|
if (options.balanceChanges === true && typeof result.meta === "object") {
|
|
177
|
-
result.
|
|
178
|
+
const tx = result.tx || result.tx_json || result;
|
|
179
|
+
result.balanceChanges = (0, balance_changes_1.parseBalanceChanges)(result.meta, Client.getNativeCurrency(), tx);
|
|
178
180
|
}
|
|
179
181
|
if (options.specification === true) {
|
|
180
182
|
const details = (0, transaction_1.getTxDetails)(result, options.includeRawTransaction, Client.getNativeCurrency(), options.definitions);
|
package/lib/parse/index.d.ts
CHANGED
package/lib/parse/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.parseTransaction = exports.parseTransactionType = exports.parseOutcome = exports.Outcomes = exports.Utils = exports.Ledger = void 0;
|
|
36
|
+
exports.normalizeMPTokensPreviousFields = exports.parseTransaction = exports.parseTransactionType = exports.parseOutcome = exports.Outcomes = exports.Utils = exports.Ledger = void 0;
|
|
37
37
|
exports.Ledger = __importStar(require("./ledger"));
|
|
38
38
|
exports.Utils = __importStar(require("./utils"));
|
|
39
39
|
exports.Outcomes = __importStar(require("./outcome/index"));
|
|
@@ -42,3 +42,5 @@ Object.defineProperty(exports, "parseOutcome", { enumerable: true, get: function
|
|
|
42
42
|
var transaction_1 = require("./transaction");
|
|
43
43
|
Object.defineProperty(exports, "parseTransactionType", { enumerable: true, get: function () { return transaction_1.parseTransactionType; } });
|
|
44
44
|
Object.defineProperty(exports, "parseTransaction", { enumerable: true, get: function () { return transaction_1.parseTransaction; } });
|
|
45
|
+
var mptoken_normalize_1 = require("./mptoken_normalize");
|
|
46
|
+
Object.defineProperty(exports, "normalizeMPTokensPreviousFields", { enumerable: true, get: function () { return mptoken_normalize_1.normalizeMPTokensPreviousFields; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function normalizeMPTokensPreviousFields(meta: any, tx: any): void;
|
|
2
|
+
export declare function normalizeMPTokensPreviousFieldsEscrowCreate(meta: any): void;
|
|
3
|
+
export declare function normalizeMPTokensPreviousFieldsEscrowFinish(meta: any): void;
|
|
4
|
+
export declare function normalizeMPTokensPreviousFieldsEscrowCancel(meta: any): void;
|
|
5
|
+
export declare function normalizeMPTokensPreviousFieldsTransfer(meta: any, tx: any): void;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeMPTokensPreviousFields = normalizeMPTokensPreviousFields;
|
|
4
|
+
exports.normalizeMPTokensPreviousFieldsEscrowCreate = normalizeMPTokensPreviousFieldsEscrowCreate;
|
|
5
|
+
exports.normalizeMPTokensPreviousFieldsEscrowFinish = normalizeMPTokensPreviousFieldsEscrowFinish;
|
|
6
|
+
exports.normalizeMPTokensPreviousFieldsEscrowCancel = normalizeMPTokensPreviousFieldsEscrowCancel;
|
|
7
|
+
exports.normalizeMPTokensPreviousFieldsTransfer = normalizeMPTokensPreviousFieldsTransfer;
|
|
8
|
+
const TRANSFER_TRANSACTION_TYPES = ["Payment", "CheckCash", "EscrowFinish", "Clawback", "AMMClawback"];
|
|
9
|
+
function normalizeMPTokensPreviousFields(meta, tx) {
|
|
10
|
+
if (meta.TransactionResult !== "tesSUCCESS") {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (tx.TransactionType === "EscrowCreate") {
|
|
14
|
+
normalizeMPTokensPreviousFieldsEscrowCreate(meta);
|
|
15
|
+
}
|
|
16
|
+
else if (tx.TransactionType === "EscrowFinish") {
|
|
17
|
+
normalizeMPTokensPreviousFieldsEscrowFinish(meta);
|
|
18
|
+
}
|
|
19
|
+
else if (tx.TransactionType === "EscrowCancel") {
|
|
20
|
+
normalizeMPTokensPreviousFieldsEscrowCancel(meta);
|
|
21
|
+
}
|
|
22
|
+
else if (TRANSFER_TRANSACTION_TYPES.includes(tx.TransactionType)) {
|
|
23
|
+
normalizeMPTokensPreviousFieldsTransfer(meta, tx);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function normalizeMPTokensPreviousFieldsEscrowCreate(meta) {
|
|
27
|
+
const escrowNode = meta.AffectedNodes.find((node) => {
|
|
28
|
+
const createdNode = node.CreatedNode;
|
|
29
|
+
return createdNode && createdNode.LedgerEntryType === "Escrow";
|
|
30
|
+
});
|
|
31
|
+
if (!escrowNode) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const escrowFields = escrowNode.CreatedNode.NewFields;
|
|
35
|
+
const mptokenIssuanceID = escrowFields?.Amount?.mpt_issuance_id;
|
|
36
|
+
if (!mptokenIssuanceID) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const mptIssuanceNode = meta.AffectedNodes.find((node) => {
|
|
40
|
+
const modifiedNode = node.ModifiedNode;
|
|
41
|
+
return modifiedNode && modifiedNode.LedgerEntryType === "MPTokenIssuance";
|
|
42
|
+
});
|
|
43
|
+
if (mptIssuanceNode) {
|
|
44
|
+
const prevFields = mptIssuanceNode.ModifiedNode.PreviousFields;
|
|
45
|
+
if (prevFields && prevFields.LockedAmount === undefined) {
|
|
46
|
+
if (prevFields.LockedAmount === undefined) {
|
|
47
|
+
prevFields.LockedAmount = "0";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const mptokenNode = meta.AffectedNodes.find((node) => {
|
|
52
|
+
const modifiedNode = node.ModifiedNode;
|
|
53
|
+
return (modifiedNode &&
|
|
54
|
+
modifiedNode.LedgerEntryType === "MPToken" &&
|
|
55
|
+
modifiedNode.FinalFields.Account === escrowFields.Account &&
|
|
56
|
+
modifiedNode.FinalFields.MPTokenIssuanceID === mptokenIssuanceID);
|
|
57
|
+
});
|
|
58
|
+
if (mptokenNode) {
|
|
59
|
+
const finalFields = mptokenNode.ModifiedNode.FinalFields;
|
|
60
|
+
const prevFields = mptokenNode.ModifiedNode.PreviousFields;
|
|
61
|
+
if (prevFields && prevFields.LockedAmount === undefined) {
|
|
62
|
+
if (finalFields.Amount === undefined) {
|
|
63
|
+
finalFields.Amount = "0";
|
|
64
|
+
}
|
|
65
|
+
if (prevFields.LockedAmount === undefined) {
|
|
66
|
+
prevFields.LockedAmount = "0";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function normalizeMPTokensPreviousFieldsEscrowFinish(meta) {
|
|
72
|
+
const escrowNode = meta.AffectedNodes.find((node) => {
|
|
73
|
+
const deletedNode = node.DeletedNode;
|
|
74
|
+
return deletedNode && deletedNode.LedgerEntryType === "Escrow";
|
|
75
|
+
});
|
|
76
|
+
if (!escrowNode) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const escrowFields = escrowNode.DeletedNode.FinalFields;
|
|
80
|
+
const mptokenIssuanceID = escrowFields?.Amount?.mpt_issuance_id;
|
|
81
|
+
if (!mptokenIssuanceID) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const value = escrowFields?.Amount?.value ?? "0";
|
|
85
|
+
if (escrowFields.Account === escrowFields.Destination) {
|
|
86
|
+
const mptokenNode = meta.AffectedNodes.find((node) => {
|
|
87
|
+
const modifiedNode = node.ModifiedNode;
|
|
88
|
+
return (modifiedNode &&
|
|
89
|
+
modifiedNode.LedgerEntryType === "MPToken" &&
|
|
90
|
+
modifiedNode.FinalFields.Account === escrowFields.Account &&
|
|
91
|
+
modifiedNode.FinalFields.MPTokenIssuanceID === mptokenIssuanceID);
|
|
92
|
+
});
|
|
93
|
+
if (mptokenNode) {
|
|
94
|
+
const finalFields = mptokenNode.ModifiedNode.FinalFields;
|
|
95
|
+
const prevFields = mptokenNode.ModifiedNode.PreviousFields;
|
|
96
|
+
if (prevFields && prevFields.LockedAmount === undefined) {
|
|
97
|
+
if (finalFields.LockedAmount === undefined) {
|
|
98
|
+
finalFields.LockedAmount = "0";
|
|
99
|
+
}
|
|
100
|
+
if (prevFields.MPTAmount === undefined) {
|
|
101
|
+
prevFields.MPTAmount = "0";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const mptokenSourceNode = meta.AffectedNodes.find((node) => {
|
|
108
|
+
const modifiedNode = node.ModifiedNode;
|
|
109
|
+
return (modifiedNode &&
|
|
110
|
+
modifiedNode.LedgerEntryType === "MPToken" &&
|
|
111
|
+
modifiedNode.FinalFields.Account === escrowFields.Account &&
|
|
112
|
+
modifiedNode.FinalFields.MPTokenIssuanceID === mptokenIssuanceID);
|
|
113
|
+
});
|
|
114
|
+
if (mptokenSourceNode) {
|
|
115
|
+
const finalFields = mptokenSourceNode.ModifiedNode.FinalFields;
|
|
116
|
+
const prevFields = mptokenSourceNode.ModifiedNode.PreviousFields;
|
|
117
|
+
if (prevFields && prevFields.MPTAmount === undefined) {
|
|
118
|
+
if (finalFields.MPTAmount === undefined) {
|
|
119
|
+
finalFields.MPTAmount = "0";
|
|
120
|
+
}
|
|
121
|
+
if (finalFields.LockedAmount === undefined) {
|
|
122
|
+
finalFields.LockedAmount = "0";
|
|
123
|
+
}
|
|
124
|
+
if (prevFields.LockedAmount === undefined) {
|
|
125
|
+
prevFields.LockedAmount = value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const mptokenDestNode = meta.AffectedNodes.find((node) => {
|
|
130
|
+
const modifiedNode = node.ModifiedNode;
|
|
131
|
+
return (modifiedNode &&
|
|
132
|
+
modifiedNode.LedgerEntryType === "MPToken" &&
|
|
133
|
+
modifiedNode.FinalFields.Account === escrowFields.Destination &&
|
|
134
|
+
modifiedNode.FinalFields.MPTokenIssuanceID === mptokenIssuanceID);
|
|
135
|
+
});
|
|
136
|
+
if (mptokenDestNode) {
|
|
137
|
+
const prevFields = mptokenDestNode.ModifiedNode.PreviousFields;
|
|
138
|
+
if (prevFields && prevFields.LockedAmount === undefined) {
|
|
139
|
+
if (prevFields.MPTAmount === undefined) {
|
|
140
|
+
prevFields.MPTAmount = "0";
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function normalizeMPTokensPreviousFieldsEscrowCancel(meta) {
|
|
146
|
+
const escrowNode = meta.AffectedNodes.find((node) => {
|
|
147
|
+
const deletedNode = node.DeletedNode;
|
|
148
|
+
return deletedNode && deletedNode.LedgerEntryType === "Escrow";
|
|
149
|
+
});
|
|
150
|
+
if (!escrowNode) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const escrowFields = escrowNode.DeletedNode.FinalFields;
|
|
154
|
+
const mptokenIssuanceID = escrowFields?.Amount?.mpt_issuance_id;
|
|
155
|
+
if (!mptokenIssuanceID) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const mptokenNode = meta.AffectedNodes.find((node) => {
|
|
159
|
+
const modifiedNode = node.ModifiedNode;
|
|
160
|
+
return (modifiedNode &&
|
|
161
|
+
modifiedNode.LedgerEntryType === "MPToken" &&
|
|
162
|
+
modifiedNode.FinalFields.Account === escrowFields.Account &&
|
|
163
|
+
modifiedNode.FinalFields.MPTokenIssuanceID === mptokenIssuanceID);
|
|
164
|
+
});
|
|
165
|
+
if (mptokenNode) {
|
|
166
|
+
const finalFields = mptokenNode.ModifiedNode.FinalFields;
|
|
167
|
+
const prevFields = mptokenNode.ModifiedNode.PreviousFields;
|
|
168
|
+
if (prevFields && prevFields.LockedAmount === undefined) {
|
|
169
|
+
if (finalFields.LockedAmount === undefined) {
|
|
170
|
+
finalFields.LockedAmount = "0";
|
|
171
|
+
}
|
|
172
|
+
if (prevFields.MPTAmount === undefined) {
|
|
173
|
+
prevFields.MPTAmount = "0";
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function normalizeMPTokensPreviousFieldsTransfer(meta, tx) {
|
|
179
|
+
if (tx.Destination === undefined) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
let amount = null;
|
|
183
|
+
if (typeof tx.Amount === "object") {
|
|
184
|
+
amount = tx.Amount;
|
|
185
|
+
}
|
|
186
|
+
else if (typeof tx.SendMax === "object") {
|
|
187
|
+
amount = tx.SendMax;
|
|
188
|
+
}
|
|
189
|
+
else if (typeof tx.DeliverMax === "object") {
|
|
190
|
+
amount = tx.DeliverMax;
|
|
191
|
+
}
|
|
192
|
+
if (!amount) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const mptokenIssuanceID = amount.mpt_issuance_id;
|
|
196
|
+
const destination = tx.Destination;
|
|
197
|
+
if (!mptokenIssuanceID || !destination) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const mptokenNode = meta.AffectedNodes.find((node) => {
|
|
201
|
+
const modifiedNode = node.ModifiedNode;
|
|
202
|
+
return (modifiedNode &&
|
|
203
|
+
modifiedNode.LedgerEntryType === "MPToken" &&
|
|
204
|
+
modifiedNode.FinalFields.Account === destination &&
|
|
205
|
+
modifiedNode.FinalFields.MPTokenIssuanceID === mptokenIssuanceID);
|
|
206
|
+
});
|
|
207
|
+
if (mptokenNode) {
|
|
208
|
+
const prevFields = mptokenNode.ModifiedNode.PreviousFields;
|
|
209
|
+
if (prevFields && prevFields.LockedAmount === undefined) {
|
|
210
|
+
if (prevFields.MPTAmount === undefined) {
|
|
211
|
+
prevFields.MPTAmount = "0";
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -13,7 +13,7 @@ export interface AddressBalanceChangeQuantity {
|
|
|
13
13
|
export interface BalanceChanges {
|
|
14
14
|
[key: string]: BalanceChangeQuantity[];
|
|
15
15
|
}
|
|
16
|
-
declare function parseBalanceChanges(metadata: TransactionMetadata, nativeCurrency?: string): BalanceChanges;
|
|
16
|
+
declare function parseBalanceChanges(metadata: TransactionMetadata, nativeCurrency?: string, tx?: any): BalanceChanges;
|
|
17
17
|
declare function parseFinalBalances(metadata: TransactionMetadata, nativeCurrency?: string): {
|
|
18
18
|
[x: string]: BalanceChangeQuantity[];
|
|
19
19
|
};
|
|
@@ -11,6 +11,7 @@ const common_1 = require("../../common");
|
|
|
11
11
|
const client_1 = require("../../client");
|
|
12
12
|
const utils_1 = require("../utils");
|
|
13
13
|
const mptoken_1 = require("../../models/mptoken");
|
|
14
|
+
const mptoken_normalize_1 = require("../mptoken_normalize");
|
|
14
15
|
function groupByAddress(balanceChanges) {
|
|
15
16
|
const grouped = lodash_1.default.groupBy(balanceChanges, function (node) {
|
|
16
17
|
return node.address;
|
|
@@ -22,9 +23,6 @@ function groupByAddress(balanceChanges) {
|
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
25
|
function parseValue(value) {
|
|
25
|
-
if (Array.isArray(value)) {
|
|
26
|
-
return new bignumber_js_1.default(0);
|
|
27
|
-
}
|
|
28
26
|
if (typeof value === "string" || typeof value === "number") {
|
|
29
27
|
return new bignumber_js_1.default(value);
|
|
30
28
|
}
|
|
@@ -36,22 +34,29 @@ function computeBalanceChange(node) {
|
|
|
36
34
|
value = parseValue(node.newFields.Balance);
|
|
37
35
|
}
|
|
38
36
|
else if (node.newFields.MPTAmount) {
|
|
39
|
-
value = parseValue(node.newFields);
|
|
37
|
+
value = parseValue(node.newFields.MPTAmount);
|
|
40
38
|
}
|
|
41
39
|
else if (node.previousFields.Balance && node.finalFields.Balance) {
|
|
42
40
|
value = parseValue(node.finalFields.Balance).minus(parseValue(node.previousFields.Balance));
|
|
43
41
|
}
|
|
44
|
-
else if (node.previousFields.MPTAmount || node.
|
|
42
|
+
else if (node.entryType === "MPToken" && (node.previousFields.MPTAmount || node.previousFields.LockedAmount)) {
|
|
45
43
|
value = parseValue(node.finalFields.MPTAmount ?? 0).minus(parseValue(node.previousFields.MPTAmount ?? 0));
|
|
44
|
+
if (node.previousFields.LockedAmount) {
|
|
45
|
+
value = value
|
|
46
|
+
.plus(parseValue(node.finalFields.LockedAmount ?? 0))
|
|
47
|
+
.minus(parseValue(node.previousFields.LockedAmount ?? 0));
|
|
48
|
+
}
|
|
46
49
|
}
|
|
47
|
-
else if (node.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
else if (node.entryType === "MPTokenIssuance") {
|
|
51
|
+
if (node.newFields.MaximumAmount) {
|
|
52
|
+
value = parseValue(node.newFields.MaximumAmount);
|
|
53
|
+
}
|
|
54
|
+
else if (node.diffType === "DeletedNode" && node.finalFields.MaximumAmount) {
|
|
55
|
+
value = parseValue(node.finalFields.MaximumAmount).multipliedBy(-1);
|
|
56
|
+
}
|
|
57
|
+
else if (node.previousFields.OutstandingAmount) {
|
|
58
|
+
value = parseValue(node.previousFields.OutstandingAmount ?? 0).minus(parseValue(node.finalFields.OutstandingAmount ?? 0));
|
|
59
|
+
}
|
|
55
60
|
}
|
|
56
61
|
return value === null ? null : value.isZero() ? null : value;
|
|
57
62
|
}
|
|
@@ -62,17 +67,19 @@ function parseFinalBalance(node) {
|
|
|
62
67
|
else if (node.finalFields.Balance) {
|
|
63
68
|
return parseValue(node.finalFields.Balance);
|
|
64
69
|
}
|
|
65
|
-
else if (node.
|
|
70
|
+
else if (node.entryType === "MPToken") {
|
|
66
71
|
return parseValue(node.finalFields.MPTAmount);
|
|
67
72
|
}
|
|
68
|
-
else if (node.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
else if (node.entryType === "MPTokenIssuance") {
|
|
74
|
+
if (node.newFields.MaximumAmount) {
|
|
75
|
+
return parseValue(node.newFields.MaximumAmount);
|
|
76
|
+
}
|
|
77
|
+
else if (node.diffType === "DeletedNode" && node.finalFields.MaximumAmount) {
|
|
78
|
+
return new bignumber_js_1.default(0);
|
|
79
|
+
}
|
|
80
|
+
else if (node.finalFields.MaximumAmount) {
|
|
81
|
+
return parseValue(node.finalFields.MaximumAmount).minus(parseValue(node.finalFields.OutstandingAmount));
|
|
82
|
+
}
|
|
76
83
|
}
|
|
77
84
|
return null;
|
|
78
85
|
}
|
|
@@ -181,7 +188,10 @@ function parseQuantities(metadata, valueParser, nativeCurrency) {
|
|
|
181
188
|
});
|
|
182
189
|
return groupByAddress(lodash_1.default.compact(lodash_1.default.flatten(values)));
|
|
183
190
|
}
|
|
184
|
-
function parseBalanceChanges(metadata, nativeCurrency) {
|
|
191
|
+
function parseBalanceChanges(metadata, nativeCurrency, tx) {
|
|
192
|
+
if (tx && nativeCurrency === common_1.MAINNET_NATIVE_CURRENCY && metadata.TransactionResult === "tesSUCCESS") {
|
|
193
|
+
(0, mptoken_normalize_1.normalizeMPTokensPreviousFields)(metadata, tx);
|
|
194
|
+
}
|
|
185
195
|
return parseQuantities(metadata, computeBalanceChange, nativeCurrency);
|
|
186
196
|
}
|
|
187
197
|
function parseFinalBalances(metadata, nativeCurrency) {
|
|
@@ -14,7 +14,7 @@ function parseDeliveredAmount(tx, balanceChanges) {
|
|
|
14
14
|
return undefined;
|
|
15
15
|
}
|
|
16
16
|
if (tx.TransactionType === "Payment") {
|
|
17
|
-
const txBalanceChanges = balanceChanges || (0, balance_changes_1.parseBalanceChanges)(tx.meta, (0, client_1.getNativeCurrency)());
|
|
17
|
+
const txBalanceChanges = balanceChanges || (0, balance_changes_1.parseBalanceChanges)(tx.meta, (0, client_1.getNativeCurrency)(), tx);
|
|
18
18
|
if (txBalanceChanges) {
|
|
19
19
|
const account = tx.Destination;
|
|
20
20
|
const changes = txBalanceChanges[account];
|
|
@@ -27,7 +27,7 @@ function parseDeliveredAmount(tx, balanceChanges) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
else if (tx.TransactionType === "CheckCash") {
|
|
30
|
-
const txBalanceChanges = balanceChanges || (0, balance_changes_1.parseBalanceChanges)(tx.meta, (0, client_1.getNativeCurrency)());
|
|
30
|
+
const txBalanceChanges = balanceChanges || (0, balance_changes_1.parseBalanceChanges)(tx.meta, (0, client_1.getNativeCurrency)(), tx);
|
|
31
31
|
if (txBalanceChanges) {
|
|
32
32
|
const account = tx.Account;
|
|
33
33
|
const changes = txBalanceChanges[account];
|
|
@@ -40,7 +40,7 @@ function parseDeliveredAmount(tx, balanceChanges) {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
else if (tx.TransactionType === "Import") {
|
|
43
|
-
const txBalanceChanges = balanceChanges || (0, balance_changes_1.parseBalanceChanges)(tx.meta, (0, client_1.getNativeCurrency)());
|
|
43
|
+
const txBalanceChanges = balanceChanges || (0, balance_changes_1.parseBalanceChanges)(tx.meta, (0, client_1.getNativeCurrency)(), tx);
|
|
44
44
|
const blob = (0, import_1.parseImportBlob)(tx.Blob);
|
|
45
45
|
if (typeof blob === "object") {
|
|
46
46
|
const account = blob.transaction.tx.Account;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { TransactionMetadata } from "xrpl";
|
|
2
2
|
interface LockedBalanceChangeQuantity {
|
|
3
|
-
issuer
|
|
4
|
-
currency
|
|
3
|
+
issuer?: string;
|
|
4
|
+
currency?: string;
|
|
5
5
|
value: string;
|
|
6
|
-
counterparty
|
|
6
|
+
counterparty?: string;
|
|
7
|
+
mpt_issuance_id?: string;
|
|
7
8
|
}
|
|
8
9
|
export interface AddressLockedBalanceChangeQuantity {
|
|
9
10
|
address: string;
|
|
@@ -12,9 +13,7 @@ export interface AddressLockedBalanceChangeQuantity {
|
|
|
12
13
|
export interface LockedBalanceChanges {
|
|
13
14
|
[key: string]: LockedBalanceChangeQuantity[];
|
|
14
15
|
}
|
|
15
|
-
declare function parseLockedBalanceChanges(metadata: TransactionMetadata):
|
|
16
|
-
[x: string]: LockedBalanceChangeQuantity[];
|
|
17
|
-
};
|
|
16
|
+
declare function parseLockedBalanceChanges(metadata: TransactionMetadata): LockedBalanceChanges;
|
|
18
17
|
declare function parseFinalLockedBalances(metadata: TransactionMetadata): {
|
|
19
18
|
[x: string]: LockedBalanceChangeQuantity[];
|
|
20
19
|
};
|
|
@@ -19,7 +19,10 @@ function groupByAddress(lockedBalanceChanges) {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
function parseValue(value) {
|
|
22
|
-
|
|
22
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
23
|
+
return new bignumber_js_1.default(value);
|
|
24
|
+
}
|
|
25
|
+
return new bignumber_js_1.default(value.value ?? 0);
|
|
23
26
|
}
|
|
24
27
|
function computeBalanceChange(node) {
|
|
25
28
|
let value = null;
|
|
@@ -32,6 +35,9 @@ function computeBalanceChange(node) {
|
|
|
32
35
|
else if (node.previousFields.LockedBalance) {
|
|
33
36
|
value = parseValue(node.previousFields.LockedBalance).negated();
|
|
34
37
|
}
|
|
38
|
+
else if (node.finalFields.LockedAmount || node.previousFields.LockedAmount) {
|
|
39
|
+
value = parseValue(node.finalFields.LockedAmount ?? 0).minus(parseValue(node.previousFields.LockedAmount ?? 0));
|
|
40
|
+
}
|
|
35
41
|
return value === null ? null : value.isZero() ? null : value;
|
|
36
42
|
}
|
|
37
43
|
function parseFinalBalance(node) {
|
|
@@ -72,16 +78,33 @@ function parseTrustlineQuantity(node, valueParser) {
|
|
|
72
78
|
};
|
|
73
79
|
return [result];
|
|
74
80
|
}
|
|
81
|
+
function parseMPTQuantity(node, valueParser) {
|
|
82
|
+
const value = valueParser(node);
|
|
83
|
+
if (value === null) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const fields = lodash_1.default.isEmpty(node.newFields) ? node.finalFields : node.newFields;
|
|
87
|
+
return {
|
|
88
|
+
address: fields.Account,
|
|
89
|
+
lockedBalance: {
|
|
90
|
+
value: value.toString(),
|
|
91
|
+
mpt_issuance_id: fields.MPTokenIssuanceID,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
75
95
|
function parseQuantities(metadata, valueParser) {
|
|
76
96
|
const values = metadata.AffectedNodes.map(function (affectedNode) {
|
|
77
97
|
const node = affectedNode.CreatedNode || affectedNode.ModifiedNode || affectedNode.DeletedNode;
|
|
78
|
-
if (node.LedgerEntryType
|
|
98
|
+
if (!["RippleState", "MPToken"].includes(node.LedgerEntryType)) {
|
|
79
99
|
return [];
|
|
80
100
|
}
|
|
81
101
|
const normalizedNode = (0, utils_1.normalizeNode)(affectedNode);
|
|
82
102
|
if (node.LedgerEntryType === "RippleState") {
|
|
83
103
|
return parseTrustlineQuantity(normalizedNode, valueParser);
|
|
84
104
|
}
|
|
105
|
+
else if (node.LedgerEntryType === "MPToken") {
|
|
106
|
+
return [parseMPTQuantity(normalizedNode, valueParser)];
|
|
107
|
+
}
|
|
85
108
|
return [];
|
|
86
109
|
});
|
|
87
110
|
return groupByAddress(lodash_1.default.compact(lodash_1.default.flatten(values)));
|
|
@@ -50,6 +50,7 @@ class MPTokenChanges {
|
|
|
50
50
|
mptIssuanceID,
|
|
51
51
|
account,
|
|
52
52
|
amount: node.NewFields.MPTAmount,
|
|
53
|
+
lockedAmount: node.NewFields.LockedAmount,
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
56
|
if (affectedNode.ModifiedNode) {
|
|
@@ -61,6 +62,15 @@ class MPTokenChanges {
|
|
|
61
62
|
if (amountChange === "0") {
|
|
62
63
|
amountChange = undefined;
|
|
63
64
|
}
|
|
65
|
+
let lockedAmountChange = undefined;
|
|
66
|
+
if (node.PreviousFields.LockedAmount !== undefined) {
|
|
67
|
+
lockedAmountChange = new bignumber_js_1.default(node.FinalFields.LockedAmount ?? 0)
|
|
68
|
+
.minus(node.PreviousFields.LockedAmount ?? 0)
|
|
69
|
+
.toString();
|
|
70
|
+
if (lockedAmountChange === "0") {
|
|
71
|
+
lockedAmountChange = undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
64
74
|
let flagsChange;
|
|
65
75
|
if (node.PreviousFields?.Flags !== undefined) {
|
|
66
76
|
flagsChange = (0, mptoken_flags_1.default)(node.PreviousFields.Flags);
|
|
@@ -71,7 +81,9 @@ class MPTokenChanges {
|
|
|
71
81
|
mptIssuanceID,
|
|
72
82
|
account,
|
|
73
83
|
amount: node.FinalFields.MPTAmount,
|
|
84
|
+
lockedAmount: node.FinalFields.LockedAmount,
|
|
74
85
|
amountChange,
|
|
86
|
+
lockedAmountChange,
|
|
75
87
|
flagsChange,
|
|
76
88
|
});
|
|
77
89
|
}
|
|
@@ -84,6 +96,7 @@ class MPTokenChanges {
|
|
|
84
96
|
mptIssuanceID,
|
|
85
97
|
account,
|
|
86
98
|
amount: node.FinalFields.MPTAmount,
|
|
99
|
+
lockedAmount: node.FinalFields.LockedAmount,
|
|
87
100
|
});
|
|
88
101
|
}
|
|
89
102
|
}
|
|
@@ -50,6 +50,7 @@ class MPTokenIssuanceChanges {
|
|
|
50
50
|
transferFee: node.NewFields.TransferFee,
|
|
51
51
|
maximumAmount: node.NewFields.MaximumAmount,
|
|
52
52
|
outstandingAmount: node.NewFields.OutstandingAmount,
|
|
53
|
+
lockedAmount: node.NewFields.LockedAmount,
|
|
53
54
|
metadata: node.NewFields.Metadata,
|
|
54
55
|
scale: node.NewFields.AssetScale,
|
|
55
56
|
});
|
|
@@ -62,6 +63,23 @@ class MPTokenIssuanceChanges {
|
|
|
62
63
|
if (outstandingAmountChange === "0") {
|
|
63
64
|
outstandingAmountChange = undefined;
|
|
64
65
|
}
|
|
66
|
+
let lockedAmountChange = undefined;
|
|
67
|
+
if (node.PreviousFields.LockedAmount !== undefined) {
|
|
68
|
+
lockedAmountChange = new bignumber_js_1.default(node.FinalFields.LockedAmount ?? 0)
|
|
69
|
+
.minus(new bignumber_js_1.default(node.PreviousFields.LockedAmount ?? 0))
|
|
70
|
+
.toString();
|
|
71
|
+
if (lockedAmountChange === "0") {
|
|
72
|
+
lockedAmountChange = undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
let lockedAmount = node.FinalFields.LockedAmount;
|
|
76
|
+
if (lockedAmount === undefined && lockedAmountChange !== undefined) {
|
|
77
|
+
lockedAmount = "0";
|
|
78
|
+
}
|
|
79
|
+
let flagsChange;
|
|
80
|
+
if (node.PreviousFields?.Flags !== undefined) {
|
|
81
|
+
flagsChange = (0, mptoken_issuance_flags_1.default)(node.PreviousFields.Flags);
|
|
82
|
+
}
|
|
65
83
|
this.addChange(mptIssuanceID, {
|
|
66
84
|
status: "modified",
|
|
67
85
|
flags: (0, mptoken_issuance_flags_1.default)(node.FinalFields.Flags),
|
|
@@ -71,10 +89,12 @@ class MPTokenIssuanceChanges {
|
|
|
71
89
|
transferFee: node.FinalFields.TransferFee,
|
|
72
90
|
maximumAmount: node.FinalFields.MaximumAmount,
|
|
73
91
|
outstandingAmount: node.FinalFields.OutstandingAmount,
|
|
92
|
+
lockedAmount,
|
|
74
93
|
metadata: node.FinalFields.Metadata,
|
|
75
94
|
scale: node.FinalFields.AssetScale,
|
|
76
95
|
outstandingAmountChange,
|
|
77
|
-
|
|
96
|
+
lockedAmountChange,
|
|
97
|
+
flagsChange,
|
|
78
98
|
});
|
|
79
99
|
}
|
|
80
100
|
if (affectedNode.DeletedNode) {
|
|
@@ -88,6 +108,7 @@ class MPTokenIssuanceChanges {
|
|
|
88
108
|
transferFee: node.FinalFields.TransferFee,
|
|
89
109
|
maximumAmount: node.FinalFields.MaximumAmount,
|
|
90
110
|
outstandingAmount: node.FinalFields.OutstandingAmount,
|
|
111
|
+
lockedAmount: node.FinalFields.LockedAmount,
|
|
91
112
|
metadata: node.FinalFields.Metadata,
|
|
92
113
|
scale: node.FinalFields.AssetScale,
|
|
93
114
|
});
|
package/lib/parse/outcome.js
CHANGED
|
@@ -35,6 +35,9 @@ const MPTOKEN_TYPES = [
|
|
|
35
35
|
"MPTokenIssuanceDestroy",
|
|
36
36
|
"Payment",
|
|
37
37
|
"Clawback",
|
|
38
|
+
"EscrowFinish",
|
|
39
|
+
"EscrowCreate",
|
|
40
|
+
"EscrowCancel",
|
|
38
41
|
];
|
|
39
42
|
const CREDENTIAL_TYPES = ["CredentialCreate", "CredentialAccept", "CredentialDelete"];
|
|
40
43
|
const DELEGATE_TYPES = ["DelegateSet"];
|
|
@@ -79,7 +82,7 @@ function parseOutcome(tx, nativeCurrency, definitions) {
|
|
|
79
82
|
});
|
|
80
83
|
}
|
|
81
84
|
function getBalanceChanges(tx, nativeCurrency) {
|
|
82
|
-
const balanceChanges = (0, index_1.parseBalanceChanges)(tx.meta, nativeCurrency);
|
|
85
|
+
const balanceChanges = (0, index_1.parseBalanceChanges)(tx.meta, nativeCurrency, tx);
|
|
83
86
|
return Object.keys(balanceChanges).length > 0 ? balanceChanges : undefined;
|
|
84
87
|
}
|
|
85
88
|
function getLockedBalanceChanges(tx) {
|