@bithomp/xrpl-api 3.6.9 → 3.6.11

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.
@@ -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
- transaction.balanceChanges = (0, balance_changes_1.parseBalanceChanges)(transaction.meta, Client.getNativeCurrency());
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
- newTransaction.balanceChanges = (0, balance_changes_1.parseBalanceChanges)(newTransaction.meta, Client.getNativeCurrency());
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.balanceChanges = (0, balance_changes_1.parseBalanceChanges)(result.meta, Client.getNativeCurrency());
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.balanceChanges = (0, balance_changes_1.parseBalanceChanges)(result.meta, Client.getNativeCurrency());
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);
@@ -3,3 +3,4 @@ export * as Utils from "./utils";
3
3
  export * as Outcomes from "./outcome/index";
4
4
  export { parseOutcome } from "./outcome";
5
5
  export { parseTransactionType, parseTransaction } from "./transaction";
6
+ export { normalizeMPTokensPreviousFields } from "./mptoken_normalize";
@@ -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
  }
@@ -41,17 +39,22 @@ function computeBalanceChange(node) {
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.finalFields.MPTAmount) {
45
- value = parseValue(node.finalFields.MPTAmount ?? 0).minus(parseValue(node.previousFields.MPTAmount ?? 0));
46
- }
47
- else if (node.newFields.MaximumAmount) {
48
- value = parseValue(node.newFields.MaximumAmount);
49
- }
50
- else if (node.diffType === "DeletedNode" && node.finalFields.MaximumAmount) {
51
- value = parseValue(node.finalFields.MaximumAmount).multipliedBy(-1);
42
+ else if (node.entryType === "MPToken" && (node.previousFields.MPTAmount || node.previousFields.LockedAmount)) {
43
+ value = parseValue(node.finalFields.MPTAmount ?? 0)
44
+ .minus(parseValue(node.previousFields.MPTAmount ?? 0))
45
+ .plus(parseValue(node.finalFields.LockedAmount ?? 0))
46
+ .minus(parseValue(node.previousFields.LockedAmount ?? 0));
52
47
  }
53
- else if (node.previousFields.OutstandingAmount) {
54
- value = parseValue(node.previousFields.OutstandingAmount ?? 0).minus(parseValue(node.finalFields.OutstandingAmount ?? 0));
48
+ else if (node.entryType === "MPTokenIssuance") {
49
+ if (node.newFields.MaximumAmount) {
50
+ value = parseValue(node.newFields.MaximumAmount);
51
+ }
52
+ else if (node.diffType === "DeletedNode" && node.finalFields.MaximumAmount) {
53
+ value = parseValue(node.finalFields.MaximumAmount).multipliedBy(-1);
54
+ }
55
+ else if (node.previousFields.OutstandingAmount) {
56
+ value = parseValue(node.previousFields.OutstandingAmount ?? 0).minus(parseValue(node.finalFields.OutstandingAmount ?? 0));
57
+ }
55
58
  }
56
59
  return value === null ? null : value.isZero() ? null : value;
57
60
  }
@@ -62,17 +65,19 @@ function parseFinalBalance(node) {
62
65
  else if (node.finalFields.Balance) {
63
66
  return parseValue(node.finalFields.Balance);
64
67
  }
65
- else if (node.finalFields.MPTAmount) {
68
+ else if (node.entryType === "MPToken") {
66
69
  return parseValue(node.finalFields.MPTAmount);
67
70
  }
68
- else if (node.newFields.MaximumAmount) {
69
- return parseValue(node.newFields.MaximumAmount);
70
- }
71
- else if (node.diffType === "DeletedNode" && node.finalFields.MaximumAmount) {
72
- return new bignumber_js_1.default(0);
73
- }
74
- else if (node.finalFields.MaximumAmount) {
75
- return parseValue(node.finalFields.MaximumAmount).minus(parseValue(node.finalFields.OutstandingAmount));
71
+ else if (node.entryType === "MPTokenIssuance") {
72
+ if (node.newFields.MaximumAmount) {
73
+ return parseValue(node.newFields.MaximumAmount);
74
+ }
75
+ else if (node.diffType === "DeletedNode" && node.finalFields.MaximumAmount) {
76
+ return new bignumber_js_1.default(0);
77
+ }
78
+ else if (node.finalFields.MaximumAmount) {
79
+ return parseValue(node.finalFields.MaximumAmount).minus(parseValue(node.finalFields.OutstandingAmount));
80
+ }
76
81
  }
77
82
  return null;
78
83
  }
@@ -181,7 +186,10 @@ function parseQuantities(metadata, valueParser, nativeCurrency) {
181
186
  });
182
187
  return groupByAddress(lodash_1.default.compact(lodash_1.default.flatten(values)));
183
188
  }
184
- function parseBalanceChanges(metadata, nativeCurrency) {
189
+ function parseBalanceChanges(metadata, nativeCurrency, tx) {
190
+ if (tx && nativeCurrency === common_1.MAINNET_NATIVE_CURRENCY && metadata.TransactionResult === "tesSUCCESS") {
191
+ (0, mptoken_normalize_1.normalizeMPTokensPreviousFields)(metadata, tx);
192
+ }
185
193
  return parseQuantities(metadata, computeBalanceChange, nativeCurrency);
186
194
  }
187
195
  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: string;
4
- currency: string;
3
+ issuer?: string;
4
+ currency?: string;
5
5
  value: string;
6
- counterparty: string;
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
- return new bignumber_js_1.default(value.value ?? value);
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 !== "RippleState") {
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)));
@@ -79,7 +79,7 @@ function parseOutcome(tx, nativeCurrency, definitions) {
79
79
  });
80
80
  }
81
81
  function getBalanceChanges(tx, nativeCurrency) {
82
- const balanceChanges = (0, index_1.parseBalanceChanges)(tx.meta, nativeCurrency);
82
+ const balanceChanges = (0, index_1.parseBalanceChanges)(tx.meta, nativeCurrency, tx);
83
83
  return Object.keys(balanceChanges).length > 0 ? balanceChanges : undefined;
84
84
  }
85
85
  function getLockedBalanceChanges(tx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bithomp/xrpl-api",
3
- "version": "3.6.9",
3
+ "version": "3.6.11",
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",