@hashgraphonline/standards-sdk 0.1.141-canary.2 → 0.1.141-canary.3
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/dist/cjs/standards-sdk.cjs +1 -1
- package/dist/cjs/standards-sdk.cjs.map +1 -1
- package/dist/es/standards-sdk.es109.js +1 -1
- package/dist/es/standards-sdk.es110.js +5 -5
- package/dist/es/standards-sdk.es120.js +1 -1
- package/dist/es/standards-sdk.es121.js +1 -1
- package/dist/es/standards-sdk.es122.js +5 -5
- package/dist/es/standards-sdk.es124.js +6 -6
- package/dist/es/standards-sdk.es124.js.map +1 -1
- package/dist/es/standards-sdk.es125.js +1 -1
- package/dist/es/standards-sdk.es127.js +1 -1
- package/dist/es/standards-sdk.es137.js +760 -17
- package/dist/es/standards-sdk.es137.js.map +1 -1
- package/dist/es/standards-sdk.es138.js +56 -760
- package/dist/es/standards-sdk.es138.js.map +1 -1
- package/dist/es/standards-sdk.es139.js +45 -12255
- package/dist/es/standards-sdk.es139.js.map +1 -1
- package/dist/es/standards-sdk.es140.js +12235 -133
- package/dist/es/standards-sdk.es140.js.map +1 -1
- package/dist/es/standards-sdk.es141.js +139 -289
- package/dist/es/standards-sdk.es141.js.map +1 -1
- package/dist/es/standards-sdk.es142.js +274 -298
- package/dist/es/standards-sdk.es142.js.map +1 -1
- package/dist/es/standards-sdk.es143.js +262 -369
- package/dist/es/standards-sdk.es143.js.map +1 -1
- package/dist/es/standards-sdk.es144.js +316 -194
- package/dist/es/standards-sdk.es144.js.map +1 -1
- package/dist/es/standards-sdk.es145.js +319 -64
- package/dist/es/standards-sdk.es145.js.map +1 -1
- package/dist/es/standards-sdk.es146.js +69 -49
- package/dist/es/standards-sdk.es146.js.map +1 -1
- package/dist/es/standards-sdk.es147.js +15 -62
- package/dist/es/standards-sdk.es147.js.map +1 -1
- package/dist/es/standards-sdk.es17.js +1 -1
- package/dist/es/standards-sdk.es19.js +2 -2
- package/dist/es/standards-sdk.es20.js +2 -2
- package/dist/es/standards-sdk.es28.js +2 -2
- package/dist/es/standards-sdk.es31.js +1 -1
- package/dist/es/standards-sdk.es32.js +1 -1
- package/dist/es/standards-sdk.es36.js +2 -2
- package/dist/es/standards-sdk.es37.js +1 -1
- package/dist/es/standards-sdk.es38.js +1 -1
- package/dist/es/standards-sdk.es57.js +1 -1
- package/dist/es/standards-sdk.es59.js +1 -1
- package/dist/es/standards-sdk.es60.js +1 -1
- package/dist/es/standards-sdk.es61.js +1 -1
- package/dist/es/standards-sdk.es63.js +1 -1
- package/dist/es/standards-sdk.es65.js +1 -1
- package/dist/es/standards-sdk.es66.js +1 -1
- package/dist/es/standards-sdk.es78.js +1 -1
- package/package.json +1 -1
|
@@ -1,349 +1,325 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { proto } from "@hashgraph/proto";
|
|
2
|
+
import { Long } from "@hashgraph/sdk";
|
|
3
|
+
import { hasTransactionType, parseKey } from "./standards-sdk.es146.js";
|
|
4
|
+
import { Buffer } from "buffer";
|
|
5
|
+
class FileParser {
|
|
6
|
+
/**
|
|
7
|
+
* Parse File Service transaction using unified dual-branch approach
|
|
8
|
+
* This handles both regular transactions and signed transaction variants
|
|
9
|
+
*/
|
|
10
|
+
static parseFileTransaction(transaction, originalBytes) {
|
|
11
|
+
try {
|
|
12
|
+
if (originalBytes || transaction.toBytes) {
|
|
13
|
+
try {
|
|
14
|
+
const bytesToParse = originalBytes || transaction.toBytes();
|
|
15
|
+
const decoded = proto.TransactionList.decode(bytesToParse);
|
|
16
|
+
if (decoded.transactionList && decoded.transactionList.length > 0) {
|
|
17
|
+
const tx = decoded.transactionList[0];
|
|
18
|
+
let txBody = null;
|
|
19
|
+
if (tx.bodyBytes && tx.bodyBytes.length > 0) {
|
|
20
|
+
txBody = proto.TransactionBody.decode(tx.bodyBytes);
|
|
21
|
+
} else if (tx.signedTransactionBytes && tx.signedTransactionBytes.length > 0) {
|
|
22
|
+
const signedTx = proto.SignedTransaction.decode(
|
|
23
|
+
tx.signedTransactionBytes
|
|
24
|
+
);
|
|
25
|
+
if (signedTx.bodyBytes) {
|
|
26
|
+
txBody = proto.TransactionBody.decode(signedTx.bodyBytes);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (txBody) {
|
|
30
|
+
const protoResult = this.parseFromProtobufTxBody(txBody);
|
|
31
|
+
if (protoResult.type && protoResult.type !== "UNKNOWN") {
|
|
32
|
+
return protoResult;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} catch (protoError) {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return this.parseFromTransactionInternals(transaction);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
return { type: "UNKNOWN", humanReadableType: "Unknown File Transaction" };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parse file transaction from protobuf TransactionBody
|
|
46
|
+
* Handles all file operations from decoded protobuf data
|
|
47
|
+
*/
|
|
48
|
+
static parseFromProtobufTxBody(txBody) {
|
|
49
|
+
if (txBody.fileCreate) {
|
|
50
|
+
const fileCreate = this.parseFileCreate(txBody.fileCreate);
|
|
51
|
+
if (fileCreate) {
|
|
13
52
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
53
|
+
type: "FILECREATE",
|
|
54
|
+
humanReadableType: "File Create",
|
|
55
|
+
fileCreate
|
|
17
56
|
};
|
|
18
|
-
}
|
|
57
|
+
}
|
|
19
58
|
}
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
59
|
+
if (txBody.fileAppend) {
|
|
60
|
+
const fileAppend = this.parseFileAppend(txBody.fileAppend);
|
|
61
|
+
if (fileAppend) {
|
|
62
|
+
return {
|
|
63
|
+
type: "FILEAPPEND",
|
|
64
|
+
humanReadableType: "File Append",
|
|
65
|
+
fileAppend
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (txBody.fileUpdate) {
|
|
70
|
+
const fileUpdate = this.parseFileUpdate(txBody.fileUpdate);
|
|
71
|
+
if (fileUpdate) {
|
|
72
|
+
return {
|
|
73
|
+
type: "FILEUPDATE",
|
|
74
|
+
humanReadableType: "File Update",
|
|
75
|
+
fileUpdate
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (txBody.fileDelete) {
|
|
80
|
+
const fileDelete = this.parseFileDelete(txBody.fileDelete);
|
|
81
|
+
if (fileDelete) {
|
|
82
|
+
return {
|
|
83
|
+
type: "FILEDELETE",
|
|
84
|
+
humanReadableType: "File Delete",
|
|
85
|
+
fileDelete
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return {};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Extract file data from Transaction internal fields
|
|
93
|
+
* This handles cases where data is stored in Transaction object internals
|
|
94
|
+
*/
|
|
95
|
+
static parseFromTransactionInternals(transaction) {
|
|
96
|
+
try {
|
|
97
|
+
const tx = transaction;
|
|
98
|
+
if (hasTransactionType(transaction, "fileCreate")) {
|
|
99
|
+
const fileCreate = {};
|
|
100
|
+
if (tx._contents) {
|
|
101
|
+
const contentInfo = this.analyzeContent(tx._contents);
|
|
102
|
+
fileCreate.contents = contentInfo.encoded;
|
|
103
|
+
if (contentInfo.contentType) {
|
|
104
|
+
fileCreate.contentType = contentInfo.contentType;
|
|
105
|
+
}
|
|
106
|
+
if (contentInfo.size) {
|
|
107
|
+
fileCreate.contentSize = contentInfo.size;
|
|
40
108
|
}
|
|
41
109
|
}
|
|
110
|
+
if (tx._keys && tx._keys.length > 0) {
|
|
111
|
+
const keyList = {
|
|
112
|
+
keys: tx._keys
|
|
113
|
+
};
|
|
114
|
+
fileCreate.keys = parseKey({ keyList });
|
|
115
|
+
}
|
|
116
|
+
if (tx._expirationTime) {
|
|
117
|
+
fileCreate.expirationTime = tx._expirationTime.toString();
|
|
118
|
+
}
|
|
119
|
+
if (tx._memo) {
|
|
120
|
+
fileCreate.memo = tx._memo;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
type: "FILECREATE",
|
|
124
|
+
humanReadableType: "File Create",
|
|
125
|
+
fileCreate
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (hasTransactionType(transaction, "fileAppend")) {
|
|
129
|
+
const fileAppend = {
|
|
130
|
+
fileId: tx._fileId.toString()
|
|
131
|
+
};
|
|
132
|
+
if (tx._contents) {
|
|
133
|
+
const contentInfo = this.analyzeContent(tx._contents);
|
|
134
|
+
fileAppend.contents = contentInfo.encoded;
|
|
135
|
+
if (contentInfo.size) {
|
|
136
|
+
fileAppend.contentSize = contentInfo.size;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
type: "FILEAPPEND",
|
|
141
|
+
humanReadableType: "File Append",
|
|
142
|
+
fileAppend
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (hasTransactionType(transaction, "fileUpdate")) {
|
|
146
|
+
const fileUpdate = {
|
|
147
|
+
fileId: tx._fileId.toString()
|
|
148
|
+
};
|
|
149
|
+
if (tx._contents) {
|
|
150
|
+
const contentInfo = this.analyzeContent(tx._contents);
|
|
151
|
+
fileUpdate.contents = contentInfo.encoded;
|
|
152
|
+
if (contentInfo.size) {
|
|
153
|
+
fileUpdate.contentSize = contentInfo.size;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (tx._keys && tx._keys.length > 0) {
|
|
157
|
+
const keyList = {
|
|
158
|
+
keys: tx._keys
|
|
159
|
+
};
|
|
160
|
+
fileUpdate.keys = parseKey({ keyList });
|
|
161
|
+
}
|
|
162
|
+
if (tx._expirationTime) {
|
|
163
|
+
fileUpdate.expirationTime = tx._expirationTime.toString();
|
|
164
|
+
}
|
|
165
|
+
if (tx._memo) {
|
|
166
|
+
fileUpdate.memo = tx._memo;
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
type: "FILEUPDATE",
|
|
170
|
+
humanReadableType: "File Update",
|
|
171
|
+
fileUpdate
|
|
172
|
+
};
|
|
42
173
|
}
|
|
174
|
+
if (hasTransactionType(transaction, "fileDelete")) {
|
|
175
|
+
const fileDelete = {
|
|
176
|
+
fileId: tx._fileId.toString()
|
|
177
|
+
};
|
|
178
|
+
return {
|
|
179
|
+
type: "FILEDELETE",
|
|
180
|
+
humanReadableType: "File Delete",
|
|
181
|
+
fileDelete
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return {};
|
|
185
|
+
} catch (error) {
|
|
186
|
+
return {};
|
|
43
187
|
}
|
|
44
188
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
189
|
+
/**
|
|
190
|
+
* Enhanced content analysis with type detection and metadata
|
|
191
|
+
*/
|
|
192
|
+
static analyzeContent(contents) {
|
|
193
|
+
const size = contents.length;
|
|
194
|
+
const contentBuffer = Buffer.from(contents);
|
|
195
|
+
let contentType;
|
|
196
|
+
if (size >= 4) {
|
|
197
|
+
const header = contentBuffer.subarray(0, 4);
|
|
198
|
+
const headerHex = header.toString("hex");
|
|
199
|
+
const signatures = {
|
|
200
|
+
"89504e47": "image/png",
|
|
201
|
+
ffd8ffe0: "image/jpeg",
|
|
202
|
+
ffd8ffe1: "image/jpeg",
|
|
203
|
+
"47494638": "image/gif",
|
|
204
|
+
"25504446": "application/pdf",
|
|
205
|
+
"504b0304": "application/zip",
|
|
206
|
+
"7f454c46": "application/x-executable",
|
|
207
|
+
d0cf11e0: "application/msoffice"
|
|
208
|
+
};
|
|
209
|
+
contentType = signatures[headerHex.toLowerCase()];
|
|
54
210
|
}
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
211
|
+
if (!contentType) {
|
|
212
|
+
try {
|
|
213
|
+
const textContent = contentBuffer.toString("utf8");
|
|
214
|
+
const hasControlChars = /[\x00-\x08\x0B\x0E-\x1F\x7F]/.test(
|
|
215
|
+
textContent
|
|
216
|
+
);
|
|
217
|
+
const hasReplacementChars = textContent.includes("�");
|
|
218
|
+
if (!hasControlChars && !hasReplacementChars) {
|
|
219
|
+
if (textContent.trim().startsWith("{") && textContent.trim().endsWith("}")) {
|
|
220
|
+
contentType = "application/json";
|
|
221
|
+
} else if (textContent.includes("<?xml") || textContent.includes("<html")) {
|
|
222
|
+
contentType = "text/xml";
|
|
223
|
+
} else if (textContent.includes("<!DOCTYPE html")) {
|
|
224
|
+
contentType = "text/html";
|
|
225
|
+
} else {
|
|
226
|
+
contentType = "text/plain";
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
contentType = "application/octet-stream";
|
|
230
|
+
}
|
|
231
|
+
} catch {
|
|
232
|
+
contentType = "application/octet-stream";
|
|
233
|
+
}
|
|
61
234
|
}
|
|
62
|
-
|
|
235
|
+
let encoded;
|
|
236
|
+
if (contentType?.startsWith("text/") || contentType === "application/json") {
|
|
237
|
+
try {
|
|
238
|
+
encoded = contentBuffer.toString("utf8");
|
|
239
|
+
if (encoded.includes("�") || /[\x00-\x08\x0B\x0E-\x1F\x7F]/.test(encoded)) {
|
|
240
|
+
encoded = contentBuffer.toString("base64");
|
|
241
|
+
}
|
|
242
|
+
} catch {
|
|
243
|
+
encoded = contentBuffer.toString("base64");
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
encoded = contentBuffer.toString("base64");
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
encoded,
|
|
250
|
+
contentType,
|
|
251
|
+
size
|
|
252
|
+
};
|
|
63
253
|
}
|
|
64
|
-
static
|
|
254
|
+
static parseFileCreate(body) {
|
|
65
255
|
if (!body) return void 0;
|
|
66
256
|
const data = {};
|
|
67
|
-
if (body.
|
|
68
|
-
data.
|
|
69
|
-
|
|
70
|
-
).toString(
|
|
71
|
-
}
|
|
72
|
-
if (body.key) {
|
|
73
|
-
data.key = parseKey(body.key);
|
|
257
|
+
if (body.expirationTime?.seconds) {
|
|
258
|
+
data.expirationTime = `${Long.fromValue(
|
|
259
|
+
body.expirationTime.seconds
|
|
260
|
+
).toString()}.${body.expirationTime.nanos}`;
|
|
74
261
|
}
|
|
75
|
-
if (body.
|
|
76
|
-
data.
|
|
262
|
+
if (body.keys) {
|
|
263
|
+
data.keys = parseKey({ keyList: body.keys });
|
|
77
264
|
}
|
|
78
|
-
if (body.
|
|
79
|
-
data.
|
|
80
|
-
body.autoRenewPeriod.seconds
|
|
81
|
-
).toString();
|
|
265
|
+
if (body.contents) {
|
|
266
|
+
data.contents = Buffer.from(body.contents).toString("base64");
|
|
82
267
|
}
|
|
83
268
|
if (body.memo) {
|
|
84
269
|
data.memo = body.memo;
|
|
85
270
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (body
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
body.stakedAccountId.accountNum ?? 0
|
|
94
|
-
).toString();
|
|
95
|
-
} else if (body.stakedNodeId !== null && body.stakedNodeId !== void 0) {
|
|
96
|
-
data.stakedNodeId = Long.fromValue(body.stakedNodeId).toString();
|
|
97
|
-
}
|
|
98
|
-
if (body.declineReward !== void 0) {
|
|
99
|
-
data.declineReward = body.declineReward;
|
|
271
|
+
return data;
|
|
272
|
+
}
|
|
273
|
+
static parseFileAppend(body) {
|
|
274
|
+
if (!body) return void 0;
|
|
275
|
+
const data = {};
|
|
276
|
+
if (body.fileID) {
|
|
277
|
+
data.fileId = `${body.fileID.shardNum ?? 0}.${body.fileID.realmNum ?? 0}.${body.fileID.fileNum ?? 0}`;
|
|
100
278
|
}
|
|
101
|
-
if (body.
|
|
102
|
-
data.
|
|
279
|
+
if (body.contents) {
|
|
280
|
+
data.contents = Buffer.from(body.contents).toString("base64");
|
|
103
281
|
}
|
|
104
282
|
return data;
|
|
105
283
|
}
|
|
106
|
-
static
|
|
284
|
+
static parseFileUpdate(body) {
|
|
107
285
|
if (!body) return void 0;
|
|
108
286
|
const data = {};
|
|
109
|
-
if (body.
|
|
110
|
-
data.
|
|
111
|
-
body.accountIDToUpdate.shardNum ?? 0,
|
|
112
|
-
body.accountIDToUpdate.realmNum ?? 0,
|
|
113
|
-
body.accountIDToUpdate.accountNum ?? 0
|
|
114
|
-
).toString();
|
|
115
|
-
}
|
|
116
|
-
if (body.key) {
|
|
117
|
-
data.key = parseKey(body.key);
|
|
287
|
+
if (body.fileID) {
|
|
288
|
+
data.fileId = `${body.fileID.shardNum ?? 0}.${body.fileID.realmNum ?? 0}.${body.fileID.fileNum ?? 0}`;
|
|
118
289
|
}
|
|
119
290
|
if (body.expirationTime?.seconds) {
|
|
120
291
|
data.expirationTime = `${Long.fromValue(
|
|
121
292
|
body.expirationTime.seconds
|
|
122
293
|
).toString()}.${body.expirationTime.nanos}`;
|
|
123
294
|
}
|
|
124
|
-
if (body.
|
|
125
|
-
data.
|
|
295
|
+
if (body.keys) {
|
|
296
|
+
data.keys = parseKey({ keyList: body.keys });
|
|
126
297
|
}
|
|
127
|
-
if (body.
|
|
128
|
-
data.
|
|
129
|
-
body.autoRenewPeriod.seconds
|
|
130
|
-
).toString();
|
|
298
|
+
if (body.contents) {
|
|
299
|
+
data.contents = Buffer.from(body.contents).toString("base64");
|
|
131
300
|
}
|
|
132
301
|
if (body.memo?.value !== void 0) {
|
|
133
302
|
data.memo = body.memo.value;
|
|
134
303
|
}
|
|
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
|
|
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);
|
|
154
|
-
}
|
|
155
304
|
return data;
|
|
156
305
|
}
|
|
157
|
-
static
|
|
306
|
+
static parseFileDelete(body) {
|
|
158
307
|
if (!body) return void 0;
|
|
159
308
|
const data = {};
|
|
160
|
-
if (body.
|
|
161
|
-
data.
|
|
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
|
-
});
|
|
309
|
+
if (body.fileID) {
|
|
310
|
+
data.fileId = `${body.fileID.shardNum ?? 0}.${body.fileID.realmNum ?? 0}.${body.fileID.fileNum ?? 0}`;
|
|
232
311
|
}
|
|
233
312
|
return data;
|
|
234
313
|
}
|
|
235
|
-
static parseCryptoDeleteAllowance(body) {
|
|
236
|
-
if (!body) return void 0;
|
|
237
|
-
const data = {};
|
|
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
|
-
}));
|
|
252
|
-
}
|
|
253
|
-
return data;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Extract HBAR transfers from Transaction object
|
|
257
|
-
*/
|
|
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) {
|
|
275
|
-
}
|
|
276
|
-
return transfers;
|
|
277
|
-
}
|
|
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) {
|
|
300
|
-
}
|
|
301
|
-
return tokenTransfers;
|
|
302
|
-
}
|
|
303
314
|
/**
|
|
304
|
-
* Parse
|
|
305
|
-
* This is the unified entry point that
|
|
315
|
+
* Parse File Service transaction from Transaction object
|
|
316
|
+
* This is the unified entry point that delegates to the comprehensive parsing logic
|
|
306
317
|
*/
|
|
307
318
|
static parseFromTransactionObject(transaction) {
|
|
308
|
-
|
|
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
|
-
}
|
|
319
|
+
return this.parseFileTransaction(transaction);
|
|
344
320
|
}
|
|
345
321
|
}
|
|
346
322
|
export {
|
|
347
|
-
|
|
323
|
+
FileParser
|
|
348
324
|
};
|
|
349
325
|
//# sourceMappingURL=standards-sdk.es142.js.map
|