@hashgraphonline/standards-sdk 0.1.140 → 0.1.141

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.
Files changed (33) hide show
  1. package/dist/cjs/hcs-20/points-indexer.d.ts +4 -0
  2. package/dist/cjs/hcs-20/points-indexer.d.ts.map +1 -1
  3. package/dist/cjs/standards-sdk.cjs +1 -1
  4. package/dist/cjs/standards-sdk.cjs.map +1 -1
  5. package/dist/es/hcs-20/points-indexer.d.ts +4 -0
  6. package/dist/es/hcs-20/points-indexer.d.ts.map +1 -1
  7. package/dist/es/standards-sdk.es110.js +5 -5
  8. package/dist/es/standards-sdk.es120.js +1 -1
  9. package/dist/es/standards-sdk.es121.js +1 -1
  10. package/dist/es/standards-sdk.es122.js +5 -5
  11. package/dist/es/standards-sdk.es140.js +51 -167
  12. package/dist/es/standards-sdk.es140.js.map +1 -1
  13. package/dist/es/standards-sdk.es141.js +53 -311
  14. package/dist/es/standards-sdk.es141.js.map +1 -1
  15. package/dist/es/standards-sdk.es142.js +120 -294
  16. package/dist/es/standards-sdk.es142.js.map +1 -1
  17. package/dist/es/standards-sdk.es143.js +191 -322
  18. package/dist/es/standards-sdk.es143.js.map +1 -1
  19. package/dist/es/standards-sdk.es144.js +294 -279
  20. package/dist/es/standards-sdk.es144.js.map +1 -1
  21. package/dist/es/standards-sdk.es145.js +440 -63
  22. package/dist/es/standards-sdk.es145.js.map +1 -1
  23. package/dist/es/standards-sdk.es146.js +330 -55
  24. package/dist/es/standards-sdk.es146.js.map +1 -1
  25. package/dist/es/standards-sdk.es147.js +62 -50
  26. package/dist/es/standards-sdk.es147.js.map +1 -1
  27. package/dist/es/standards-sdk.es57.js +1 -1
  28. package/dist/es/standards-sdk.es59.js +1 -1
  29. package/dist/es/standards-sdk.es60.js +1 -1
  30. package/dist/es/standards-sdk.es63.js +1 -1
  31. package/dist/es/standards-sdk.es78.js +12 -6
  32. package/dist/es/standards-sdk.es78.js.map +1 -1
  33. package/package.json +1 -1
