@hashgraphonline/standards-sdk 0.1.146-chore-jsr-improvements.canary.6bc8731.90 → 0.1.146-chore-jsr-improvements.canary.01d3174.92
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/jsr-entry.d.ts +30 -10
- package/dist/cjs/jsr-entry.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/base-client.d.ts +14 -1
- package/dist/cjs/services/registry-broker/client/base-client.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/search-helpers.d.ts +16 -0
- package/dist/cjs/services/registry-broker/client/search-helpers.d.ts.map +1 -0
- package/dist/cjs/services/registry-broker/client/search.d.ts +5 -18
- package/dist/cjs/services/registry-broker/client/search.d.ts.map +1 -1
- package/dist/cjs/standards-sdk.cjs +1 -1
- package/dist/cjs/standards-sdk.cjs.map +1 -1
- package/dist/es/jsr-entry.d.ts +30 -10
- package/dist/es/jsr-entry.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/base-client.d.ts +14 -1
- package/dist/es/services/registry-broker/client/base-client.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/search-helpers.d.ts +16 -0
- package/dist/es/services/registry-broker/client/search-helpers.d.ts.map +1 -0
- package/dist/es/services/registry-broker/client/search.d.ts +5 -18
- package/dist/es/services/registry-broker/client/search.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +9 -10
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +1 -1
- package/dist/es/standards-sdk.es103.js +1 -1
- package/dist/es/standards-sdk.es109.js +2 -3
- package/dist/es/standards-sdk.es109.js.map +1 -1
- package/dist/es/standards-sdk.es11.js +1 -1
- package/dist/es/standards-sdk.es110.js +5 -5
- package/dist/es/standards-sdk.es12.js +1 -1
- 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 +1 -1
- package/dist/es/standards-sdk.es125.js +1 -1
- package/dist/es/standards-sdk.es127.js +3 -3
- package/dist/es/standards-sdk.es128.js +61 -164
- package/dist/es/standards-sdk.es128.js.map +1 -1
- package/dist/es/standards-sdk.es129.js +102 -85
- package/dist/es/standards-sdk.es129.js.map +1 -1
- package/dist/es/standards-sdk.es130.js +222 -96
- package/dist/es/standards-sdk.es130.js.map +1 -1
- package/dist/es/standards-sdk.es131.js +153 -220
- package/dist/es/standards-sdk.es131.js.map +1 -1
- package/dist/es/standards-sdk.es132.js +104 -162
- package/dist/es/standards-sdk.es132.js.map +1 -1
- package/dist/es/standards-sdk.es133.js +296 -92
- package/dist/es/standards-sdk.es133.js.map +1 -1
- package/dist/es/standards-sdk.es134.js +587 -288
- package/dist/es/standards-sdk.es134.js.map +1 -1
- package/dist/es/standards-sdk.es135.js +14 -461
- package/dist/es/standards-sdk.es135.js.map +1 -1
- package/dist/es/standards-sdk.es136.js +79 -15
- package/dist/es/standards-sdk.es136.js.map +1 -1
- package/dist/es/standards-sdk.es137.js +77 -71
- package/dist/es/standards-sdk.es137.js.map +1 -1
- package/dist/es/standards-sdk.es138.js +53 -80
- package/dist/es/standards-sdk.es138.js.map +1 -1
- package/dist/es/standards-sdk.es139.js +152 -53
- package/dist/es/standards-sdk.es139.js.map +1 -1
- package/dist/es/standards-sdk.es140.js +7 -159
- package/dist/es/standards-sdk.es140.js.map +1 -1
- package/dist/es/standards-sdk.es141.js +86 -7
- package/dist/es/standards-sdk.es141.js.map +1 -1
- package/dist/es/standards-sdk.es142.js +43 -64
- package/dist/es/standards-sdk.es142.js.map +1 -1
- package/dist/es/standards-sdk.es143.js +30 -65
- package/dist/es/standards-sdk.es143.js.map +1 -1
- package/dist/es/standards-sdk.es144.js +34 -30
- package/dist/es/standards-sdk.es144.js.map +1 -1
- package/dist/es/standards-sdk.es145.js +28 -34
- package/dist/es/standards-sdk.es145.js.map +1 -1
- package/dist/es/standards-sdk.es146.js +138 -28
- package/dist/es/standards-sdk.es146.js.map +1 -1
- package/dist/es/standards-sdk.es147.js +34 -12281
- package/dist/es/standards-sdk.es147.js.map +1 -1
- package/dist/es/standards-sdk.es148.js +17 -959
- package/dist/es/standards-sdk.es148.js.map +1 -1
- package/dist/es/standards-sdk.es149.js +12256 -105
- package/dist/es/standards-sdk.es149.js.map +1 -1
- package/dist/es/standards-sdk.es150.js +959 -42
- package/dist/es/standards-sdk.es150.js.map +1 -1
- package/dist/es/standards-sdk.es151.js +54 -15
- package/dist/es/standards-sdk.es151.js.map +1 -1
- package/dist/es/standards-sdk.es152.js +76 -48
- package/dist/es/standards-sdk.es152.js.map +1 -1
- package/dist/es/standards-sdk.es153.js +160 -72
- package/dist/es/standards-sdk.es153.js.map +1 -1
- package/dist/es/standards-sdk.es154.js +289 -139
- package/dist/es/standards-sdk.es154.js.map +1 -1
- package/dist/es/standards-sdk.es155.js +298 -274
- package/dist/es/standards-sdk.es155.js.map +1 -1
- package/dist/es/standards-sdk.es156.js +369 -262
- package/dist/es/standards-sdk.es156.js.map +1 -1
- package/dist/es/standards-sdk.es157.js +194 -316
- package/dist/es/standards-sdk.es157.js.map +1 -1
- package/dist/es/standards-sdk.es158.js +64 -319
- package/dist/es/standards-sdk.es158.js.map +1 -1
- package/dist/es/standards-sdk.es159.js +231 -68
- package/dist/es/standards-sdk.es159.js.map +1 -1
- package/dist/es/standards-sdk.es16.js +2 -3
- package/dist/es/standards-sdk.es16.js.map +1 -1
- package/dist/es/standards-sdk.es160.js +223 -218
- package/dist/es/standards-sdk.es160.js.map +1 -1
- package/dist/es/standards-sdk.es18.js +5 -6
- package/dist/es/standards-sdk.es18.js.map +1 -1
- package/dist/es/standards-sdk.es19.js +3 -4
- package/dist/es/standards-sdk.es19.js.map +1 -1
- package/dist/es/standards-sdk.es22.js +1 -1
- package/dist/es/standards-sdk.es27.js +5 -6
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +1 -1
- package/dist/es/standards-sdk.es31.js +1 -1
- package/dist/es/standards-sdk.es35.js +3 -4
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +3 -3
- package/dist/es/standards-sdk.es37.js +1 -1
- package/dist/es/standards-sdk.es4.js +1 -1
- package/dist/es/standards-sdk.es53.js +1 -1
- package/dist/es/standards-sdk.es56.js +1 -1
- package/dist/es/standards-sdk.es58.js +1 -1
- package/dist/es/standards-sdk.es59.js +1 -1
- package/dist/es/standards-sdk.es60.js +3 -4
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +1 -1
- package/dist/es/standards-sdk.es64.js +1 -1
- package/dist/es/standards-sdk.es65.js +2 -2
- package/dist/es/standards-sdk.es68.js +2 -2
- package/dist/es/standards-sdk.es69.js +1 -1
- package/dist/es/standards-sdk.es7.js +1 -1
- package/dist/es/standards-sdk.es71.js +1 -1
- package/dist/es/standards-sdk.es76.js +1 -1
- package/dist/es/standards-sdk.es77.js +2 -3
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +1 -1
- package/dist/es/standards-sdk.es81.js +1 -1
- package/dist/es/standards-sdk.es83.js +1 -1
- package/dist/es/standards-sdk.es87.js +3 -3
- package/dist/es/standards-sdk.es91.js +1 -1
- package/dist/es/standards-sdk.es92.js +1 -1
- package/dist/es/standards-sdk.es97.js +1 -1
- package/dist/es/standards-sdk.es99.js +1 -1
- package/package.json +1 -1
- package/dist/es/standards-sdk.es161.js +0 -247
- package/dist/es/standards-sdk.es161.js.map +0 -1
|
@@ -1,325 +1,349 @@
|
|
|
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 { 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) {
|
|
52
|
-
return {
|
|
53
|
-
type: "FILECREATE",
|
|
54
|
-
humanReadableType: "File Create",
|
|
55
|
-
fileCreate
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
}
|
|
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) {
|
|
1
|
+
import { AccountId, Hbar, Long, HbarUnit, TokenId } from "@hashgraph/sdk";
|
|
2
|
+
import { parseKey } from "./standards-sdk.es158.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));
|
|
72
13
|
return {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
14
|
+
accountId: accountId.toString(),
|
|
15
|
+
amount: hbarAmount.toString(HbarUnit.Hbar),
|
|
16
|
+
isDecimal: true
|
|
76
17
|
};
|
|
77
|
-
}
|
|
18
|
+
});
|
|
78
19
|
}
|
|
79
|
-
if (
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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;
|
|
108
|
-
}
|
|
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;
|
|
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
|
+
});
|
|
154
40
|
}
|
|
155
41
|
}
|
|
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
|
-
};
|
|
173
42
|
}
|
|
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 {};
|
|
187
43
|
}
|
|
188
44
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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()];
|
|
210
|
-
}
|
|
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
|
-
}
|
|
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();
|
|
234
54
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
} catch {
|
|
243
|
-
encoded = contentBuffer.toString("base64");
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
encoded = contentBuffer.toString("base64");
|
|
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();
|
|
247
61
|
}
|
|
248
|
-
return
|
|
249
|
-
encoded,
|
|
250
|
-
contentType,
|
|
251
|
-
size
|
|
252
|
-
};
|
|
62
|
+
return data;
|
|
253
63
|
}
|
|
254
|
-
static
|
|
64
|
+
static parseCryptoCreateAccount(body) {
|
|
255
65
|
if (!body) return void 0;
|
|
256
66
|
const data = {};
|
|
257
|
-
if (body.
|
|
258
|
-
data.
|
|
259
|
-
body.
|
|
260
|
-
).toString()
|
|
67
|
+
if (body.initialBalance) {
|
|
68
|
+
data.initialBalance = Hbar.fromTinybars(
|
|
69
|
+
Long.fromValue(body.initialBalance)
|
|
70
|
+
).toString(HbarUnit.Hbar);
|
|
261
71
|
}
|
|
262
|
-
if (body.
|
|
263
|
-
data.
|
|
72
|
+
if (body.key) {
|
|
73
|
+
data.key = parseKey(body.key);
|
|
264
74
|
}
|
|
265
|
-
if (body.
|
|
266
|
-
data.
|
|
75
|
+
if (body.receiverSigRequired !== void 0) {
|
|
76
|
+
data.receiverSigRequired = body.receiverSigRequired;
|
|
77
|
+
}
|
|
78
|
+
if (body.autoRenewPeriod?.seconds) {
|
|
79
|
+
data.autoRenewPeriod = Long.fromValue(
|
|
80
|
+
body.autoRenewPeriod.seconds
|
|
81
|
+
).toString();
|
|
267
82
|
}
|
|
268
83
|
if (body.memo) {
|
|
269
84
|
data.memo = body.memo;
|
|
270
85
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
86
|
+
if (body.maxAutomaticTokenAssociations !== void 0) {
|
|
87
|
+
data.maxAutomaticTokenAssociations = body.maxAutomaticTokenAssociations;
|
|
88
|
+
}
|
|
89
|
+
if (body.stakedAccountId) {
|
|
90
|
+
data.stakedAccountId = new AccountId(
|
|
91
|
+
body.stakedAccountId.shardNum ?? 0,
|
|
92
|
+
body.stakedAccountId.realmNum ?? 0,
|
|
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();
|
|
278
97
|
}
|
|
279
|
-
if (body.
|
|
280
|
-
data.
|
|
98
|
+
if (body.declineReward !== void 0) {
|
|
99
|
+
data.declineReward = body.declineReward;
|
|
100
|
+
}
|
|
101
|
+
if (body.alias && body.alias.length > 0) {
|
|
102
|
+
data.alias = Buffer.from(body.alias).toString("hex");
|
|
281
103
|
}
|
|
282
104
|
return data;
|
|
283
105
|
}
|
|
284
|
-
static
|
|
106
|
+
static parseCryptoUpdateAccount(body) {
|
|
285
107
|
if (!body) return void 0;
|
|
286
108
|
const data = {};
|
|
287
|
-
if (body.
|
|
288
|
-
data.
|
|
109
|
+
if (body.accountIDToUpdate) {
|
|
110
|
+
data.accountIdToUpdate = new AccountId(
|
|
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);
|
|
289
118
|
}
|
|
290
119
|
if (body.expirationTime?.seconds) {
|
|
291
120
|
data.expirationTime = `${Long.fromValue(
|
|
292
121
|
body.expirationTime.seconds
|
|
293
122
|
).toString()}.${body.expirationTime.nanos}`;
|
|
294
123
|
}
|
|
295
|
-
if (body.
|
|
296
|
-
data.
|
|
124
|
+
if (body.receiverSigRequired !== null && body.receiverSigRequired !== void 0) {
|
|
125
|
+
data.receiverSigRequired = Boolean(body.receiverSigRequired);
|
|
297
126
|
}
|
|
298
|
-
if (body.
|
|
299
|
-
data.
|
|
127
|
+
if (body.autoRenewPeriod?.seconds) {
|
|
128
|
+
data.autoRenewPeriod = Long.fromValue(
|
|
129
|
+
body.autoRenewPeriod.seconds
|
|
130
|
+
).toString();
|
|
300
131
|
}
|
|
301
132
|
if (body.memo?.value !== void 0) {
|
|
302
133
|
data.memo = body.memo.value;
|
|
303
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
|
|
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
|
+
}
|
|
304
155
|
return data;
|
|
305
156
|
}
|
|
306
|
-
static
|
|
157
|
+
static parseCryptoApproveAllowance(body) {
|
|
307
158
|
if (!body) return void 0;
|
|
308
159
|
const data = {};
|
|
309
|
-
if (body.
|
|
310
|
-
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
|
+
}));
|
|
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
|
+
});
|
|
311
232
|
}
|
|
312
233
|
return data;
|
|
313
234
|
}
|
|
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
|
+
}
|
|
314
303
|
/**
|
|
315
|
-
* Parse
|
|
316
|
-
* This is the unified entry point that
|
|
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
|
|
317
306
|
*/
|
|
318
307
|
static parseFromTransactionObject(transaction) {
|
|
319
|
-
|
|
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
|
+
}
|
|
320
344
|
}
|
|
321
345
|
}
|
|
322
346
|
export {
|
|
323
|
-
|
|
347
|
+
CryptoParser
|
|
324
348
|
};
|
|
325
349
|
//# sourceMappingURL=standards-sdk.es155.js.map
|