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