@@ -1,334 +1,349 @@
1
- import { proto } from "@hashgraph/proto";
2
- import { Long, FileId, ContractId } from "@hashgraph/sdk";
3
- import { hasTransactionType } from "./standards-sdk.es145.js";
4
- class UtilParser {
5
- /**
6
- * Parse Utility/System Service transaction using unified dual-branch approach
7
- * This handles both regular transactions and signed transaction variants
8
- */
9
- static parseUtilTransaction(transaction, originalBytes) {
10
- try {
11
- if (originalBytes || transaction.toBytes) {
12
- try {
13
- const bytesToParse = originalBytes || transaction.toBytes();
14
- const decoded = proto.TransactionList.decode(bytesToParse);
15
- if (decoded.transactionList && decoded.transactionList.length > 0) {
16
- const tx = decoded.transactionList[0];
17
- let txBody = null;
18
- if (tx.bodyBytes && tx.bodyBytes.length > 0) {
19
- txBody = proto.TransactionBody.decode(tx.bodyBytes);
20
- } else if (tx.signedTransactionBytes && tx.signedTransactionBytes.length > 0) {
21
- const signedTx = proto.SignedTransaction.decode(
22
- tx.signedTransactionBytes
23
- );
24
- if (signedTx.bodyBytes) {
25
- txBody = proto.TransactionBody.decode(signedTx.bodyBytes);
26
- }
27
- }
28
- if (txBody) {
29
- const protoResult = this.parseFromProtobufTxBody(txBody);
30
- if (protoResult.type && protoResult.type !== "UNKNOWN") {
31
- return protoResult;
32
- }
33
- }
1
+ import { AccountId, Hbar, Long, HbarUnit, TokenId } from "@hashgraph/sdk";
2
+ import { parseKey } from "./standards-sdk.es147.js";
3
+ class CryptoParser {
4
+ static parseCryptoTransfers(cryptoTransfer, result) {
5
+ if (cryptoTransfer.transfers?.accountAmounts) {
6
+ result.transfers = cryptoTransfer.transfers.accountAmounts.map((aa) => {
7
+ const accountId = new AccountId(
8
+ aa.accountID.shardNum ?? 0,
9
+ aa.accountID.realmNum ?? 0,
10
+ aa.accountID.accountNum ?? 0
11
+ );
12
+ const hbarAmount = Hbar.fromTinybars(Long.fromValue(aa.amount));
13
+ return {
14
+ accountId: accountId.toString(),
15
+ amount: hbarAmount.toString(HbarUnit.Hbar),
16
+ isDecimal: true
17
+ };
18
+ });
19
+ }
20
+ if (cryptoTransfer.tokenTransfers) {
21
+ for (const tokenTransferList of cryptoTransfer.tokenTransfers) {
22
+ const tokenId = new TokenId(
23
+ tokenTransferList.token.shardNum ?? 0,
24
+ tokenTransferList.token.realmNum ?? 0,
25
+ tokenTransferList.token.tokenNum ?? 0
26
+ );
27
+ if (tokenTransferList.transfers) {
28
+ for (const transfer of tokenTransferList.transfers) {
29
+ const accountId = new AccountId(
30
+ transfer.accountID.shardNum ?? 0,
31
+ transfer.accountID.realmNum ?? 0,
32
+ transfer.accountID.accountNum ?? 0
33
+ );
34
+ const tokenAmount = Long.fromValue(transfer.amount).toNumber();
35
+ result.tokenTransfers.push({
36
+ tokenId: tokenId.toString(),
37
+ accountId: accountId.toString(),
38
+ amount: tokenAmount
39
+ });
34
40
  }
35
- } catch (protoError) {
36
41
  }
37
42
  }
38
- return this.parseFromTransactionInternals(transaction);
39
- } catch (error) {
40
- return {
41
- type: "UNKNOWN",
42
- humanReadableType: "Unknown Utility Transaction"
43
- };
44
43
  }
45
44
  }
46
- /**
47
- * Parse utility transaction from protobuf TransactionBody
48
- * Handles all utility operations from decoded protobuf data
49
- */
50
- static parseFromProtobufTxBody(txBody) {
51
- if (txBody.utilPrng) {
52
- const utilPrng = this.parseUtilPrng(txBody.utilPrng);
53
- if (utilPrng) {
54
- return {
55
- type: "PRNG",
56
- humanReadableType: "Pseudo Random Number",
57
- utilPrng
58
- };
59
- }
45
+ static parseCryptoDelete(body) {
46
+ if (!body) return void 0;
47
+ const data = {};
48
+ if (body.deleteAccountID) {
49
+ data.deleteAccountId = new AccountId(
50
+ body.deleteAccountID.shardNum ?? 0,
51
+ body.deleteAccountID.realmNum ?? 0,
52
+ body.deleteAccountID.accountNum ?? 0
53
+ ).toString();
60
54
  }
61
- if (txBody.freeze) {
62
- const networkFreeze = this.parseNetworkFreezeFromProto(txBody.freeze);
63
- if (networkFreeze) {
64
- return {
65
- type: "FREEZE",
66
- humanReadableType: "Network Freeze",
67
- freeze: networkFreeze
68
- };
69
- }
55
+ if (body.transferAccountID) {
56
+ data.transferAccountId = new AccountId(
57
+ body.transferAccountID.shardNum ?? 0,
58
+ body.transferAccountID.realmNum ?? 0,
59
+ body.transferAccountID.accountNum ?? 0
60
+ ).toString();
70
61
  }
71
- if (txBody.systemDelete) {
72
- const systemDelete = this.parseSystemDeleteFromProto(txBody.systemDelete);
73
- if (systemDelete) {
74
- return {
75
- type: "SYSTEMDELETE",
76
- humanReadableType: "System Delete",
77
- systemDelete
78
- };
79
- }
62
+ return data;
63
+ }
64
+ static parseCryptoCreateAccount(body) {
65
+ if (!body) return void 0;
66
+ const data = {};
67
+ if (body.initialBalance) {
68
+ data.initialBalance = Hbar.fromTinybars(
69
+ Long.fromValue(body.initialBalance)
70
+ ).toString(HbarUnit.Hbar);
80
71
  }
81
- if (txBody.systemUndelete) {
82
- const systemUndelete = this.parseSystemUndeleteFromProto(
83
- txBody.systemUndelete
84
- );
85
- if (systemUndelete) {
86
- return {
87
- type: "SYSTEMUNDELETE",
88
- humanReadableType: "System Undelete",
89
- systemUndelete
90
- };
91
- }
72
+ if (body.key) {
73
+ data.key = parseKey(body.key);
92
74
  }
93
- if (txBody.nodeCreate) {
94
- const nodeCreate = this.parseNodeCreateFromProto(txBody.nodeCreate);
95
- if (nodeCreate) {
96
- return {
97
- type: "NODECREATE",
98
- humanReadableType: "Node Create",
99
- nodeCreate
100
- };
101
- }
75
+ if (body.receiverSigRequired !== void 0) {
76
+ data.receiverSigRequired = body.receiverSigRequired;
102
77
  }
103
- if (txBody.nodeUpdate) {
104
- const nodeUpdate = this.parseNodeUpdateFromProto(txBody.nodeUpdate);
105
- if (nodeUpdate) {
106
- return {
107
- type: "NODEUPDATE",
108
- humanReadableType: "Node Update",
109
- nodeUpdate
110
- };
111
- }
78
+ if (body.autoRenewPeriod?.seconds) {
79
+ data.autoRenewPeriod = Long.fromValue(
80
+ body.autoRenewPeriod.seconds
81
+ ).toString();
112
82
  }
113
- if (txBody.nodeDelete) {
114
- const nodeDelete = this.parseNodeDeleteFromProto(txBody.nodeDelete);
115
- if (nodeDelete) {
116
- return {
117
- type: "NODEDELETE",
118
- humanReadableType: "Node Delete",
119
- nodeDelete
120
- };
121
- }
83
+ if (body.memo) {
84
+ data.memo = body.memo;
122
85
  }
123
- return {};
124
- }
125
- /**
126
- * Extract utility data from Transaction internal fields
127
- * This handles cases where data is stored in Transaction object internals
128
- */
129
- static parseFromTransactionInternals(transaction) {
130
- try {
131
- const tx = transaction;
132
- if (hasTransactionType(transaction, "utilPrng")) {
133
- const utilPrng = {};
134
- if (tx._range && tx._range !== 0) {
135
- utilPrng.range = tx._range;
136
- }
137
- return {
138
- type: "PRNG",
139
- humanReadableType: "Pseudo Random Number",
140
- utilPrng
141
- };
142
- }
143
- if (hasTransactionType(transaction, "freeze")) {
144
- const networkFreeze = {};
145
- if (tx._startTime) {
146
- networkFreeze.startTime = tx._startTime.toString();
147
- }
148
- if (tx._endTime) {
149
- networkFreeze.endTime = tx._endTime.toString();
150
- }
151
- if (tx._updateFile) {
152
- networkFreeze.updateFile = tx._updateFile.toString();
153
- }
154
- if (tx._fileHash) {
155
- networkFreeze.fileHash = Buffer.from(tx._fileHash).toString("hex");
156
- }
157
- if (tx._freezeType) {
158
- networkFreeze.freezeType = tx._freezeType;
159
- }
160
- return {
161
- type: "FREEZE",
162
- humanReadableType: "Network Freeze",
163
- freeze: networkFreeze
164
- };
165
- }
166
- if (hasTransactionType(transaction, "systemDelete")) {
167
- const systemDelete = {};
168
- if (tx._fileId) {
169
- systemDelete.fileId = tx._fileId.toString();
170
- } else if (tx._contractId) {
171
- systemDelete.contractId = tx._contractId.toString();
172
- }
173
- if (tx._expirationTime) {
174
- systemDelete.expirationTime = tx._expirationTime.toString();
175
- }
176
- return {
177
- type: "SYSTEMDELETE",
178
- humanReadableType: "System Delete",
179
- systemDelete
180
- };
181
- }
182
- if (hasTransactionType(transaction, "systemUndelete")) {
183
- const systemUndelete = {};
184
- if (tx._fileId) {
185
- systemUndelete.fileId = tx._fileId.toString();
186
- } else if (tx._contractId) {
187
- systemUndelete.contractId = tx._contractId.toString();
188
- }
189
- return {
190
- type: "SYSTEMUNDELETE",
191
- humanReadableType: "System Undelete",
192
- systemUndelete
193
- };
194
- }
195
- return {};
196
- } catch (error) {
197
- return {};
86
+ if (body.maxAutomaticTokenAssociations !== void 0) {
87
+ data.maxAutomaticTokenAssociations = body.maxAutomaticTokenAssociations;
198
88
  }
199
- }
200
- /**
201
- * Parse Network Freeze from protobuf data
202
- */
203
- static parseNetworkFreezeFromProto(body) {
204
- if (!body) return void 0;
205
- const data = {};
206
- if (body.startTime?.seconds) {
207
- data.startTime = `${Long.fromValue(
208
- body.startTime.seconds
209
- ).toString()}.${body.startTime.nanos ?? 0}`;
210
- }
211
- if (body.updateFile) {
212
- data.updateFile = new FileId(
213
- body.updateFile.shardNum ?? 0,
214
- body.updateFile.realmNum ?? 0,
215
- body.updateFile.fileNum ?? 0
89
+ if (body.stakedAccountId) {
90
+ data.stakedAccountId = new AccountId(
91
+ body.stakedAccountId.shardNum ?? 0,
92
+ body.stakedAccountId.realmNum ?? 0,
93
+ body.stakedAccountId.accountNum ?? 0
216
94
  ).toString();
95
+ } else if (body.stakedNodeId !== null && body.stakedNodeId !== void 0) {
96
+ data.stakedNodeId = Long.fromValue(body.stakedNodeId).toString();
217
97
  }
218
- if (body.fileHash && body.fileHash.length > 0) {
219
- data.fileHash = Buffer.from(body.fileHash).toString("hex");
98
+ if (body.declineReward !== void 0) {
99
+ data.declineReward = body.declineReward;
220
100
  }
221
- if (body.freezeType !== void 0) {
222
- const freezeTypes = [
223
- "FREEZE_ONLY",
224
- "PREPARE_UPGRADE",
225
- "FREEZE_UPGRADE",
226
- "FREEZE_ABORT"
227
- ];
228
- data.freezeType = freezeTypes[body.freezeType] || "FREEZE_ONLY";
101
+ if (body.alias && body.alias.length > 0) {
102
+ data.alias = Buffer.from(body.alias).toString("hex");
229
103
  }
230
104
  return data;
231
105
  }
232
- /**
233
- * Parse System Delete from protobuf data
234
- */
235
- static parseSystemDeleteFromProto(body) {
106
+ static parseCryptoUpdateAccount(body) {
236
107
  if (!body) return void 0;
237
108
  const data = {};
238
- if (body.fileID) {
239
- data.fileId = new FileId(
240
- body.fileID.shardNum ?? 0,
241
- body.fileID.realmNum ?? 0,
242
- body.fileID.fileNum ?? 0
243
- ).toString();
244
- } else if (body.contractID) {
245
- data.contractId = new ContractId(
246
- body.contractID.shardNum ?? 0,
247
- body.contractID.realmNum ?? 0,
248
- body.contractID.contractNum ?? 0
109
+ if (body.accountIDToUpdate) {
110
+ data.accountIdToUpdate = new AccountId(
111
+ body.accountIDToUpdate.shardNum ?? 0,
112
+ body.accountIDToUpdate.realmNum ?? 0,
113
+ body.accountIDToUpdate.accountNum ?? 0
249
114
  ).toString();
250
115
  }
116
+ if (body.key) {
117
+ data.key = parseKey(body.key);
118
+ }
251
119
  if (body.expirationTime?.seconds) {
252
- data.expirationTime = Long.fromValue(
120
+ data.expirationTime = `${Long.fromValue(
253
121
  body.expirationTime.seconds
254
- ).toString();
122
+ ).toString()}.${body.expirationTime.nanos}`;
255
123
  }
256
- return data;
257
- }
258
- /**
259
- * Parse System Undelete from protobuf data
260
- */
261
- static parseSystemUndeleteFromProto(body) {
262
- if (!body) return void 0;
263
- const data = {};
264
- if (body.fileID) {
265
- data.fileId = new FileId(
266
- body.fileID.shardNum ?? 0,
267
- body.fileID.realmNum ?? 0,
268
- body.fileID.fileNum ?? 0
124
+ if (body.receiverSigRequired !== null && body.receiverSigRequired !== void 0) {
125
+ data.receiverSigRequired = Boolean(body.receiverSigRequired);
126
+ }
127
+ if (body.autoRenewPeriod?.seconds) {
128
+ data.autoRenewPeriod = Long.fromValue(
129
+ body.autoRenewPeriod.seconds
269
130
  ).toString();
270
- } else if (body.contractID) {
271
- data.contractId = new ContractId(
272
- body.contractID.shardNum ?? 0,
273
- body.contractID.realmNum ?? 0,
274
- body.contractID.contractNum ?? 0
131
+ }
132
+ if (body.memo?.value !== void 0) {
133
+ data.memo = body.memo.value;
134
+ }
135
+ if (body.maxAutomaticTokenAssociations?.value !== void 0) {
136
+ data.maxAutomaticTokenAssociations = body.maxAutomaticTokenAssociations.value;
137
+ }
138
+ if (body.stakedAccountId) {
139
+ data.stakedAccountId = new AccountId(
140
+ body.stakedAccountId.shardNum ?? 0,
141
+ body.stakedAccountId.realmNum ?? 0,
142
+ body.stakedAccountId.accountNum ?? 0
275
143
  ).toString();
144
+ data.stakedNodeId = void 0;
145
+ } else if (body.stakedNodeId !== null && body.stakedNodeId !== void 0) {
146
+ data.stakedNodeId = Long.fromValue(body.stakedNodeId).toString();
147
+ data.stakedAccountId = void 0;
148
+ } else {
149
+ data.stakedAccountId = void 0;
150
+ data.stakedNodeId = void 0;
151
+ }
152
+ if (body.declineReward !== null && body.declineReward !== void 0) {
153
+ data.declineReward = Boolean(body.declineReward);
276
154
  }
277
155
  return data;
278
156
  }
279
- /**
280
- * Parse Node Create from protobuf data
281
- */
282
- static parseNodeCreateFromProto(body) {
157
+ static parseCryptoApproveAllowance(body) {
283
158
  if (!body) return void 0;
284
159
  const data = {};
285
- if (body.nodeId !== void 0) {
286
- data.nodeId = Long.fromValue(body.nodeId).toNumber();
160
+ if (body.cryptoAllowances && body.cryptoAllowances.length > 0) {
161
+ data.hbarAllowances = body.cryptoAllowances.map((a) => ({
162
+ ownerAccountId: new AccountId(
163
+ a.owner.shardNum ?? 0,
164
+ a.owner.realmNum ?? 0,
165
+ a.owner.accountNum ?? 0
166
+ ).toString(),
167
+ spenderAccountId: new AccountId(
168
+ a.spender.shardNum ?? 0,
169
+ a.spender.realmNum ?? 0,
170
+ a.spender.accountNum ?? 0
171
+ ).toString(),
172
+ amount: Hbar.fromTinybars(Long.fromValue(a.amount)).toString(
173
+ HbarUnit.Hbar
174
+ )
175
+ }));
176
+ }
177
+ if (body.tokenAllowances && body.tokenAllowances.length > 0) {
178
+ data.tokenAllowances = body.tokenAllowances.map((a) => ({
179
+ tokenId: new TokenId(
180
+ a.tokenId.shardNum ?? 0,
181
+ a.tokenId.realmNum ?? 0,
182
+ a.tokenId.tokenNum ?? 0
183
+ ).toString(),
184
+ ownerAccountId: new AccountId(
185
+ a.owner.shardNum ?? 0,
186
+ a.owner.realmNum ?? 0,
187
+ a.owner.accountNum ?? 0
188
+ ).toString(),
189
+ spenderAccountId: new AccountId(
190
+ a.spender.shardNum ?? 0,
191
+ a.spender.realmNum ?? 0,
192
+ a.spender.accountNum ?? 0
193
+ ).toString(),
194
+ amount: Long.fromValue(a.amount).toString()
195
+ }));
196
+ }
197
+ if (body.nftAllowances && body.nftAllowances.length > 0) {
198
+ data.nftAllowances = body.nftAllowances.map((a) => {
199
+ const allowance = {};
200
+ if (a.tokenId)
201
+ allowance.tokenId = new TokenId(
202
+ a.tokenId.shardNum ?? 0,
203
+ a.tokenId.realmNum ?? 0,
204
+ a.tokenId.tokenNum ?? 0
205
+ ).toString();
206
+ if (a.owner)
207
+ allowance.ownerAccountId = new AccountId(
208
+ a.owner.shardNum ?? 0,
209
+ a.owner.realmNum ?? 0,
210
+ a.owner.accountNum ?? 0
211
+ ).toString();
212
+ if (a.spender)
213
+ allowance.spenderAccountId = new AccountId(
214
+ a.spender.shardNum ?? 0,
215
+ a.spender.realmNum ?? 0,
216
+ a.spender.accountNum ?? 0
217
+ ).toString();
218
+ if (a.serialNumbers && a.serialNumbers.length > 0)
219
+ allowance.serialNumbers = a.serialNumbers.map(
220
+ (sn) => Long.fromValue(sn).toString()
221
+ );
222
+ if (a.approvedForAll?.value !== void 0)
223
+ allowance.approvedForAll = a.approvedForAll.value;
224
+ if (a.delegatingSpender)
225
+ allowance.delegatingSpender = new AccountId(
226
+ a.delegatingSpender.shardNum ?? 0,
227
+ a.delegatingSpender.realmNum ?? 0,
228
+ a.delegatingSpender.accountNum ?? 0
229
+ ).toString();
230
+ return allowance;
231
+ });
287
232
  }
288
233
  return data;
289
234
  }
290
- /**
291
- * Parse Node Update from protobuf data
292
- */
293
- static parseNodeUpdateFromProto(body) {
235
+ static parseCryptoDeleteAllowance(body) {
294
236
  if (!body) return void 0;
295
237
  const data = {};
296
- if (body.nodeId !== void 0) {
297
- data.nodeId = Long.fromValue(body.nodeId).toNumber();
238
+ if (body.nftAllowances && body.nftAllowances.length > 0) {
239
+ data.nftAllowancesToRemove = body.nftAllowances.map((a) => ({
240
+ ownerAccountId: new AccountId(
241
+ a.owner.shardNum ?? 0,
242
+ a.owner.realmNum ?? 0,
243
+ a.owner.accountNum ?? 0
244
+ ).toString(),
245
+ tokenId: new TokenId(
246
+ a.tokenId.shardNum ?? 0,
247
+ a.tokenId.realmNum ?? 0,
248
+ a.tokenId.tokenNum ?? 0
249
+ ).toString(),
250
+ serialNumbers: a.serialNumbers ? a.serialNumbers.map((sn) => Long.fromValue(sn).toString()) : []
251
+ }));
298
252
  }
299
253
  return data;
300
254
  }
301
255
  /**
302
- * Parse Node Delete from protobuf data
256
+ * Extract HBAR transfers from Transaction object
303
257
  */
304
- static parseNodeDeleteFromProto(body) {
305
- if (!body) return void 0;
306
- const data = {};
307
- if (body.nodeId !== void 0) {
308
- data.nodeId = Long.fromValue(body.nodeId).toNumber();
258
+ static extractHbarTransfersFromTransaction(transaction) {
259
+ const transfers = [];
260
+ try {
261
+ const hbarTransfers = transaction._hbarTransfers;
262
+ if (Array.isArray(hbarTransfers)) {
263
+ hbarTransfers.forEach((transfer) => {
264
+ if (transfer.accountId && transfer.amount) {
265
+ const amountInTinybars = transfer.amount.toTinybars();
266
+ const amountInHbar = Number(amountInTinybars) / 1e8;
267
+ transfers.push({
268
+ accountId: transfer.accountId.toString(),
269
+ amount: amountInHbar
270
+ });
271
+ }
272
+ });
273
+ }
274
+ } catch (error) {
309
275
  }
310
- return data;
276
+ return transfers;
311
277
  }
312
- static parseUtilPrng(body) {
313
- if (!body) return void 0;
314
- const data = {};
315
- if (body.range && body.range !== 0) {
316
- data.range = body.range;
278
+ /**
279
+ * Extract token transfers from Transaction object
280
+ */
281
+ static extractTokenTransfersFromTransaction(transaction) {
282
+ const tokenTransfers = [];
283
+ try {
284
+ const tokenTransfersList = transaction._tokenTransfers;
285
+ if (Array.isArray(tokenTransfersList)) {
286
+ tokenTransfersList.forEach((tokenTransfer) => {
287
+ if (tokenTransfer.tokenId && Array.isArray(tokenTransfer.transfers)) {
288
+ const transfers = tokenTransfer.transfers.map((transfer) => ({
289
+ accountId: transfer.accountId?.toString() || "Unknown",
290
+ amount: Number(transfer.amount || 0)
291
+ }));
292
+ tokenTransfers.push({
293
+ tokenId: tokenTransfer.tokenId.toString(),
294
+ transfers
295
+ });
296
+ }
297
+ });
298
+ }
299
+ } catch (error) {
317
300
  }
318
- return data;
319
- }
320
- static parseFreeze(body) {
321
- return this.parseNetworkFreezeFromProto(body);
301
+ return tokenTransfers;
322
302
  }
323
303
  /**
324
- * Parse Utility/System Service transaction from Transaction object
325
- * This is the unified entry point that delegates to the comprehensive parsing logic
304
+ * Parse crypto transaction from Transaction object with comprehensive extraction
305
+ * This is the unified entry point that handles both protobuf and internal field extraction
326
306
  */
327
307
  static parseFromTransactionObject(transaction) {
328
- return this.parseUtilTransaction(transaction);
308
+ try {
309
+ const hbarTransfers = this.extractHbarTransfersFromTransaction(transaction);
310
+ const tokenTransfers = this.extractTokenTransfersFromTransaction(transaction);
311
+ if (hbarTransfers.length > 0 || tokenTransfers.length > 0) {
312
+ const convertedTransfers = hbarTransfers.map((transfer) => ({
313
+ accountId: transfer.accountId,
314
+ amount: transfer.amount.toString() + " ℏ",
315
+ isDecimal: true
316
+ }));
317
+ const convertedTokenTransfers = tokenTransfers.flatMap(
318
+ (tokenGroup) => tokenGroup.transfers.map((transfer) => ({
319
+ tokenId: tokenGroup.tokenId,
320
+ accountId: transfer.accountId,
321
+ amount: transfer.amount
322
+ }))
323
+ );
324
+ if (hbarTransfers.length > 0) {
325
+ return {
326
+ type: "CRYPTOTRANSFER",
327
+ humanReadableType: "Crypto Transfer",
328
+ transfers: convertedTransfers,
329
+ tokenTransfers: convertedTokenTransfers
330
+ };
331
+ } else if (tokenTransfers.length > 0) {
332
+ return {
333
+ type: "TOKENTRANSFER",
334
+ humanReadableType: "Token Transfer",
335
+ transfers: convertedTransfers,
336
+ tokenTransfers: convertedTokenTransfers
337
+ };
338
+ }
339
+ }
340
+ return {};
341
+ } catch (error) {
342
+ return {};
343
+ }
329
344
  }
330
345
  }
331
346
  export {
332
- UtilParser
347
+ CryptoParser
333
348
  };
334
349
  //# sourceMappingURL=standards-sdk.es144.js.map