@ledgerhq/coin-tester-evm 1.6.0-nightly.8 → 1.6.0
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +41 -59
- package/lib/src/helpers.d.ts +6 -6
- package/lib/src/helpers.d.ts.map +1 -1
- package/lib/src/helpers.js +11 -12
- package/lib/src/helpers.js.map +1 -1
- package/lib/src/indexer.d.ts.map +1 -1
- package/lib/src/indexer.js +184 -193
- package/lib/src/indexer.js.map +1 -1
- package/lib/src/scenarii/blast.d.ts.map +1 -1
- package/lib/src/scenarii/blast.js +8 -8
- package/lib/src/scenarii/blast.js.map +1 -1
- package/lib/src/scenarii/ethereum.d.ts.map +1 -1
- package/lib/src/scenarii/ethereum.js +10 -10
- package/lib/src/scenarii/ethereum.js.map +1 -1
- package/lib/src/scenarii/polygon.d.ts.map +1 -1
- package/lib/src/scenarii/polygon.js +11 -11
- package/lib/src/scenarii/polygon.js.map +1 -1
- package/lib/src/scenarii/scroll.d.ts.map +1 -1
- package/lib/src/scenarii/scroll.js +8 -8
- package/lib/src/scenarii/scroll.js.map +1 -1
- package/lib/src/scenarii/sonic.d.ts.map +1 -1
- package/lib/src/scenarii/sonic.js +8 -8
- package/lib/src/scenarii/sonic.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib-es/src/helpers.d.ts +6 -6
- package/lib-es/src/helpers.d.ts.map +1 -1
- package/lib-es/src/helpers.js +11 -12
- package/lib-es/src/helpers.js.map +1 -1
- package/lib-es/src/indexer.d.ts.map +1 -1
- package/lib-es/src/indexer.js +185 -194
- package/lib-es/src/indexer.js.map +1 -1
- package/lib-es/src/scenarii/blast.d.ts.map +1 -1
- package/lib-es/src/scenarii/blast.js +9 -9
- package/lib-es/src/scenarii/blast.js.map +1 -1
- package/lib-es/src/scenarii/ethereum.d.ts.map +1 -1
- package/lib-es/src/scenarii/ethereum.js +11 -11
- package/lib-es/src/scenarii/ethereum.js.map +1 -1
- package/lib-es/src/scenarii/polygon.d.ts.map +1 -1
- package/lib-es/src/scenarii/polygon.js +12 -12
- package/lib-es/src/scenarii/polygon.js.map +1 -1
- package/lib-es/src/scenarii/scroll.d.ts.map +1 -1
- package/lib-es/src/scenarii/scroll.js +9 -9
- package/lib-es/src/scenarii/scroll.js.map +1 -1
- package/lib-es/src/scenarii/sonic.d.ts.map +1 -1
- package/lib-es/src/scenarii/sonic.js +9 -9
- package/lib-es/src/scenarii/sonic.js.map +1 -1
- package/lib-es/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -11
- package/src/helpers.ts +14 -15
- package/src/indexer.ts +205 -200
- package/src/scenarii/blast.ts +11 -9
- package/src/scenarii/ethereum.ts +13 -11
- package/src/scenarii/polygon.ts +14 -12
- package/src/scenarii/scroll.ts +11 -9
- package/src/scenarii/sonic.ts +11 -9
package/lib/src/indexer.js
CHANGED
|
@@ -12,15 +12,14 @@ const ethers_1 = require("ethers");
|
|
|
12
12
|
const index_1 = require("@ledgerhq/coin-evm/abis/index");
|
|
13
13
|
const utils_1 = require("@ledgerhq/coin-evm/utils");
|
|
14
14
|
const MAX_BLOCK_RANGE = 1024;
|
|
15
|
-
const ERC20Interface = new ethers_1.
|
|
16
|
-
const ERC721Interface = new ethers_1.
|
|
17
|
-
const ERC1155Interface = new ethers_1.
|
|
15
|
+
const ERC20Interface = new ethers_1.utils.Interface(index_1.ERC20_ABI);
|
|
16
|
+
const ERC721Interface = new ethers_1.utils.Interface(index_1.ERC721_ABI);
|
|
17
|
+
const ERC1155Interface = new ethers_1.utils.Interface(index_1.ERC1155_ABI);
|
|
18
18
|
const TRANSFER_EVENTS_TOPICS = {
|
|
19
|
-
ERC20: ERC20Interface.
|
|
20
|
-
ERC721: ERC721Interface.
|
|
21
|
-
ERC1155: ERC1155Interface.
|
|
19
|
+
ERC20: ERC20Interface.getEventTopic("Transfer"),
|
|
20
|
+
ERC721: ERC721Interface.getEventTopic("Transfer"),
|
|
21
|
+
ERC1155: ERC1155Interface.getEventTopic("TransferSingle"),
|
|
22
22
|
};
|
|
23
|
-
const abiCoder = new ethers_1.AbiCoder();
|
|
24
23
|
const explorerEtherscanOperationByAddress = {};
|
|
25
24
|
const explorerEtherscanERC20EventsByAddress = {};
|
|
26
25
|
const explorerEtherscanERC721EventsByAddress = {};
|
|
@@ -51,21 +50,11 @@ const resetIndexer = () => {
|
|
|
51
50
|
};
|
|
52
51
|
exports.resetIndexer = resetIndexer;
|
|
53
52
|
const handleLog = async (log, provider) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
// if call didn’t revert and returned something valid
|
|
61
|
-
hasDecimals = !!(res && res !== "0x");
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// execution reverted → no decimals()
|
|
65
|
-
hasDecimals = false;
|
|
66
|
-
}
|
|
67
|
-
const isERC20 = log.topics[0] === TRANSFER_EVENTS_TOPICS.ERC20 && hasDecimals;
|
|
68
|
-
const isERC721 = log.topics[0] === TRANSFER_EVENTS_TOPICS.ERC721 && !hasDecimals;
|
|
53
|
+
const contractDecimals = await provider
|
|
54
|
+
.call({ to: log.address, data: ERC20Interface.encodeFunctionData("decimals") })
|
|
55
|
+
.then(res => (!res || res === "0x" ? false : true));
|
|
56
|
+
const isERC20 = log.topics[0] === TRANSFER_EVENTS_TOPICS.ERC20 && contractDecimals;
|
|
57
|
+
const isERC721 = log.topics[0] === TRANSFER_EVENTS_TOPICS.ERC721 && !contractDecimals;
|
|
69
58
|
const isERC1155 = log.topics[0] === TRANSFER_EVENTS_TOPICS.ERC1155;
|
|
70
59
|
if (isERC20) {
|
|
71
60
|
return handleERC20Log(log, provider);
|
|
@@ -81,10 +70,10 @@ const handleERC20Log = async (log, provider) => {
|
|
|
81
70
|
const [name, ticker, decimals, block, tx, receipt] = await Promise.all([
|
|
82
71
|
provider
|
|
83
72
|
.call({ to: log.address, data: ERC20Interface.encodeFunctionData("name") })
|
|
84
|
-
.then(res =>
|
|
73
|
+
.then(res => ethers_1.ethers.utils.defaultAbiCoder.decode(["string"], res)[0]),
|
|
85
74
|
provider
|
|
86
75
|
.call({ to: log.address, data: ERC20Interface.encodeFunctionData("symbol") })
|
|
87
|
-
.then(res =>
|
|
76
|
+
.then(res => ethers_1.ethers.utils.defaultAbiCoder.decode(["string"], res)[0]),
|
|
88
77
|
provider
|
|
89
78
|
.call({ to: log.address, data: ERC20Interface.encodeFunctionData("decimals") })
|
|
90
79
|
.then(res => new bignumber_js_1.default(res).toString()),
|
|
@@ -92,29 +81,29 @@ const handleERC20Log = async (log, provider) => {
|
|
|
92
81
|
provider.getTransaction(log.transactionHash),
|
|
93
82
|
provider.getTransactionReceipt(log.transactionHash),
|
|
94
83
|
]);
|
|
95
|
-
const from = (0, utils_1.safeEncodeEIP55)(
|
|
96
|
-
const to = (0, utils_1.safeEncodeEIP55)(
|
|
97
|
-
const amount =
|
|
84
|
+
const from = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[1])[0]);
|
|
85
|
+
const to = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[2])[0]);
|
|
86
|
+
const amount = ethers_1.ethers.BigNumber.from(log.data === "0x" ? 0 : log.data).toString();
|
|
98
87
|
const etherscanErc20Event = {
|
|
99
|
-
blockNumber: block
|
|
100
|
-
timeStamp: block
|
|
88
|
+
blockNumber: block.number.toString(),
|
|
89
|
+
timeStamp: block.timestamp.toString(),
|
|
101
90
|
hash: log.transactionHash,
|
|
102
|
-
nonce: tx
|
|
103
|
-
blockHash: block
|
|
91
|
+
nonce: tx.nonce.toString(),
|
|
92
|
+
blockHash: block.hash,
|
|
104
93
|
from,
|
|
105
94
|
to,
|
|
106
95
|
value: amount,
|
|
107
96
|
tokenName: name,
|
|
108
97
|
tokenSymbol: ticker,
|
|
109
98
|
tokenDecimal: decimals,
|
|
110
|
-
transactionIndex: block
|
|
111
|
-
gas: tx
|
|
112
|
-
gasPrice: tx
|
|
113
|
-
cumulativeGasUsed: receipt
|
|
99
|
+
transactionIndex: block.transactions.indexOf(log.transactionHash).toString(),
|
|
100
|
+
gas: tx.gasLimit.toString(),
|
|
101
|
+
gasPrice: tx.gasPrice?.toString() || "",
|
|
102
|
+
cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
|
|
114
103
|
gasUsed: receipt?.gasUsed?.toString() || "0",
|
|
115
|
-
input: tx
|
|
116
|
-
confirmations: tx
|
|
117
|
-
contractAddress: tx
|
|
104
|
+
input: tx.data,
|
|
105
|
+
confirmations: tx.confirmations.toString(),
|
|
106
|
+
contractAddress: tx.to.toLowerCase(),
|
|
118
107
|
};
|
|
119
108
|
if (!explorerEtherscanERC20EventsByAddress[from]) {
|
|
120
109
|
explorerEtherscanERC20EventsByAddress[from] = new Map();
|
|
@@ -130,9 +119,8 @@ const handleERC20Log = async (log, provider) => {
|
|
|
130
119
|
if (!explorerLedgerOperationByAddress[to]) {
|
|
131
120
|
explorerLedgerOperationByAddress[to] = new Map();
|
|
132
121
|
}
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
(txHash && explorerLedgerOperationByAddress[to].get(txHash));
|
|
122
|
+
const alreadyExistingOperation = explorerLedgerOperationByAddress[from].get(tx.hash) ||
|
|
123
|
+
explorerLedgerOperationByAddress[to].get(tx.hash);
|
|
136
124
|
const ledgerOperation = alreadyExistingOperation
|
|
137
125
|
? {
|
|
138
126
|
...alreadyExistingOperation,
|
|
@@ -147,16 +135,16 @@ const handleERC20Log = async (log, provider) => {
|
|
|
147
135
|
}
|
|
148
136
|
: {
|
|
149
137
|
hash: log.transactionHash,
|
|
150
|
-
transaction_type: receipt
|
|
138
|
+
transaction_type: receipt.type,
|
|
151
139
|
nonce: "",
|
|
152
140
|
nonce_value: -1,
|
|
153
|
-
value: tx
|
|
154
|
-
gas: tx
|
|
155
|
-
gas_price: receipt
|
|
156
|
-
max_fee_per_gas: tx
|
|
157
|
-
max_priority_fee_per_gas: tx
|
|
158
|
-
from: tx
|
|
159
|
-
to: tx
|
|
141
|
+
value: tx.value.toString(),
|
|
142
|
+
gas: tx.gasLimit.toString(),
|
|
143
|
+
gas_price: receipt.effectiveGasPrice.toString(),
|
|
144
|
+
max_fee_per_gas: tx.type === 2 ? tx.maxFeePerGas.toString() : null,
|
|
145
|
+
max_priority_fee_per_gas: tx.type === 2 ? tx.maxPriorityFeePerGas.toString() : null,
|
|
146
|
+
from: tx.from,
|
|
147
|
+
to: tx.to,
|
|
160
148
|
transfer_events: [
|
|
161
149
|
{
|
|
162
150
|
contract: log.address,
|
|
@@ -169,16 +157,16 @@ const handleERC20Log = async (log, provider) => {
|
|
|
169
157
|
erc1155_transfer_events: [],
|
|
170
158
|
approval_events: [],
|
|
171
159
|
actions: [],
|
|
172
|
-
confirmations: tx
|
|
160
|
+
confirmations: tx.confirmations,
|
|
173
161
|
input: null,
|
|
174
|
-
gas_used: receipt
|
|
175
|
-
cumulative_gas_used: receipt
|
|
176
|
-
status: receipt
|
|
177
|
-
received_at: new Date(
|
|
162
|
+
gas_used: receipt.gasUsed.toString(),
|
|
163
|
+
cumulative_gas_used: receipt.cumulativeGasUsed.toString(),
|
|
164
|
+
status: receipt.status,
|
|
165
|
+
received_at: new Date(block.timestamp * 1000).toISOString(),
|
|
178
166
|
block: {
|
|
179
167
|
hash: log.blockHash,
|
|
180
168
|
height: log.blockNumber,
|
|
181
|
-
time: new Date(
|
|
169
|
+
time: new Date(block.timestamp * 1000).toISOString(),
|
|
182
170
|
},
|
|
183
171
|
};
|
|
184
172
|
explorerLedgerOperationByAddress[from].set(ledgerOperation.hash, ledgerOperation);
|
|
@@ -190,25 +178,25 @@ const handleERC721Log = async (log, provider) => {
|
|
|
190
178
|
provider.getTransaction(log.transactionHash),
|
|
191
179
|
provider.getTransactionReceipt(log.transactionHash),
|
|
192
180
|
]);
|
|
193
|
-
const from = (0, utils_1.safeEncodeEIP55)(
|
|
194
|
-
const to = (0, utils_1.safeEncodeEIP55)(
|
|
195
|
-
const tokenID =
|
|
181
|
+
const from = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[1])[0]);
|
|
182
|
+
const to = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[2])[0]);
|
|
183
|
+
const tokenID = ethers_1.ethers.utils.defaultAbiCoder.decode(["uint256"], log.topics[3])[0].toString();
|
|
196
184
|
const erc721Event = {
|
|
197
|
-
blockNumber: block
|
|
198
|
-
timeStamp: block
|
|
199
|
-
hash: tx
|
|
200
|
-
nonce: tx
|
|
201
|
-
blockHash: block
|
|
185
|
+
blockNumber: block.number.toString(),
|
|
186
|
+
timeStamp: block.timestamp.toString(),
|
|
187
|
+
hash: tx.hash,
|
|
188
|
+
nonce: tx.nonce.toString(),
|
|
189
|
+
blockHash: block.hash,
|
|
202
190
|
from,
|
|
203
191
|
to,
|
|
204
|
-
transactionIndex: block
|
|
205
|
-
gas: tx
|
|
206
|
-
gasPrice: tx
|
|
207
|
-
cumulativeGasUsed: receipt
|
|
192
|
+
transactionIndex: block.transactions.indexOf(log.transactionHash).toString(),
|
|
193
|
+
gas: tx.gasLimit.toString(),
|
|
194
|
+
gasPrice: tx.gasPrice?.toString() || "",
|
|
195
|
+
cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
|
|
208
196
|
gasUsed: receipt?.gasUsed?.toString() || "0",
|
|
209
|
-
input: tx
|
|
210
|
-
confirmations: tx
|
|
211
|
-
contractAddress: tx
|
|
197
|
+
input: tx.data,
|
|
198
|
+
confirmations: tx.confirmations.toString(),
|
|
199
|
+
contractAddress: tx.to,
|
|
212
200
|
tokenID,
|
|
213
201
|
tokenName: "tokenName",
|
|
214
202
|
tokenSymbol: "tokenSymbol",
|
|
@@ -228,9 +216,8 @@ const handleERC721Log = async (log, provider) => {
|
|
|
228
216
|
if (!explorerLedgerOperationByAddress[to]) {
|
|
229
217
|
explorerLedgerOperationByAddress[to] = new Map();
|
|
230
218
|
}
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
(txHash && explorerLedgerOperationByAddress[to].get(txHash));
|
|
219
|
+
const alreadyExistingOperation = explorerLedgerOperationByAddress[from].get(tx.hash) ||
|
|
220
|
+
explorerLedgerOperationByAddress[to].get(tx.hash);
|
|
234
221
|
const ledgerOperation = alreadyExistingOperation
|
|
235
222
|
? {
|
|
236
223
|
...alreadyExistingOperation,
|
|
@@ -245,16 +232,16 @@ const handleERC721Log = async (log, provider) => {
|
|
|
245
232
|
}
|
|
246
233
|
: {
|
|
247
234
|
hash: log.transactionHash,
|
|
248
|
-
transaction_type: receipt
|
|
235
|
+
transaction_type: receipt.type,
|
|
249
236
|
nonce: "",
|
|
250
237
|
nonce_value: -1,
|
|
251
|
-
value: tx
|
|
252
|
-
gas: tx
|
|
253
|
-
gas_price: receipt
|
|
254
|
-
max_fee_per_gas: tx
|
|
255
|
-
max_priority_fee_per_gas: tx
|
|
256
|
-
from: tx
|
|
257
|
-
to: tx
|
|
238
|
+
value: tx.value.toString(),
|
|
239
|
+
gas: tx.gasLimit.toString(),
|
|
240
|
+
gas_price: receipt.effectiveGasPrice.toString(),
|
|
241
|
+
max_fee_per_gas: tx.type === 2 ? tx.maxFeePerGas.toString() : null,
|
|
242
|
+
max_priority_fee_per_gas: tx.type === 2 ? tx.maxPriorityFeePerGas.toString() : null,
|
|
243
|
+
from: tx.from,
|
|
244
|
+
to: tx.to,
|
|
258
245
|
transfer_events: [],
|
|
259
246
|
erc721_transfer_events: [
|
|
260
247
|
{
|
|
@@ -267,16 +254,16 @@ const handleERC721Log = async (log, provider) => {
|
|
|
267
254
|
erc1155_transfer_events: [],
|
|
268
255
|
approval_events: [],
|
|
269
256
|
actions: [],
|
|
270
|
-
confirmations: tx
|
|
257
|
+
confirmations: tx.confirmations,
|
|
271
258
|
input: null,
|
|
272
|
-
gas_used: receipt
|
|
273
|
-
cumulative_gas_used: receipt
|
|
274
|
-
status: receipt
|
|
275
|
-
received_at: new Date(
|
|
259
|
+
gas_used: receipt.gasUsed.toString(),
|
|
260
|
+
cumulative_gas_used: receipt.cumulativeGasUsed.toString(),
|
|
261
|
+
status: receipt.status,
|
|
262
|
+
received_at: new Date(block.timestamp * 1000).toISOString(),
|
|
276
263
|
block: {
|
|
277
264
|
hash: log.blockHash,
|
|
278
265
|
height: log.blockNumber,
|
|
279
|
-
time: new Date(
|
|
266
|
+
time: new Date(block.timestamp * 1000).toISOString(),
|
|
280
267
|
},
|
|
281
268
|
};
|
|
282
269
|
explorerLedgerOperationByAddress[from].set(ledgerOperation.hash, ledgerOperation);
|
|
@@ -288,28 +275,28 @@ const handleERC1155Log = async (log, provider) => {
|
|
|
288
275
|
provider.getTransaction(log.transactionHash),
|
|
289
276
|
provider.getTransactionReceipt(log.transactionHash),
|
|
290
277
|
]);
|
|
291
|
-
const from = (0, utils_1.safeEncodeEIP55)(
|
|
292
|
-
const to = (0, utils_1.safeEncodeEIP55)(
|
|
293
|
-
const operator = (0, utils_1.safeEncodeEIP55)(
|
|
294
|
-
const transfersMap =
|
|
278
|
+
const from = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[2])[0]);
|
|
279
|
+
const to = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[3])[0]);
|
|
280
|
+
const operator = (0, utils_1.safeEncodeEIP55)(ethers_1.ethers.utils.defaultAbiCoder.decode(["address"], log.topics[1])[0]);
|
|
281
|
+
const transfersMap = ethers_1.ethers.utils.defaultAbiCoder
|
|
295
282
|
.decode(["uint256", "uint256"], log.data)
|
|
296
283
|
.map((value, index) => [index === 0 ? "id" : "value", value.toString()]);
|
|
297
284
|
const etherscanERC1155Events = transfersMap.map(([id, value]) => ({
|
|
298
|
-
blockNumber: block
|
|
299
|
-
timeStamp: block
|
|
300
|
-
hash: tx
|
|
301
|
-
nonce: tx
|
|
302
|
-
blockHash: block
|
|
285
|
+
blockNumber: block.number.toString(),
|
|
286
|
+
timeStamp: block.timestamp.toString(),
|
|
287
|
+
hash: tx.hash,
|
|
288
|
+
nonce: tx.nonce.toString(),
|
|
289
|
+
blockHash: block.hash,
|
|
303
290
|
from,
|
|
304
291
|
to,
|
|
305
|
-
transactionIndex: block
|
|
306
|
-
gas: tx
|
|
307
|
-
gasPrice: tx
|
|
308
|
-
cumulativeGasUsed: receipt
|
|
292
|
+
transactionIndex: block.transactions.indexOf(log.transactionHash).toString(),
|
|
293
|
+
gas: tx.gasLimit.toString(),
|
|
294
|
+
gasPrice: tx.gasPrice?.toString() || "",
|
|
295
|
+
cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
|
|
309
296
|
gasUsed: receipt?.gasUsed?.toString() || "0",
|
|
310
|
-
input: tx
|
|
311
|
-
confirmations: tx
|
|
312
|
-
contractAddress: tx
|
|
297
|
+
input: tx.data,
|
|
298
|
+
confirmations: tx.confirmations.toString(),
|
|
299
|
+
contractAddress: tx.to,
|
|
313
300
|
tokenID: id,
|
|
314
301
|
tokenValue: value,
|
|
315
302
|
tokenName: "tokenName",
|
|
@@ -331,9 +318,8 @@ const handleERC1155Log = async (log, provider) => {
|
|
|
331
318
|
if (!explorerLedgerOperationByAddress[to]) {
|
|
332
319
|
explorerLedgerOperationByAddress[to] = new Map();
|
|
333
320
|
}
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
(txHash && explorerLedgerOperationByAddress[to].get(txHash));
|
|
321
|
+
const alreadyExistingOperation = explorerLedgerOperationByAddress[from].get(tx.hash) ||
|
|
322
|
+
explorerLedgerOperationByAddress[to].get(tx.hash);
|
|
337
323
|
const ledgerOperation = alreadyExistingOperation
|
|
338
324
|
? {
|
|
339
325
|
...alreadyExistingOperation,
|
|
@@ -348,17 +334,17 @@ const handleERC1155Log = async (log, provider) => {
|
|
|
348
334
|
],
|
|
349
335
|
}
|
|
350
336
|
: {
|
|
351
|
-
hash: log.transactionHash
|
|
352
|
-
transaction_type: receipt
|
|
337
|
+
hash: log.transactionHash,
|
|
338
|
+
transaction_type: receipt.type,
|
|
353
339
|
nonce: "",
|
|
354
340
|
nonce_value: -1,
|
|
355
|
-
value: tx
|
|
356
|
-
gas: tx
|
|
357
|
-
gas_price: receipt
|
|
358
|
-
max_fee_per_gas: tx
|
|
359
|
-
max_priority_fee_per_gas: tx
|
|
360
|
-
from: tx
|
|
361
|
-
to: tx
|
|
341
|
+
value: tx.value.toString(),
|
|
342
|
+
gas: tx.gasLimit.toString(),
|
|
343
|
+
gas_price: receipt.effectiveGasPrice.toString(),
|
|
344
|
+
max_fee_per_gas: tx.type === 2 ? tx.maxFeePerGas.toString() : null,
|
|
345
|
+
max_priority_fee_per_gas: tx.type === 2 ? tx.maxPriorityFeePerGas.toString() : null,
|
|
346
|
+
from: tx.from,
|
|
347
|
+
to: tx.to,
|
|
362
348
|
transfer_events: [],
|
|
363
349
|
erc721_transfer_events: [],
|
|
364
350
|
erc1155_transfer_events: [
|
|
@@ -372,52 +358,52 @@ const handleERC1155Log = async (log, provider) => {
|
|
|
372
358
|
],
|
|
373
359
|
approval_events: [],
|
|
374
360
|
actions: [],
|
|
375
|
-
confirmations: tx
|
|
361
|
+
confirmations: tx.confirmations,
|
|
376
362
|
input: null,
|
|
377
|
-
gas_used: receipt
|
|
378
|
-
cumulative_gas_used: receipt
|
|
379
|
-
status: receipt
|
|
380
|
-
received_at: new Date(
|
|
363
|
+
gas_used: receipt.gasUsed.toString(),
|
|
364
|
+
cumulative_gas_used: receipt.cumulativeGasUsed.toString(),
|
|
365
|
+
status: receipt.status,
|
|
366
|
+
received_at: new Date(block.timestamp * 1000).toISOString(),
|
|
381
367
|
block: {
|
|
382
368
|
hash: log.blockHash,
|
|
383
369
|
height: log.blockNumber,
|
|
384
|
-
time: new Date(
|
|
370
|
+
time: new Date(block.timestamp * 1000).toISOString(),
|
|
385
371
|
},
|
|
386
372
|
};
|
|
387
373
|
explorerLedgerOperationByAddress[from].set(ledgerOperation.hash, ledgerOperation);
|
|
388
374
|
explorerLedgerOperationByAddress[to].set(ledgerOperation.hash, ledgerOperation);
|
|
389
375
|
};
|
|
390
376
|
const handleBlock = async (blockNumber, provider) => {
|
|
391
|
-
const block = await provider.
|
|
377
|
+
const block = await provider.getBlockWithTransactions(blockNumber);
|
|
392
378
|
for (const transaction of block?.transactions || []) {
|
|
393
379
|
const [tx, receipt, traces] = await Promise.all([
|
|
394
|
-
provider.getTransaction(transaction),
|
|
395
|
-
provider.getTransactionReceipt(transaction),
|
|
396
|
-
provider.send("trace_transaction", [transaction]).catch(() => []),
|
|
380
|
+
provider.getTransaction(transaction.hash),
|
|
381
|
+
provider.getTransactionReceipt(transaction.hash),
|
|
382
|
+
provider.send("trace_transaction", [transaction.hash]).catch(() => []),
|
|
397
383
|
]);
|
|
398
|
-
const code =
|
|
399
|
-
const from = (0, utils_1.safeEncodeEIP55)(
|
|
400
|
-
const to = (0, utils_1.safeEncodeEIP55)(
|
|
384
|
+
const code = transaction.to ? await provider.getCode(transaction.to) : false;
|
|
385
|
+
const from = (0, utils_1.safeEncodeEIP55)(transaction.from);
|
|
386
|
+
const to = (0, utils_1.safeEncodeEIP55)(transaction.to || "");
|
|
401
387
|
const etherscanOperation = {
|
|
402
|
-
blockNumber: block
|
|
403
|
-
timeStamp: block
|
|
404
|
-
hash:
|
|
405
|
-
nonce:
|
|
406
|
-
blockHash: block
|
|
407
|
-
transactionIndex: block
|
|
388
|
+
blockNumber: block.number.toString(),
|
|
389
|
+
timeStamp: block.timestamp.toString(),
|
|
390
|
+
hash: transaction.hash,
|
|
391
|
+
nonce: transaction.nonce.toString(),
|
|
392
|
+
blockHash: block.hash,
|
|
393
|
+
transactionIndex: block.transactions.indexOf(transaction).toString(),
|
|
408
394
|
from,
|
|
409
395
|
to,
|
|
410
|
-
value:
|
|
411
|
-
gas:
|
|
412
|
-
gasPrice:
|
|
413
|
-
isError: receipt
|
|
414
|
-
txreceipt_status: receipt
|
|
415
|
-
input:
|
|
416
|
-
contractAddress: code === "0x" ? "" :
|
|
417
|
-
cumulativeGasUsed: receipt
|
|
396
|
+
value: transaction.value.toBigInt().toString(),
|
|
397
|
+
gas: transaction.gasLimit.toString(),
|
|
398
|
+
gasPrice: transaction.gasPrice?.toString() || "",
|
|
399
|
+
isError: receipt.status === 1 ? "0" : "1",
|
|
400
|
+
txreceipt_status: receipt.status.toString(),
|
|
401
|
+
input: transaction.data,
|
|
402
|
+
contractAddress: code === "0x" ? "" : transaction.to,
|
|
403
|
+
cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
|
|
418
404
|
gasUsed: receipt?.gasUsed?.toString() || "0",
|
|
419
|
-
confirmations:
|
|
420
|
-
methodId:
|
|
405
|
+
confirmations: transaction.confirmations.toString(),
|
|
406
|
+
methodId: transaction.data?.length > 10 ? transaction.data.slice(0, 10) : "",
|
|
421
407
|
functionName: "",
|
|
422
408
|
};
|
|
423
409
|
if (!explorerEtherscanOperationByAddress[from]) {
|
|
@@ -435,32 +421,32 @@ const handleBlock = async (blockNumber, provider) => {
|
|
|
435
421
|
explorerLedgerOperationByAddress[to] = new Map();
|
|
436
422
|
}
|
|
437
423
|
const ledgerOperation = {
|
|
438
|
-
hash: receipt
|
|
439
|
-
transaction_type: receipt
|
|
424
|
+
hash: receipt.transactionHash,
|
|
425
|
+
transaction_type: receipt.type,
|
|
440
426
|
nonce: "",
|
|
441
427
|
nonce_value: -1,
|
|
442
|
-
value: tx
|
|
443
|
-
gas: tx
|
|
444
|
-
gas_price: receipt
|
|
445
|
-
max_fee_per_gas: tx
|
|
446
|
-
max_priority_fee_per_gas: tx
|
|
447
|
-
from: tx
|
|
448
|
-
to: tx
|
|
428
|
+
value: tx.value.toString(),
|
|
429
|
+
gas: tx.gasLimit.toString(),
|
|
430
|
+
gas_price: receipt.effectiveGasPrice.toString(),
|
|
431
|
+
max_fee_per_gas: tx.type === 2 ? tx.maxFeePerGas.toString() : null,
|
|
432
|
+
max_priority_fee_per_gas: tx.type === 2 ? tx.maxPriorityFeePerGas.toString() : null,
|
|
433
|
+
from: tx.from,
|
|
434
|
+
to: tx.to,
|
|
449
435
|
transfer_events: [],
|
|
450
436
|
erc721_transfer_events: [],
|
|
451
437
|
erc1155_transfer_events: [],
|
|
452
438
|
approval_events: [],
|
|
453
439
|
actions: [],
|
|
454
|
-
confirmations: tx
|
|
440
|
+
confirmations: tx.confirmations,
|
|
455
441
|
input: null,
|
|
456
|
-
gas_used: receipt
|
|
457
|
-
cumulative_gas_used: receipt
|
|
458
|
-
status: receipt
|
|
459
|
-
received_at: new Date(
|
|
442
|
+
gas_used: receipt.gasUsed.toString(),
|
|
443
|
+
cumulative_gas_used: receipt.cumulativeGasUsed.toString(),
|
|
444
|
+
status: receipt.status,
|
|
445
|
+
received_at: new Date(block.timestamp * 1000).toISOString(),
|
|
460
446
|
block: {
|
|
461
|
-
hash: receipt
|
|
462
|
-
height: receipt
|
|
463
|
-
time: new Date(
|
|
447
|
+
hash: receipt.blockHash,
|
|
448
|
+
height: receipt.blockNumber,
|
|
449
|
+
time: new Date(block.timestamp * 1000).toISOString(),
|
|
464
450
|
},
|
|
465
451
|
};
|
|
466
452
|
explorerLedgerOperationByAddress[from].set(ledgerOperation.hash, ledgerOperation);
|
|
@@ -473,18 +459,20 @@ const handleBlock = async (blockNumber, provider) => {
|
|
|
473
459
|
const to = (0, utils_1.safeEncodeEIP55)(action.to || "");
|
|
474
460
|
const etherscanInternalTransaction = {
|
|
475
461
|
blockNumber: blockNumber.toString(),
|
|
476
|
-
timeStamp: block
|
|
462
|
+
timeStamp: block.timestamp.toString(),
|
|
477
463
|
hash: transactionHash,
|
|
478
464
|
from,
|
|
479
465
|
to,
|
|
480
|
-
value:
|
|
466
|
+
value: ethers_1.ethers.BigNumber.from(action.value).toBigInt().toString(),
|
|
481
467
|
contractAddress: code === "0x" ? "" : action.to,
|
|
482
468
|
input: action.input || "0x",
|
|
483
469
|
type,
|
|
484
|
-
gas:
|
|
485
|
-
gasUsed:
|
|
470
|
+
gas: ethers_1.ethers.BigNumber.from(action.gas).toBigInt().toString(),
|
|
471
|
+
gasUsed: ethers_1.ethers.BigNumber.from(result?.gasUsed || "0")
|
|
472
|
+
.toBigInt()
|
|
473
|
+
.toString(),
|
|
486
474
|
traceId: transactionPosition.toString(),
|
|
487
|
-
isError: receipt
|
|
475
|
+
isError: receipt.status === 1 ? "0" : "1",
|
|
488
476
|
errCode: "",
|
|
489
477
|
};
|
|
490
478
|
if (!explorerEtherscanInternalByAddress[from]) {
|
|
@@ -501,9 +489,8 @@ const handleBlock = async (blockNumber, provider) => {
|
|
|
501
489
|
if (!explorerLedgerOperationByAddress[to]) {
|
|
502
490
|
explorerLedgerOperationByAddress[to] = new Map();
|
|
503
491
|
}
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
(txHash && explorerLedgerOperationByAddress[to].get(txHash));
|
|
492
|
+
const alreadyExistingOperation = explorerLedgerOperationByAddress[from].get(tx.hash) ||
|
|
493
|
+
explorerLedgerOperationByAddress[to].get(tx.hash);
|
|
507
494
|
const ledgerOperation = alreadyExistingOperation
|
|
508
495
|
? {
|
|
509
496
|
...alreadyExistingOperation,
|
|
@@ -513,25 +500,27 @@ const handleBlock = async (blockNumber, provider) => {
|
|
|
513
500
|
from,
|
|
514
501
|
to,
|
|
515
502
|
input: null,
|
|
516
|
-
value:
|
|
517
|
-
gas:
|
|
518
|
-
gas_used:
|
|
503
|
+
value: ethers_1.ethers.BigNumber.from(action.value).toBigInt().toString(),
|
|
504
|
+
gas: ethers_1.ethers.BigNumber.from(action.gas).toBigInt().toString(),
|
|
505
|
+
gas_used: ethers_1.ethers.BigNumber.from(result?.gasUsed || "0")
|
|
506
|
+
.toBigInt()
|
|
507
|
+
.toString(),
|
|
519
508
|
error: null,
|
|
520
509
|
},
|
|
521
510
|
],
|
|
522
511
|
}
|
|
523
512
|
: {
|
|
524
|
-
hash: receipt
|
|
525
|
-
transaction_type: receipt
|
|
513
|
+
hash: receipt.transactionHash,
|
|
514
|
+
transaction_type: receipt.type,
|
|
526
515
|
nonce: "",
|
|
527
516
|
nonce_value: -1,
|
|
528
|
-
value: tx
|
|
529
|
-
gas: tx
|
|
530
|
-
gas_price: receipt
|
|
531
|
-
max_fee_per_gas: tx
|
|
532
|
-
max_priority_fee_per_gas: tx
|
|
533
|
-
from: tx
|
|
534
|
-
to: tx
|
|
517
|
+
value: tx.value.toString(),
|
|
518
|
+
gas: tx.gasLimit.toString(),
|
|
519
|
+
gas_price: receipt.effectiveGasPrice.toString(),
|
|
520
|
+
max_fee_per_gas: tx.type === 2 ? tx.maxFeePerGas.toString() : null,
|
|
521
|
+
max_priority_fee_per_gas: tx.type === 2 ? tx.maxPriorityFeePerGas.toString() : null,
|
|
522
|
+
from: tx.from,
|
|
523
|
+
to: tx.to,
|
|
535
524
|
transfer_events: [],
|
|
536
525
|
erc721_transfer_events: [],
|
|
537
526
|
erc1155_transfer_events: [],
|
|
@@ -541,22 +530,24 @@ const handleBlock = async (blockNumber, provider) => {
|
|
|
541
530
|
from,
|
|
542
531
|
to,
|
|
543
532
|
input: null,
|
|
544
|
-
value:
|
|
545
|
-
gas:
|
|
546
|
-
gas_used:
|
|
533
|
+
value: ethers_1.ethers.BigNumber.from(action.value).toBigInt().toString(),
|
|
534
|
+
gas: ethers_1.ethers.BigNumber.from(action.gas).toBigInt().toString(),
|
|
535
|
+
gas_used: ethers_1.ethers.BigNumber.from(result?.gasUsed || "0")
|
|
536
|
+
.toBigInt()
|
|
537
|
+
.toString(),
|
|
547
538
|
error: null,
|
|
548
539
|
},
|
|
549
540
|
],
|
|
550
|
-
confirmations: tx
|
|
541
|
+
confirmations: tx.confirmations,
|
|
551
542
|
input: null,
|
|
552
|
-
gas_used: receipt
|
|
553
|
-
cumulative_gas_used: receipt
|
|
554
|
-
status: receipt
|
|
555
|
-
received_at: new Date(
|
|
543
|
+
gas_used: receipt.gasUsed.toString(),
|
|
544
|
+
cumulative_gas_used: receipt.cumulativeGasUsed.toString(),
|
|
545
|
+
status: receipt.status,
|
|
546
|
+
received_at: new Date(block.timestamp * 1000).toISOString(),
|
|
556
547
|
block: {
|
|
557
|
-
hash: receipt
|
|
558
|
-
height: receipt
|
|
559
|
-
time: new Date(
|
|
548
|
+
hash: receipt.blockHash,
|
|
549
|
+
height: receipt.blockNumber,
|
|
550
|
+
time: new Date(block.timestamp * 1000).toISOString(),
|
|
560
551
|
},
|
|
561
552
|
};
|
|
562
553
|
explorerLedgerOperationByAddress[from].set(ledgerOperation.hash, ledgerOperation);
|
|
@@ -572,7 +563,7 @@ const indexBlocks = async () => {
|
|
|
572
563
|
if (!fromBlock) {
|
|
573
564
|
throw new Error("fromBlock is not set");
|
|
574
565
|
}
|
|
575
|
-
const provider = new ethers_1.
|
|
566
|
+
const provider = new ethers_1.providers.StaticJsonRpcProvider(process.env.RPC);
|
|
576
567
|
let latestBlockNumber = await provider.getBlockNumber();
|
|
577
568
|
const toBlock = Math.min(fromBlock + MAX_BLOCK_RANGE, latestBlockNumber);
|
|
578
569
|
const rangeSize = toBlock - fromBlock + 1;
|