@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,299 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 {
|
|
42
|
-
type: "UNKNOWN",
|
|
43
|
-
humanReadableType: "Unknown Contract Transaction"
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Parse contract transaction from protobuf TransactionBody
|
|
49
|
-
* Handles all contract operations from decoded protobuf data
|
|
50
|
-
*/
|
|
51
|
-
static parseFromProtobufTxBody(txBody) {
|
|
52
|
-
if (txBody.contractCall) {
|
|
53
|
-
const contractCall = this.parseContractCall(txBody.contractCall);
|
|
54
|
-
if (contractCall) {
|
|
55
|
-
return {
|
|
56
|
-
type: "CONTRACTCALL",
|
|
57
|
-
humanReadableType: "Contract Call",
|
|
58
|
-
contractCall
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (txBody.contractCreateInstance) {
|
|
63
|
-
const contractCreate = this.parseContractCreate(
|
|
64
|
-
txBody.contractCreateInstance
|
|
65
|
-
);
|
|
66
|
-
if (contractCreate) {
|
|
67
|
-
return {
|
|
68
|
-
type: "CONTRACTCREATE",
|
|
69
|
-
humanReadableType: "Contract Create",
|
|
70
|
-
contractCreate
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (txBody.contractUpdateInstance) {
|
|
75
|
-
const contractUpdate = this.parseContractUpdate(
|
|
76
|
-
txBody.contractUpdateInstance
|
|
77
|
-
);
|
|
78
|
-
if (contractUpdate) {
|
|
1
|
+
import { AccountId, Hbar, Long, HbarUnit, TokenId } from "@hashgraph/sdk";
|
|
2
|
+
import { parseKey } from "./standards-sdk.es146.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));
|
|
79
13
|
return {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
14
|
+
accountId: accountId.toString(),
|
|
15
|
+
amount: hbarAmount.toString(HbarUnit.Hbar),
|
|
16
|
+
isDecimal: true
|
|
83
17
|
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (txBody.contractDeleteInstance) {
|
|
87
|
-
const contractDelete = this.parseContractDelete(
|
|
88
|
-
txBody.contractDeleteInstance
|
|
89
|
-
);
|
|
90
|
-
if (contractDelete) {
|
|
91
|
-
return {
|
|
92
|
-
type: "CONTRACTDELETE",
|
|
93
|
-
humanReadableType: "Contract Delete",
|
|
94
|
-
contractDelete
|
|
95
|
-
};
|
|
96
|
-
}
|
|
18
|
+
});
|
|
97
19
|
}
|
|
98
|
-
if (
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (tx._contractId && tx._gas) {
|
|
120
|
-
const contractCall = {
|
|
121
|
-
contractId: tx._contractId.toString(),
|
|
122
|
-
gas: typeof tx._gas === "number" ? tx._gas : Long.fromValue(tx._gas).toNumber(),
|
|
123
|
-
amount: tx._amount ? parseFloat(tx._amount.toString()) : 0
|
|
124
|
-
};
|
|
125
|
-
if (tx._functionParameters) {
|
|
126
|
-
const funcParams = Buffer.from(tx._functionParameters).toString(
|
|
127
|
-
"hex"
|
|
128
|
-
);
|
|
129
|
-
contractCall.functionParameters = funcParams;
|
|
130
|
-
contractCall.functionName = this.extractFunctionName(funcParams);
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
type: "CONTRACTCALL",
|
|
134
|
-
humanReadableType: "Contract Call",
|
|
135
|
-
contractCall
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
if (hasTransactionType(transaction, "contractCreateInstance")) {
|
|
139
|
-
const contractCreate = {
|
|
140
|
-
gas: tx._gas.toString(),
|
|
141
|
-
initialBalance: tx._initialBalance?.toString() || "0"
|
|
142
|
-
};
|
|
143
|
-
if (tx._fileId) {
|
|
144
|
-
contractCreate.initcodeSource = "fileID";
|
|
145
|
-
contractCreate.initcode = tx._fileId.toString();
|
|
146
|
-
} else if (tx._bytecode) {
|
|
147
|
-
contractCreate.initcodeSource = "bytes";
|
|
148
|
-
contractCreate.initcode = Buffer.from(tx._bytecode).toString("hex");
|
|
149
|
-
}
|
|
150
|
-
if (tx._constructorParameters) {
|
|
151
|
-
contractCreate.constructorParameters = Buffer.from(
|
|
152
|
-
tx._constructorParameters
|
|
153
|
-
).toString("hex");
|
|
154
|
-
}
|
|
155
|
-
if (tx._memo) contractCreate.memo = tx._memo;
|
|
156
|
-
if (tx._adminKey) contractCreate.adminKey = parseKey(tx._adminKey);
|
|
157
|
-
if (tx._maxAutomaticTokenAssociations !== void 0) {
|
|
158
|
-
contractCreate.maxAutomaticTokenAssociations = tx._maxAutomaticTokenAssociations;
|
|
159
|
-
}
|
|
160
|
-
if (tx._stakedAccountId) {
|
|
161
|
-
contractCreate.stakedAccountId = tx._stakedAccountId.toString();
|
|
162
|
-
} else if (tx._stakedNodeId !== null && tx._stakedNodeId !== void 0) {
|
|
163
|
-
contractCreate.stakedNodeId = Long.fromValue(
|
|
164
|
-
tx._stakedNodeId
|
|
165
|
-
).toString();
|
|
166
|
-
}
|
|
167
|
-
if (tx._declineReward !== void 0)
|
|
168
|
-
contractCreate.declineReward = tx._declineReward;
|
|
169
|
-
if (tx._autoRenewPeriod)
|
|
170
|
-
contractCreate.autoRenewPeriod = tx._autoRenewPeriod.toString();
|
|
171
|
-
return {
|
|
172
|
-
type: "CONTRACTCREATE",
|
|
173
|
-
humanReadableType: "Contract Create",
|
|
174
|
-
contractCreate
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
if (hasTransactionType(transaction, "contractUpdateInstance")) {
|
|
178
|
-
const contractUpdate = {
|
|
179
|
-
contractIdToUpdate: tx._contractId.toString()
|
|
180
|
-
};
|
|
181
|
-
if (tx._memo) contractUpdate.memo = tx._memo;
|
|
182
|
-
if (tx._adminKey) contractUpdate.adminKey = parseKey(tx._adminKey);
|
|
183
|
-
if (tx._maxAutomaticTokenAssociations !== void 0) {
|
|
184
|
-
contractUpdate.maxAutomaticTokenAssociations = tx._maxAutomaticTokenAssociations;
|
|
185
|
-
}
|
|
186
|
-
if (tx._stakedAccountId) {
|
|
187
|
-
contractUpdate.stakedAccountId = tx._stakedAccountId.toString();
|
|
188
|
-
} else if (tx._stakedNodeId !== null && tx._stakedNodeId !== void 0) {
|
|
189
|
-
contractUpdate.stakedNodeId = Long.fromValue(
|
|
190
|
-
tx._stakedNodeId
|
|
191
|
-
).toString();
|
|
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
|
+
});
|
|
40
|
+
}
|
|
192
41
|
}
|
|
193
|
-
if (tx._declineReward !== void 0)
|
|
194
|
-
contractUpdate.declineReward = tx._declineReward;
|
|
195
|
-
if (tx._autoRenewPeriod)
|
|
196
|
-
contractUpdate.autoRenewPeriod = tx._autoRenewPeriod.toString();
|
|
197
|
-
return {
|
|
198
|
-
type: "CONTRACTUPDATE",
|
|
199
|
-
humanReadableType: "Contract Update",
|
|
200
|
-
contractUpdate
|
|
201
|
-
};
|
|
202
42
|
}
|
|
203
|
-
if (hasTransactionType(transaction, "contractDeleteInstance")) {
|
|
204
|
-
const contractDelete = {
|
|
205
|
-
contractIdToDelete: tx._contractId.toString()
|
|
206
|
-
};
|
|
207
|
-
if (tx._transferAccountId) {
|
|
208
|
-
contractDelete.transferAccountId = tx._transferAccountId.toString();
|
|
209
|
-
} else if (tx._transferContractId) {
|
|
210
|
-
contractDelete.transferContractId = tx._transferContractId.toString();
|
|
211
|
-
}
|
|
212
|
-
return {
|
|
213
|
-
type: "CONTRACTDELETE",
|
|
214
|
-
humanReadableType: "Contract Delete",
|
|
215
|
-
contractDelete
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
return {};
|
|
219
|
-
} catch (error) {
|
|
220
|
-
return {};
|
|
221
43
|
}
|
|
222
44
|
}
|
|
223
|
-
|
|
224
|
-
* Enhanced function name extraction from contract call parameters
|
|
225
|
-
* Attempts to decode function selector and map to known function names
|
|
226
|
-
*/
|
|
227
|
-
static extractFunctionName(functionParameters) {
|
|
228
|
-
if (functionParameters.length < 8) return "unknown";
|
|
229
|
-
const selector = functionParameters.substring(0, 8);
|
|
230
|
-
const commonSelectors = {
|
|
231
|
-
a9059cbb: "transfer",
|
|
232
|
-
"095ea7b3": "approve",
|
|
233
|
-
"23b872dd": "transferFrom",
|
|
234
|
-
"70a08231": "balanceOf",
|
|
235
|
-
dd62ed3e: "allowance",
|
|
236
|
-
"18160ddd": "totalSupply",
|
|
237
|
-
"06fdde03": "name",
|
|
238
|
-
"95d89b41": "symbol",
|
|
239
|
-
"313ce567": "decimals",
|
|
240
|
-
"42842e0e": "safeTransferFrom",
|
|
241
|
-
b88d4fde: "safeTransferFrom",
|
|
242
|
-
e985e9c5: "isApprovedForAll",
|
|
243
|
-
a22cb465: "setApprovalForAll",
|
|
244
|
-
"6352211e": "ownerOf",
|
|
245
|
-
c87b56dd: "tokenURI",
|
|
246
|
-
"01ffc9a7": "supportsInterface",
|
|
247
|
-
"40c10f19": "mint",
|
|
248
|
-
"42966c68": "burn",
|
|
249
|
-
f2fde38b: "transferOwnership",
|
|
250
|
-
"715018a6": "renounceOwnership",
|
|
251
|
-
"8da5cb5b": "owner"
|
|
252
|
-
};
|
|
253
|
-
return commonSelectors[selector] || selector;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Parse Ethereum Transaction (was completely missing from original parser)
|
|
257
|
-
*/
|
|
258
|
-
static parseEthereumTransaction(body) {
|
|
45
|
+
static parseCryptoDelete(body) {
|
|
259
46
|
if (!body) return void 0;
|
|
260
|
-
const data = {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
data.functionParameters = ethData;
|
|
268
|
-
if (ethData.length >= 8) {
|
|
269
|
-
data.functionName = this.extractFunctionName(ethData);
|
|
270
|
-
}
|
|
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();
|
|
271
54
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
contractId: new ContractId(
|
|
279
|
-
body.contractID.shardNum ?? 0,
|
|
280
|
-
body.contractID.realmNum ?? 0,
|
|
281
|
-
body.contractID.contractNum ?? 0
|
|
282
|
-
).toString(),
|
|
283
|
-
gas: Long.fromValue(body.gas ?? 0).toNumber(),
|
|
284
|
-
amount: parseFloat(hbarAmount.toString(HbarUnit.Hbar))
|
|
285
|
-
};
|
|
286
|
-
if (body.functionParameters) {
|
|
287
|
-
data.functionParameters = Buffer.from(body.functionParameters).toString(
|
|
288
|
-
"hex"
|
|
289
|
-
);
|
|
290
|
-
if (data.functionParameters.length >= 8) {
|
|
291
|
-
data.functionName = this.extractFunctionName(data.functionParameters);
|
|
292
|
-
}
|
|
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();
|
|
293
61
|
}
|
|
294
62
|
return data;
|
|
295
63
|
}
|
|
296
|
-
static
|
|
64
|
+
static parseCryptoCreateAccount(body) {
|
|
297
65
|
if (!body) return void 0;
|
|
298
66
|
const data = {};
|
|
299
67
|
if (body.initialBalance) {
|
|
@@ -301,25 +69,23 @@ class SCSParser {
|
|
|
301
69
|
Long.fromValue(body.initialBalance)
|
|
302
70
|
).toString(HbarUnit.Hbar);
|
|
303
71
|
}
|
|
304
|
-
if (body.
|
|
305
|
-
data.
|
|
306
|
-
}
|
|
307
|
-
if (body.adminKey) {
|
|
308
|
-
data.adminKey = parseKey(body.adminKey);
|
|
72
|
+
if (body.key) {
|
|
73
|
+
data.key = parseKey(body.key);
|
|
309
74
|
}
|
|
310
|
-
if (body.
|
|
311
|
-
data.
|
|
312
|
-
body.constructorParameters
|
|
313
|
-
).toString("hex");
|
|
314
|
-
}
|
|
315
|
-
if (body.memo) {
|
|
316
|
-
data.memo = body.memo;
|
|
75
|
+
if (body.receiverSigRequired !== void 0) {
|
|
76
|
+
data.receiverSigRequired = body.receiverSigRequired;
|
|
317
77
|
}
|
|
318
78
|
if (body.autoRenewPeriod?.seconds) {
|
|
319
79
|
data.autoRenewPeriod = Long.fromValue(
|
|
320
80
|
body.autoRenewPeriod.seconds
|
|
321
81
|
).toString();
|
|
322
82
|
}
|
|
83
|
+
if (body.memo) {
|
|
84
|
+
data.memo = body.memo;
|
|
85
|
+
}
|
|
86
|
+
if (body.maxAutomaticTokenAssociations !== void 0) {
|
|
87
|
+
data.maxAutomaticTokenAssociations = body.maxAutomaticTokenAssociations;
|
|
88
|
+
}
|
|
323
89
|
if (body.stakedAccountId) {
|
|
324
90
|
data.stakedAccountId = new AccountId(
|
|
325
91
|
body.stakedAccountId.shardNum ?? 0,
|
|
@@ -332,61 +98,42 @@ class SCSParser {
|
|
|
332
98
|
if (body.declineReward !== void 0) {
|
|
333
99
|
data.declineReward = body.declineReward;
|
|
334
100
|
}
|
|
335
|
-
if (body.
|
|
336
|
-
data.
|
|
337
|
-
}
|
|
338
|
-
if (body.fileID) {
|
|
339
|
-
data.initcodeSource = "fileID";
|
|
340
|
-
data.initcode = new FileId(
|
|
341
|
-
body.fileID.shardNum ?? 0,
|
|
342
|
-
body.fileID.realmNum ?? 0,
|
|
343
|
-
body.fileID.fileNum ?? 0
|
|
344
|
-
).toString();
|
|
345
|
-
} else if (body.initcode && body.initcode.length > 0) {
|
|
346
|
-
data.initcodeSource = "bytes";
|
|
347
|
-
data.initcode = Buffer.from(body.initcode).toString("hex");
|
|
101
|
+
if (body.alias && body.alias.length > 0) {
|
|
102
|
+
data.alias = Buffer.from(body.alias).toString("hex");
|
|
348
103
|
}
|
|
349
104
|
return data;
|
|
350
105
|
}
|
|
351
|
-
static
|
|
106
|
+
static parseCryptoUpdateAccount(body) {
|
|
352
107
|
if (!body) return void 0;
|
|
353
108
|
const data = {};
|
|
354
|
-
if (body.
|
|
355
|
-
data.
|
|
356
|
-
body.
|
|
357
|
-
body.
|
|
358
|
-
body.
|
|
109
|
+
if (body.accountIDToUpdate) {
|
|
110
|
+
data.accountIdToUpdate = new AccountId(
|
|
111
|
+
body.accountIDToUpdate.shardNum ?? 0,
|
|
112
|
+
body.accountIDToUpdate.realmNum ?? 0,
|
|
113
|
+
body.accountIDToUpdate.accountNum ?? 0
|
|
359
114
|
).toString();
|
|
360
115
|
}
|
|
361
|
-
if (body.
|
|
362
|
-
data.
|
|
116
|
+
if (body.key) {
|
|
117
|
+
data.key = parseKey(body.key);
|
|
363
118
|
}
|
|
364
119
|
if (body.expirationTime?.seconds) {
|
|
365
120
|
data.expirationTime = `${Long.fromValue(
|
|
366
121
|
body.expirationTime.seconds
|
|
367
122
|
).toString()}.${body.expirationTime.nanos}`;
|
|
368
123
|
}
|
|
124
|
+
if (body.receiverSigRequired !== null && body.receiverSigRequired !== void 0) {
|
|
125
|
+
data.receiverSigRequired = Boolean(body.receiverSigRequired);
|
|
126
|
+
}
|
|
369
127
|
if (body.autoRenewPeriod?.seconds) {
|
|
370
128
|
data.autoRenewPeriod = Long.fromValue(
|
|
371
129
|
body.autoRenewPeriod.seconds
|
|
372
130
|
).toString();
|
|
373
131
|
}
|
|
374
|
-
if (body.memo) {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
data.memo = void 0;
|
|
380
|
-
} else {
|
|
381
|
-
data.memo = String(value);
|
|
382
|
-
}
|
|
383
|
-
} else if (typeof memoUnion === "string") {
|
|
384
|
-
data.memo = memoUnion;
|
|
385
|
-
} else {
|
|
386
|
-
data.memo = void 0;
|
|
387
|
-
}
|
|
388
|
-
} else {
|
|
389
|
-
data.memo = void 0;
|
|
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;
|
|
390
137
|
}
|
|
391
138
|
if (body.stakedAccountId) {
|
|
392
139
|
data.stakedAccountId = new AccountId(
|
|
@@ -395,62 +142,208 @@ class SCSParser {
|
|
|
395
142
|
body.stakedAccountId.accountNum ?? 0
|
|
396
143
|
).toString();
|
|
397
144
|
data.stakedNodeId = void 0;
|
|
398
|
-
} else if (body.stakedNodeId !== null && body.stakedNodeId !== void 0
|
|
145
|
+
} else if (body.stakedNodeId !== null && body.stakedNodeId !== void 0) {
|
|
399
146
|
data.stakedNodeId = Long.fromValue(body.stakedNodeId).toString();
|
|
400
147
|
data.stakedAccountId = void 0;
|
|
401
148
|
} else {
|
|
402
|
-
data.stakedNodeId = void 0;
|
|
403
149
|
data.stakedAccountId = void 0;
|
|
150
|
+
data.stakedNodeId = void 0;
|
|
404
151
|
}
|
|
405
|
-
if (body.declineReward
|
|
406
|
-
data.declineReward = body.declineReward
|
|
152
|
+
if (body.declineReward !== null && body.declineReward !== void 0) {
|
|
153
|
+
data.declineReward = Boolean(body.declineReward);
|
|
407
154
|
}
|
|
408
|
-
|
|
409
|
-
|
|
155
|
+
return data;
|
|
156
|
+
}
|
|
157
|
+
static parseCryptoApproveAllowance(body) {
|
|
158
|
+
if (!body) return void 0;
|
|
159
|
+
const data = {};
|
|
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
|
+
}));
|
|
410
176
|
}
|
|
411
|
-
if (body.
|
|
412
|
-
data.
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
+
});
|
|
417
232
|
}
|
|
418
233
|
return data;
|
|
419
234
|
}
|
|
420
|
-
static
|
|
235
|
+
static parseCryptoDeleteAllowance(body) {
|
|
421
236
|
if (!body) return void 0;
|
|
422
237
|
const data = {};
|
|
423
|
-
if (body.
|
|
424
|
-
data.
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
data.transferContractId = new ContractId(
|
|
438
|
-
body.transferContractID.shardNum ?? 0,
|
|
439
|
-
body.transferContractID.realmNum ?? 0,
|
|
440
|
-
body.transferContractID.contractNum ?? 0
|
|
441
|
-
).toString();
|
|
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
|
+
}));
|
|
442
252
|
}
|
|
443
253
|
return data;
|
|
444
254
|
}
|
|
445
255
|
/**
|
|
446
|
-
*
|
|
447
|
-
|
|
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
|
+
/**
|
|
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
|
|
448
306
|
*/
|
|
449
307
|
static parseFromTransactionObject(transaction) {
|
|
450
|
-
|
|
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
|
+
}
|
|
451
344
|
}
|
|
452
345
|
}
|
|
453
346
|
export {
|
|
454
|
-
|
|
347
|
+
CryptoParser
|
|
455
348
|
};
|
|
456
349
|
//# sourceMappingURL=standards-sdk.es143.js.map
|