@0xtorch/evm 0.0.157 → 0.0.158
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/_cjs/explorer/blockscout/create.js +49 -24
- package/_cjs/explorer/blockscout/create.js.map +1 -1
- package/_cjs/explorer/etherscan/create.js +53 -26
- package/_cjs/explorer/etherscan/create.js.map +1 -1
- package/_cjs/explorer/etherscanV2/create.js +53 -26
- package/_cjs/explorer/etherscanV2/create.js.map +1 -1
- package/_cjs/explorer/moralis/create.js +15 -3
- package/_cjs/explorer/moralis/create.js.map +1 -1
- package/_esm/explorer/blockscout/create.js +53 -24
- package/_esm/explorer/blockscout/create.js.map +1 -1
- package/_esm/explorer/etherscan/create.js +57 -26
- package/_esm/explorer/etherscan/create.js.map +1 -1
- package/_esm/explorer/etherscanV2/create.js +57 -26
- package/_esm/explorer/etherscanV2/create.js.map +1 -1
- package/_esm/explorer/moralis/create.js +19 -3
- package/_esm/explorer/moralis/create.js.map +1 -1
- package/_types/explorer/blockscout/create.d.ts.map +1 -1
- package/_types/explorer/etherscan/create.d.ts.map +1 -1
- package/_types/explorer/etherscanV2/create.d.ts.map +1 -1
- package/_types/explorer/index.d.ts +1 -1
- package/_types/explorer/index.d.ts.map +1 -1
- package/_types/explorer/moralis/create.d.ts.map +1 -1
- package/_types/explorer/types.d.ts +9 -8
- package/_types/explorer/types.d.ts.map +1 -1
- package/explorer/blockscout/create.ts +49 -21
- package/explorer/etherscan/create.ts +56 -23
- package/explorer/etherscanV2/create.ts +56 -23
- package/explorer/index.ts +1 -1
- package/explorer/moralis/create.ts +23 -4
- package/explorer/types.ts +13 -8
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import type { Erc20Transfer, LowerHex } from '../../types'
|
|
|
2
2
|
import type { InternalTransactionWithIndex } from '../../types/internalTransaction'
|
|
3
3
|
import type { TransactionIndex } from '../../types/transactionIndex'
|
|
4
4
|
import { createInternalTransactionId } from '../../utils/createInternalTransactionId'
|
|
5
|
-
import type { Explorer, LogWithBlockNumber } from '../types'
|
|
5
|
+
import type { Explorer, HeadersInput, LogWithBlockNumber } from '../types'
|
|
6
6
|
import { createEtherscanV2Client } from './client'
|
|
7
7
|
import { getBlockNumberByTimestamp } from './getBlockNumberByTimestamp'
|
|
8
8
|
import { getContractCreatorAndCreationTxHash } from './getContractCreatorAndCreationTxHash'
|
|
@@ -15,6 +15,22 @@ import { getListOfErc1155TokenTransferEventsByAddress } from './getListOfErc1155
|
|
|
15
15
|
import { getListOfInternalTransactionsByAddress } from './getListOfInternalTransactionsByAddress'
|
|
16
16
|
import { getListOfNormalTransactionsByAddress } from './getListOfNormalTransactionsByAddress'
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Resolves headers from either a static object or a function that returns headers.
|
|
20
|
+
* This allows for dynamic header generation (e.g., refreshing auth tokens).
|
|
21
|
+
*/
|
|
22
|
+
const resolveHeaders = async (
|
|
23
|
+
headers: HeadersInput,
|
|
24
|
+
): Promise<Record<string, string> | undefined> => {
|
|
25
|
+
if (headers === undefined) {
|
|
26
|
+
return undefined
|
|
27
|
+
}
|
|
28
|
+
if (typeof headers === 'function') {
|
|
29
|
+
return await headers()
|
|
30
|
+
}
|
|
31
|
+
return headers
|
|
32
|
+
}
|
|
33
|
+
|
|
18
34
|
type CreateEtherscanV2Parameters = {
|
|
19
35
|
name: string
|
|
20
36
|
baseUrl: string
|
|
@@ -54,13 +70,14 @@ export const createEtherscanV2 = ({
|
|
|
54
70
|
let startblock = fromBlock
|
|
55
71
|
const endblock = toBlock
|
|
56
72
|
while (true) {
|
|
73
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
57
74
|
const result = await getListOfInternalTransactionsByAddress({
|
|
58
75
|
client,
|
|
59
76
|
address,
|
|
60
77
|
startblock,
|
|
61
78
|
endblock,
|
|
62
79
|
offset: pageSize,
|
|
63
|
-
headers,
|
|
80
|
+
headers: resolvedHeaders,
|
|
64
81
|
})
|
|
65
82
|
for (const transaction of result) {
|
|
66
83
|
const id = createInternalTransactionId(transaction)
|
|
@@ -86,13 +103,14 @@ export const createEtherscanV2 = ({
|
|
|
86
103
|
let startblock = fromBlock
|
|
87
104
|
const endblock = toBlock
|
|
88
105
|
while (true) {
|
|
106
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
89
107
|
const result = await getListOfNormalTransactionsByAddress({
|
|
90
108
|
client,
|
|
91
109
|
address,
|
|
92
110
|
startblock,
|
|
93
111
|
endblock,
|
|
94
112
|
offset: pageSize,
|
|
95
|
-
headers,
|
|
113
|
+
headers: resolvedHeaders,
|
|
96
114
|
})
|
|
97
115
|
for (const index of result) {
|
|
98
116
|
if (!indexes.has(index.hash)) {
|
|
@@ -120,6 +138,7 @@ export const createEtherscanV2 = ({
|
|
|
120
138
|
// ERC20
|
|
121
139
|
let startblock = fromBlock
|
|
122
140
|
while (true) {
|
|
141
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
123
142
|
const { indexes: resultIndexes, erc20Transfers: resultErc20Transfers } =
|
|
124
143
|
await getListOfErc20TokenTransferEventsByAddress({
|
|
125
144
|
client,
|
|
@@ -127,7 +146,7 @@ export const createEtherscanV2 = ({
|
|
|
127
146
|
startblock,
|
|
128
147
|
endblock,
|
|
129
148
|
offset: pageSize,
|
|
130
|
-
headers,
|
|
149
|
+
headers: resolvedHeaders,
|
|
131
150
|
})
|
|
132
151
|
for (const index of resultIndexes) {
|
|
133
152
|
if (!indexes.has(index.hash)) {
|
|
@@ -147,13 +166,14 @@ export const createEtherscanV2 = ({
|
|
|
147
166
|
// ERC721
|
|
148
167
|
startblock = fromBlock
|
|
149
168
|
while (true) {
|
|
169
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
150
170
|
const result = await getListOfErc721TokenTransferEventsByAddress({
|
|
151
171
|
client,
|
|
152
172
|
address,
|
|
153
173
|
startblock,
|
|
154
174
|
endblock,
|
|
155
175
|
offset: pageSize,
|
|
156
|
-
headers,
|
|
176
|
+
headers: resolvedHeaders,
|
|
157
177
|
})
|
|
158
178
|
for (const index of result) {
|
|
159
179
|
if (!indexes.has(index.hash)) {
|
|
@@ -170,13 +190,14 @@ export const createEtherscanV2 = ({
|
|
|
170
190
|
// ERC1155
|
|
171
191
|
startblock = fromBlock
|
|
172
192
|
while (true) {
|
|
193
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
173
194
|
const result = await getListOfErc1155TokenTransferEventsByAddress({
|
|
174
195
|
client,
|
|
175
196
|
address,
|
|
176
197
|
startblock,
|
|
177
198
|
endblock,
|
|
178
199
|
offset: pageSize,
|
|
179
|
-
headers,
|
|
200
|
+
headers: resolvedHeaders,
|
|
180
201
|
})
|
|
181
202
|
for (const index of result) {
|
|
182
203
|
if (!indexes.has(index.hash)) {
|
|
@@ -195,24 +216,33 @@ export const createEtherscanV2 = ({
|
|
|
195
216
|
erc20Transfers,
|
|
196
217
|
}
|
|
197
218
|
},
|
|
198
|
-
getBlockNumberOfTimestamp: ({
|
|
199
|
-
|
|
219
|
+
getBlockNumberOfTimestamp: async ({
|
|
220
|
+
timestamp,
|
|
221
|
+
headers,
|
|
222
|
+
}): Promise<number> => {
|
|
223
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
224
|
+
return getBlockNumberByTimestamp({
|
|
200
225
|
client,
|
|
201
226
|
timestamp: Math.floor(timestamp / 1000),
|
|
202
|
-
headers,
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
|
|
227
|
+
headers: resolvedHeaders,
|
|
228
|
+
})
|
|
229
|
+
},
|
|
230
|
+
getContract: async ({ address, headers }) => {
|
|
231
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
232
|
+
return getContractSourceCodeForVerifiedContract({
|
|
206
233
|
client,
|
|
207
234
|
address,
|
|
208
|
-
headers,
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
|
|
235
|
+
headers: resolvedHeaders,
|
|
236
|
+
})
|
|
237
|
+
},
|
|
238
|
+
getContractCreations: async ({ addresses, headers }) => {
|
|
239
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
240
|
+
return getContractCreatorAndCreationTxHash({
|
|
212
241
|
client,
|
|
213
242
|
contractaddresses: addresses,
|
|
214
|
-
headers,
|
|
215
|
-
})
|
|
243
|
+
headers: resolvedHeaders,
|
|
244
|
+
})
|
|
245
|
+
},
|
|
216
246
|
getEventLogs: async ({
|
|
217
247
|
address,
|
|
218
248
|
topic0,
|
|
@@ -224,13 +254,14 @@ export const createEtherscanV2 = ({
|
|
|
224
254
|
let fromBlock = fromBlockParam ?? 0
|
|
225
255
|
const maxPageSize = 10_000
|
|
226
256
|
while (true) {
|
|
257
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
227
258
|
const result = await getEventLogsByAddressFilteredByTopics({
|
|
228
259
|
client,
|
|
229
260
|
address,
|
|
230
261
|
topic0,
|
|
231
262
|
fromBlock,
|
|
232
263
|
toBlock,
|
|
233
|
-
headers,
|
|
264
|
+
headers: resolvedHeaders,
|
|
234
265
|
})
|
|
235
266
|
logs.push(...result)
|
|
236
267
|
if (result.length < maxPageSize) {
|
|
@@ -241,11 +272,13 @@ export const createEtherscanV2 = ({
|
|
|
241
272
|
}
|
|
242
273
|
return logs
|
|
243
274
|
},
|
|
244
|
-
getInternalTransactionOfTransaction: ({ hash, headers }) =>
|
|
245
|
-
|
|
275
|
+
getInternalTransactionOfTransaction: async ({ hash, headers }) => {
|
|
276
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
277
|
+
return getInternalTransactionsByTransactionHash({
|
|
246
278
|
client,
|
|
247
279
|
txhash: hash,
|
|
248
|
-
headers,
|
|
249
|
-
})
|
|
280
|
+
headers: resolvedHeaders,
|
|
281
|
+
})
|
|
282
|
+
},
|
|
250
283
|
}
|
|
251
284
|
}
|
package/explorer/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createEtherscan } from './etherscan/create'
|
|
2
2
|
export { createEtherscanV2 } from './etherscanV2/create'
|
|
3
|
-
export type { Explorer } from './types'
|
|
3
|
+
export type { Explorer, HeadersInput } from './types'
|
|
4
4
|
export { createMoralisExplorer } from './moralis/create'
|
|
5
5
|
export { createNoApiExplorer } from './noApiExplorer/create'
|
|
6
6
|
export { createBlockscout } from './blockscout/create'
|
|
@@ -6,10 +6,26 @@ import {
|
|
|
6
6
|
toLowerHex,
|
|
7
7
|
} from '../../types'
|
|
8
8
|
import { createInternalTransactionId } from '../../utils/createInternalTransactionId'
|
|
9
|
-
import type { Explorer } from '../types'
|
|
9
|
+
import type { Explorer, HeadersInput } from '../types'
|
|
10
10
|
import { createMoralisClient } from './client'
|
|
11
11
|
import { getWalletTransactionHistory } from './getWalletTransactionHistory'
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Resolves headers from either a static object or a function that returns headers.
|
|
15
|
+
* This allows for dynamic header generation (e.g., refreshing auth tokens).
|
|
16
|
+
*/
|
|
17
|
+
const resolveHeaders = async (
|
|
18
|
+
headers: HeadersInput,
|
|
19
|
+
): Promise<Record<string, string> | undefined> => {
|
|
20
|
+
if (headers === undefined) {
|
|
21
|
+
return undefined
|
|
22
|
+
}
|
|
23
|
+
if (typeof headers === 'function') {
|
|
24
|
+
return await headers()
|
|
25
|
+
}
|
|
26
|
+
return headers
|
|
27
|
+
}
|
|
28
|
+
|
|
13
29
|
type CreateMoralisExplorerParameters = {
|
|
14
30
|
name: string
|
|
15
31
|
baseUrl: string
|
|
@@ -52,6 +68,7 @@ export const createMoralisExplorer = ({
|
|
|
52
68
|
let cursor: string | undefined = undefined
|
|
53
69
|
while (count < maxRequestCount) {
|
|
54
70
|
count += 1
|
|
71
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
55
72
|
const result = await getWalletTransactionHistory({
|
|
56
73
|
client,
|
|
57
74
|
address: lowerAddress,
|
|
@@ -59,7 +76,7 @@ export const createMoralisExplorer = ({
|
|
|
59
76
|
fromBlock,
|
|
60
77
|
toBlock,
|
|
61
78
|
cursor,
|
|
62
|
-
headers,
|
|
79
|
+
headers: resolvedHeaders,
|
|
63
80
|
})
|
|
64
81
|
cursor = result.cursor ?? undefined
|
|
65
82
|
|
|
@@ -108,6 +125,7 @@ export const createMoralisExplorer = ({
|
|
|
108
125
|
let cursor: string | undefined = undefined
|
|
109
126
|
while (count < maxRequestCount) {
|
|
110
127
|
count += 1
|
|
128
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
111
129
|
const result = await getWalletTransactionHistory({
|
|
112
130
|
client,
|
|
113
131
|
address: lowerAddress,
|
|
@@ -115,7 +133,7 @@ export const createMoralisExplorer = ({
|
|
|
115
133
|
fromBlock,
|
|
116
134
|
toBlock,
|
|
117
135
|
cursor,
|
|
118
|
-
headers,
|
|
136
|
+
headers: resolvedHeaders,
|
|
119
137
|
})
|
|
120
138
|
cursor = result.cursor ?? undefined
|
|
121
139
|
|
|
@@ -152,6 +170,7 @@ export const createMoralisExplorer = ({
|
|
|
152
170
|
let cursor: string | undefined = undefined
|
|
153
171
|
while (count < maxRequestCount) {
|
|
154
172
|
count += 1
|
|
173
|
+
const resolvedHeaders = await resolveHeaders(headers)
|
|
155
174
|
const result = await getWalletTransactionHistory({
|
|
156
175
|
client,
|
|
157
176
|
address: lowerAddress,
|
|
@@ -159,7 +178,7 @@ export const createMoralisExplorer = ({
|
|
|
159
178
|
fromBlock,
|
|
160
179
|
toBlock,
|
|
161
180
|
cursor,
|
|
162
|
-
headers,
|
|
181
|
+
headers: resolvedHeaders,
|
|
163
182
|
})
|
|
164
183
|
cursor = result.cursor ?? undefined
|
|
165
184
|
|
package/explorer/types.ts
CHANGED
|
@@ -18,6 +18,11 @@ export type LogWithBlockNumber = Log & {
|
|
|
18
18
|
blockNumber: number
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export type HeadersInput =
|
|
22
|
+
| Record<string, string>
|
|
23
|
+
| (() => Promise<Record<string, string> | undefined>)
|
|
24
|
+
| undefined
|
|
25
|
+
|
|
21
26
|
export type Explorer = {
|
|
22
27
|
readonly name: string
|
|
23
28
|
readonly baseUrl: string
|
|
@@ -35,21 +40,21 @@ type FunctionGetAddressInternalTransactions = (parameters: {
|
|
|
35
40
|
address: Hex
|
|
36
41
|
fromBlock?: number
|
|
37
42
|
toBlock?: number
|
|
38
|
-
headers?:
|
|
43
|
+
headers?: HeadersInput
|
|
39
44
|
}) => Promise<InternalTransactionWithIndex[]>
|
|
40
45
|
|
|
41
46
|
type FunctionGetAddressTransactionIndexes = (parameters: {
|
|
42
47
|
address: Hex
|
|
43
48
|
fromBlock?: number
|
|
44
49
|
toBlock?: number
|
|
45
|
-
headers?:
|
|
50
|
+
headers?: HeadersInput
|
|
46
51
|
}) => Promise<TransactionIndex[]>
|
|
47
52
|
|
|
48
53
|
type FunctionGetAddressTokenTransferIndexes = (parameters: {
|
|
49
54
|
address: Hex
|
|
50
55
|
fromBlock?: number
|
|
51
56
|
toBlock?: number
|
|
52
|
-
headers?:
|
|
57
|
+
headers?: HeadersInput
|
|
53
58
|
}) => Promise<{
|
|
54
59
|
indexes: TransactionIndex[]
|
|
55
60
|
erc20Transfers: Erc20Transfer[]
|
|
@@ -58,17 +63,17 @@ type FunctionGetAddressTokenTransferIndexes = (parameters: {
|
|
|
58
63
|
type FunctionGetBlockNumberOfTimestamp = (parameters: {
|
|
59
64
|
/** Unix timestamp in milliseconds */
|
|
60
65
|
timestamp: number
|
|
61
|
-
headers?:
|
|
66
|
+
headers?: HeadersInput
|
|
62
67
|
}) => Promise<number>
|
|
63
68
|
|
|
64
69
|
type FunctionGetContract = (parameters: {
|
|
65
70
|
address: Hex
|
|
66
|
-
headers?:
|
|
71
|
+
headers?: HeadersInput
|
|
67
72
|
}) => Promise<Contract | undefined>
|
|
68
73
|
|
|
69
74
|
type FunctionGetContractCreations = (parameters: {
|
|
70
75
|
addresses: Hex[]
|
|
71
|
-
headers?:
|
|
76
|
+
headers?: HeadersInput
|
|
72
77
|
}) => Promise<ContractCreation[]>
|
|
73
78
|
|
|
74
79
|
type FunctionGetEventLogs = (parameters: {
|
|
@@ -76,10 +81,10 @@ type FunctionGetEventLogs = (parameters: {
|
|
|
76
81
|
topic0: LowerHex
|
|
77
82
|
fromBlock?: number
|
|
78
83
|
toBlock?: number
|
|
79
|
-
headers?:
|
|
84
|
+
headers?: HeadersInput
|
|
80
85
|
}) => Promise<LogWithBlockNumber[]>
|
|
81
86
|
|
|
82
87
|
type FunctionGetInternalTransactionOfTransaction = (parameters: {
|
|
83
88
|
hash: LowerHex
|
|
84
|
-
headers?:
|
|
89
|
+
headers?: HeadersInput
|
|
85
90
|
}) => Promise<InternalTransactionWithIndex[]>
|