envio 3.0.0-alpha.21 → 3.0.0-alpha.22
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/bin.mjs +2 -48
- package/evm.schema.json +67 -0
- package/fuel.schema.json +67 -0
- package/index.d.ts +822 -38
- package/index.js +5 -3
- package/package.json +10 -8
- package/rescript.json +5 -9
- package/src/Address.res +4 -5
- package/src/Address.res.mjs +9 -12
- package/src/Api.res +15 -0
- package/src/Api.res.mjs +20 -0
- package/src/Batch.res +32 -34
- package/src/Batch.res.mjs +172 -187
- package/src/Bin.res +89 -0
- package/src/Bin.res.mjs +97 -0
- package/src/ChainFetcher.res +33 -57
- package/src/ChainFetcher.res.mjs +197 -227
- package/src/ChainManager.res +6 -14
- package/src/ChainManager.res.mjs +74 -85
- package/src/ChainMap.res +14 -16
- package/src/ChainMap.res.mjs +38 -38
- package/src/Config.res +193 -135
- package/src/Config.res.mjs +566 -592
- package/src/Core.res +182 -0
- package/src/Core.res.mjs +207 -0
- package/src/Ecosystem.res +25 -4
- package/src/Ecosystem.res.mjs +12 -13
- package/src/Env.res +20 -13
- package/src/Env.res.mjs +124 -113
- package/src/EnvSafe.res +269 -0
- package/src/EnvSafe.res.mjs +296 -0
- package/src/EnvSafe.resi +18 -0
- package/src/Envio.res +37 -26
- package/src/Envio.res.mjs +59 -60
- package/src/ErrorHandling.res +2 -2
- package/src/ErrorHandling.res.mjs +15 -15
- package/src/EventConfigBuilder.res +219 -81
- package/src/EventConfigBuilder.res.mjs +259 -202
- package/src/EventProcessing.res +27 -38
- package/src/EventProcessing.res.mjs +165 -183
- package/src/EventUtils.res +11 -11
- package/src/EventUtils.res.mjs +21 -22
- package/src/EvmTypes.res +0 -1
- package/src/EvmTypes.res.mjs +5 -5
- package/src/FetchState.res +360 -256
- package/src/FetchState.res.mjs +958 -914
- package/src/GlobalState.res +365 -351
- package/src/GlobalState.res.mjs +958 -992
- package/src/GlobalStateManager.res +1 -2
- package/src/GlobalStateManager.res.mjs +36 -44
- package/src/HandlerLoader.res +107 -23
- package/src/HandlerLoader.res.mjs +128 -38
- package/src/HandlerRegister.res +127 -103
- package/src/HandlerRegister.res.mjs +164 -164
- package/src/HandlerRegister.resi +12 -4
- package/src/Hasura.res +35 -22
- package/src/Hasura.res.mjs +158 -167
- package/src/InMemoryStore.res +20 -27
- package/src/InMemoryStore.res.mjs +64 -80
- package/src/InMemoryTable.res +34 -39
- package/src/InMemoryTable.res.mjs +165 -170
- package/src/Internal.res +52 -33
- package/src/Internal.res.mjs +84 -81
- package/src/LazyLoader.res.mjs +55 -61
- package/src/LoadLayer.res +77 -78
- package/src/LoadLayer.res.mjs +160 -189
- package/src/LoadManager.res +16 -21
- package/src/LoadManager.res.mjs +79 -84
- package/src/LogSelection.res +236 -68
- package/src/LogSelection.res.mjs +211 -141
- package/src/Logging.res +13 -9
- package/src/Logging.res.mjs +130 -143
- package/src/Main.res +428 -51
- package/src/Main.res.mjs +528 -271
- package/src/Persistence.res +77 -84
- package/src/Persistence.res.mjs +131 -132
- package/src/PgStorage.res +291 -167
- package/src/PgStorage.res.mjs +797 -817
- package/src/Prometheus.res +50 -58
- package/src/Prometheus.res.mjs +345 -373
- package/src/ReorgDetection.res +22 -24
- package/src/ReorgDetection.res.mjs +100 -106
- package/src/SafeCheckpointTracking.res +7 -7
- package/src/SafeCheckpointTracking.res.mjs +40 -43
- package/src/SimulateItems.res +41 -49
- package/src/SimulateItems.res.mjs +257 -272
- package/src/Sink.res +2 -2
- package/src/Sink.res.mjs +22 -26
- package/src/TableIndices.res +1 -2
- package/src/TableIndices.res.mjs +42 -48
- package/src/TestIndexer.res +196 -189
- package/src/TestIndexer.res.mjs +536 -536
- package/src/TestIndexerProxyStorage.res +15 -16
- package/src/TestIndexerProxyStorage.res.mjs +98 -122
- package/src/TestIndexerWorker.res +4 -0
- package/src/TestIndexerWorker.res.mjs +7 -0
- package/src/Throttler.res +3 -3
- package/src/Throttler.res.mjs +23 -24
- package/src/Time.res +1 -1
- package/src/Time.res.mjs +18 -21
- package/src/TopicFilter.res +3 -3
- package/src/TopicFilter.res.mjs +29 -30
- package/src/UserContext.res +93 -54
- package/src/UserContext.res.mjs +197 -182
- package/src/Utils.res +141 -86
- package/src/Utils.res.mjs +334 -295
- package/src/bindings/BigDecimal.res +0 -2
- package/src/bindings/BigDecimal.res.mjs +19 -23
- package/src/bindings/ClickHouse.res +28 -27
- package/src/bindings/ClickHouse.res.mjs +243 -240
- package/src/bindings/DateFns.res +11 -11
- package/src/bindings/DateFns.res.mjs +7 -7
- package/src/bindings/EventSource.res.mjs +2 -2
- package/src/bindings/Express.res +2 -5
- package/src/bindings/Hrtime.res +2 -2
- package/src/bindings/Hrtime.res.mjs +30 -32
- package/src/bindings/Lodash.res.mjs +1 -1
- package/src/bindings/NodeJs.res +14 -9
- package/src/bindings/NodeJs.res.mjs +20 -20
- package/src/bindings/Pino.res +8 -10
- package/src/bindings/Pino.res.mjs +40 -43
- package/src/bindings/Postgres.res +2 -5
- package/src/bindings/Postgres.res.mjs +9 -9
- package/src/bindings/PromClient.res +17 -2
- package/src/bindings/PromClient.res.mjs +30 -7
- package/src/bindings/SDSL.res.mjs +2 -2
- package/src/bindings/Viem.res +4 -4
- package/src/bindings/Viem.res.mjs +20 -22
- package/src/bindings/Vitest.res +1 -1
- package/src/bindings/Vitest.res.mjs +2 -2
- package/src/bindings/WebSocket.res +1 -1
- package/src/db/EntityHistory.res +9 -3
- package/src/db/EntityHistory.res.mjs +84 -59
- package/src/db/InternalTable.res +62 -60
- package/src/db/InternalTable.res.mjs +271 -203
- package/src/db/Schema.res +1 -2
- package/src/db/Schema.res.mjs +28 -32
- package/src/db/Table.res +28 -27
- package/src/db/Table.res.mjs +276 -292
- package/src/sources/EventRouter.res +21 -16
- package/src/sources/EventRouter.res.mjs +55 -57
- package/src/sources/Evm.res +17 -1
- package/src/sources/Evm.res.mjs +16 -8
- package/src/sources/EvmChain.res +15 -17
- package/src/sources/EvmChain.res.mjs +40 -42
- package/src/sources/Fuel.res +14 -1
- package/src/sources/Fuel.res.mjs +16 -8
- package/src/sources/FuelSDK.res +1 -1
- package/src/sources/FuelSDK.res.mjs +6 -8
- package/src/sources/HyperFuel.res +8 -10
- package/src/sources/HyperFuel.res.mjs +113 -123
- package/src/sources/HyperFuelClient.res.mjs +6 -7
- package/src/sources/HyperFuelSource.res +19 -20
- package/src/sources/HyperFuelSource.res.mjs +339 -356
- package/src/sources/HyperSync.res +11 -13
- package/src/sources/HyperSync.res.mjs +206 -220
- package/src/sources/HyperSyncClient.res +5 -7
- package/src/sources/HyperSyncClient.res.mjs +70 -75
- package/src/sources/HyperSyncHeightStream.res +8 -9
- package/src/sources/HyperSyncHeightStream.res.mjs +78 -86
- package/src/sources/HyperSyncJsonApi.res +18 -15
- package/src/sources/HyperSyncJsonApi.res.mjs +201 -231
- package/src/sources/HyperSyncSource.res +17 -21
- package/src/sources/HyperSyncSource.res.mjs +268 -290
- package/src/sources/Rpc.res +5 -5
- package/src/sources/Rpc.res.mjs +168 -192
- package/src/sources/RpcSource.res +166 -167
- package/src/sources/RpcSource.res.mjs +972 -1046
- package/src/sources/RpcWebSocketHeightStream.res +10 -11
- package/src/sources/RpcWebSocketHeightStream.res.mjs +131 -145
- package/src/sources/SimulateSource.res +1 -1
- package/src/sources/SimulateSource.res.mjs +35 -38
- package/src/sources/Source.res +1 -1
- package/src/sources/Source.res.mjs +3 -3
- package/src/sources/SourceManager.res +39 -20
- package/src/sources/SourceManager.res.mjs +340 -371
- package/src/sources/SourceManager.resi +2 -1
- package/src/sources/Svm.res +12 -5
- package/src/sources/Svm.res.mjs +44 -41
- package/src/tui/Tui.res +23 -12
- package/src/tui/Tui.res.mjs +292 -290
- package/src/tui/bindings/Ink.res +2 -4
- package/src/tui/bindings/Ink.res.mjs +35 -41
- package/src/tui/components/BufferedProgressBar.res +7 -7
- package/src/tui/components/BufferedProgressBar.res.mjs +46 -46
- package/src/tui/components/CustomHooks.res +1 -2
- package/src/tui/components/CustomHooks.res.mjs +102 -122
- package/src/tui/components/Messages.res +1 -2
- package/src/tui/components/Messages.res.mjs +38 -42
- package/src/tui/components/SyncETA.res +10 -11
- package/src/tui/components/SyncETA.res.mjs +178 -196
- package/src/tui/components/TuiData.res +1 -1
- package/src/tui/components/TuiData.res.mjs +7 -6
- package/src/vendored/Rest.res +52 -66
- package/src/vendored/Rest.res.mjs +324 -364
- package/svm.schema.json +67 -0
- package/src/Address.gen.ts +0 -8
- package/src/Config.gen.ts +0 -19
- package/src/Envio.gen.ts +0 -55
- package/src/EvmTypes.gen.ts +0 -6
- package/src/InMemoryStore.gen.ts +0 -6
- package/src/Internal.gen.ts +0 -64
- package/src/PgStorage.gen.ts +0 -10
- package/src/PgStorage.res.d.mts +0 -5
- package/src/Types.ts +0 -56
- package/src/bindings/BigDecimal.gen.ts +0 -14
- package/src/bindings/BigDecimal.res.d.mts +0 -5
- package/src/bindings/BigInt.gen.ts +0 -10
- package/src/bindings/BigInt.res +0 -70
- package/src/bindings/BigInt.res.d.mts +0 -5
- package/src/bindings/BigInt.res.mjs +0 -154
- package/src/bindings/Ethers.res.d.mts +0 -5
- package/src/bindings/Pino.gen.ts +0 -17
- package/src/bindings/Postgres.gen.ts +0 -8
- package/src/bindings/Postgres.res.d.mts +0 -5
- package/src/bindings/Promise.res +0 -67
- package/src/bindings/Promise.res.mjs +0 -26
- package/src/db/InternalTable.gen.ts +0 -36
- package/src/sources/HyperSyncClient.gen.ts +0 -19
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
open Belt
|
|
2
|
-
|
|
3
1
|
module Log = {
|
|
4
2
|
type t = {
|
|
5
3
|
address: Address.t,
|
|
@@ -43,7 +41,7 @@ let queryErrorToMsq = (e: queryError): string => {
|
|
|
43
41
|
switch e {
|
|
44
42
|
| UnexpectedMissingParams({queryName, missingParams}) =>
|
|
45
43
|
`${queryName} query failed due to unexpected missing params on response:
|
|
46
|
-
${missingParams->
|
|
44
|
+
${missingParams->Array.joinUnsafe(", ")}`
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
47
|
|
|
@@ -85,7 +83,7 @@ module GetLogs = {
|
|
|
85
83
|
for idx in 0 to fieldNames->Array.length - 1 {
|
|
86
84
|
let fieldName = fieldNames->Array.getUnsafe(idx)
|
|
87
85
|
switch returnedObj
|
|
88
|
-
->(Utils.magic: 'a =>
|
|
86
|
+
->(Utils.magic: 'a => dict<unknown>)
|
|
89
87
|
->Utils.Dict.dangerouslyGetNonOption(fieldName) {
|
|
90
88
|
| Some(_) => ()
|
|
91
89
|
| None => acc->Array.push(prefix ++ "." ++ fieldName)->ignore
|
|
@@ -110,12 +108,12 @@ module GetLogs = {
|
|
|
110
108
|
~prefix="transaction",
|
|
111
109
|
)
|
|
112
110
|
if missingParams->Array.length > 0 {
|
|
113
|
-
|
|
111
|
+
throw(Error(UnexpectedMissingParams({missingParams: missingParams})))
|
|
114
112
|
}
|
|
115
113
|
|
|
116
114
|
//Topics can be nullable and still need to be filtered
|
|
117
115
|
let logUnsanitized: Log.t = event.log->(Utils.magic: HyperSyncClient.ResponseTypes.log => Log.t)
|
|
118
|
-
let topics = event.log.topics->Option.getUnsafe->Array.
|
|
116
|
+
let topics = event.log.topics->Option.getUnsafe->Array.filterMap(Nullable.toOption)
|
|
119
117
|
let address = event.log.address->Option.getUnsafe
|
|
120
118
|
let log = {
|
|
121
119
|
...logUnsanitized,
|
|
@@ -149,7 +147,7 @@ module GetLogs = {
|
|
|
149
147
|
let page: logsQueryPage = {
|
|
150
148
|
items,
|
|
151
149
|
nextBlock,
|
|
152
|
-
archiveHeight: archiveHeight->Option.
|
|
150
|
+
archiveHeight: archiveHeight->Option.getOr(0), //Archive Height is only None if height is 0
|
|
153
151
|
events: res.data,
|
|
154
152
|
rollbackGuard,
|
|
155
153
|
}
|
|
@@ -187,7 +185,7 @@ module GetLogs = {
|
|
|
187
185
|
let res = await client.getEvents(~query)
|
|
188
186
|
if res.nextBlock <= fromBlock {
|
|
189
187
|
// Might happen when /height response was from another instance of HyperSync
|
|
190
|
-
|
|
188
|
+
throw(Error(WrongInstance))
|
|
191
189
|
}
|
|
192
190
|
|
|
193
191
|
res->convertResponse(~nonOptionalBlockFieldNames, ~nonOptionalTransactionFieldNames)
|
|
@@ -226,7 +224,7 @@ module BlockData = {
|
|
|
226
224
|
block.number->Utils.Option.mapNone("block.number"),
|
|
227
225
|
block.timestamp->Utils.Option.mapNone("block.timestamp"),
|
|
228
226
|
block.hash->Utils.Option.mapNone("block.hash"),
|
|
229
|
-
]->Array.
|
|
227
|
+
]->Array.filterMap(p => p)
|
|
230
228
|
|
|
231
229
|
Error(
|
|
232
230
|
UnexpectedMissingParams({
|
|
@@ -318,7 +316,7 @@ module BlockData = {
|
|
|
318
316
|
set->Utils.Set.add(blockNumber)->ignore
|
|
319
317
|
}
|
|
320
318
|
if toBlock.contents - fromBlock.contents > 1000 {
|
|
321
|
-
|
|
319
|
+
JsError.throwWithMessage(
|
|
322
320
|
`Invalid block data request. Range of block numbers is too large. Max range is 1000. Requested range: ${fromBlock.contents->Int.toString}-${toBlock.contents->Int.toString}`,
|
|
323
321
|
)
|
|
324
322
|
}
|
|
@@ -331,13 +329,13 @@ module BlockData = {
|
|
|
331
329
|
~logger,
|
|
332
330
|
)
|
|
333
331
|
let filtered = res->Result.map(datas => {
|
|
334
|
-
datas->Array.
|
|
332
|
+
datas->Array.filter(data => set->Utils.Set.delete(data.blockNumber))
|
|
335
333
|
})
|
|
336
334
|
if set->Utils.Set.size > 0 {
|
|
337
|
-
|
|
335
|
+
JsError.throwWithMessage(
|
|
338
336
|
`Invalid response. Failed to get block data for block numbers: ${set
|
|
339
337
|
->Utils.Set.toArray
|
|
340
|
-
->
|
|
338
|
+
->Array.joinUnsafe(", ")}`,
|
|
341
339
|
)
|
|
342
340
|
}
|
|
343
341
|
filtered
|
|
@@ -2,276 +2,270 @@
|
|
|
2
2
|
|
|
3
3
|
import * as Time from "../Time.res.mjs";
|
|
4
4
|
import * as Utils from "../Utils.res.mjs";
|
|
5
|
-
import * as Js_exn from "rescript/lib/es6/js_exn.js";
|
|
6
5
|
import * as Logging from "../Logging.res.mjs";
|
|
7
|
-
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
|
|
8
6
|
import * as Prometheus from "../Prometheus.res.mjs";
|
|
9
|
-
import * as
|
|
10
|
-
import * as
|
|
11
|
-
import * as
|
|
12
|
-
import * as
|
|
7
|
+
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
8
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
9
|
+
import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
|
|
10
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
13
11
|
import * as HyperSyncClient from "./HyperSyncClient.res.mjs";
|
|
12
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
13
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
let fieldNames = [
|
|
16
16
|
"address",
|
|
17
17
|
"data",
|
|
18
18
|
"topics",
|
|
19
19
|
"logIndex"
|
|
20
20
|
];
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
let HyperSyncQueryError = /* @__PURE__ */Primitive_exceptions.create("HyperSync.HyperSyncQueryError");
|
|
23
23
|
|
|
24
24
|
function queryErrorToMsq(e) {
|
|
25
|
-
|
|
26
|
-
return match.queryName +
|
|
25
|
+
let match = e._0;
|
|
26
|
+
return match.queryName + ` query failed due to unexpected missing params on response:
|
|
27
|
+
` + match.missingParams.join(", ");
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
function mapExn(queryResponse) {
|
|
30
31
|
if (queryResponse.TAG === "Ok") {
|
|
31
32
|
return {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
TAG: "Ok",
|
|
34
|
+
_0: queryResponse._0
|
|
35
|
+
};
|
|
35
36
|
} else {
|
|
36
37
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
TAG: "Error",
|
|
39
|
+
_0: {
|
|
40
|
+
RE_EXN_ID: HyperSyncQueryError,
|
|
41
|
+
_1: queryResponse._0
|
|
42
|
+
}
|
|
43
|
+
};
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
let $$Error = /* @__PURE__ */Primitive_exceptions.create("HyperSync.GetLogs.Error");
|
|
47
48
|
|
|
48
49
|
function makeRequestBody(fromBlock, toBlockInclusive, addressesWithTopics, fieldSelection) {
|
|
49
50
|
return {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
fromBlock: fromBlock,
|
|
52
|
+
toBlock: toBlockInclusive !== undefined ? toBlockInclusive + 1 | 0 : undefined,
|
|
53
|
+
logs: addressesWithTopics,
|
|
54
|
+
fieldSelection: fieldSelection
|
|
55
|
+
};
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
async function query(client, fromBlock, toBlock, logSelections, fieldSelection, nonOptionalBlockFieldNames, nonOptionalTransactionFieldNames) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
let addressesWithTopics = logSelections.flatMap(param => {
|
|
60
|
+
let addresses = param.addresses;
|
|
61
|
+
return param.topicSelections.map(param => {
|
|
62
|
+
let topics = HyperSyncClient.QueryTypes.makeTopicSelection(param.topic0, param.topic1, param.topic2, param.topic3);
|
|
63
|
+
return HyperSyncClient.QueryTypes.makeLogSelection(addresses, topics);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
let query$1 = makeRequestBody(fromBlock, toBlock, addressesWithTopics, fieldSelection);
|
|
67
|
+
let res = await client.getEvents(query$1);
|
|
67
68
|
if (res.nextBlock <= fromBlock) {
|
|
68
69
|
throw {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
RE_EXN_ID: $$Error,
|
|
71
|
+
_1: "WrongInstance",
|
|
72
|
+
Error: new Error()
|
|
73
|
+
};
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
missingParams.push("log");
|
|
90
|
-
}
|
|
75
|
+
let items = res.data.map(item => {
|
|
76
|
+
let missingParams = [];
|
|
77
|
+
let returnedObj = item.log;
|
|
78
|
+
if (Utils.$$Array.notEmpty(fieldNames)) {
|
|
79
|
+
if (returnedObj) {
|
|
80
|
+
for (let idx = 0, idx_finish = fieldNames.length; idx < idx_finish; ++idx) {
|
|
81
|
+
let fieldName = fieldNames[idx];
|
|
82
|
+
let match = returnedObj[fieldName];
|
|
83
|
+
if (match !== undefined) {
|
|
84
|
+
|
|
85
|
+
} else {
|
|
86
|
+
missingParams.push("log." + fieldName);
|
|
91
87
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
var returnedObj$2 = item.transaction;
|
|
109
|
-
if (Utils.$$Array.notEmpty(nonOptionalTransactionFieldNames)) {
|
|
110
|
-
if (returnedObj$2) {
|
|
111
|
-
for(var idx$2 = 0 ,idx_finish$2 = nonOptionalTransactionFieldNames.length; idx$2 < idx_finish$2; ++idx$2){
|
|
112
|
-
var fieldName$2 = nonOptionalTransactionFieldNames[idx$2];
|
|
113
|
-
var match$2 = returnedObj$2[fieldName$2];
|
|
114
|
-
if (match$2 !== undefined) {
|
|
115
|
-
|
|
116
|
-
} else {
|
|
117
|
-
missingParams.push("transaction." + fieldName$2);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} else {
|
|
121
|
-
missingParams.push("transaction");
|
|
122
|
-
}
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
missingParams.push("log");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
let returnedObj$1 = item.block;
|
|
94
|
+
if (Utils.$$Array.notEmpty(nonOptionalBlockFieldNames)) {
|
|
95
|
+
if (returnedObj$1) {
|
|
96
|
+
for (let idx$1 = 0, idx_finish$1 = nonOptionalBlockFieldNames.length; idx$1 < idx_finish$1; ++idx$1) {
|
|
97
|
+
let fieldName$1 = nonOptionalBlockFieldNames[idx$1];
|
|
98
|
+
let match$1 = returnedObj$1[fieldName$1];
|
|
99
|
+
if (match$1 !== undefined) {
|
|
100
|
+
|
|
101
|
+
} else {
|
|
102
|
+
missingParams.push("block." + fieldName$1);
|
|
123
103
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
missingParams.push("block");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
let returnedObj$2 = item.transaction;
|
|
110
|
+
if (Utils.$$Array.notEmpty(nonOptionalTransactionFieldNames)) {
|
|
111
|
+
if (returnedObj$2) {
|
|
112
|
+
for (let idx$2 = 0, idx_finish$2 = nonOptionalTransactionFieldNames.length; idx$2 < idx_finish$2; ++idx$2) {
|
|
113
|
+
let fieldName$2 = nonOptionalTransactionFieldNames[idx$2];
|
|
114
|
+
let match$2 = returnedObj$2[fieldName$2];
|
|
115
|
+
if (match$2 !== undefined) {
|
|
116
|
+
|
|
117
|
+
} else {
|
|
118
|
+
missingParams.push("transaction." + fieldName$2);
|
|
133
119
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
missingParams.push("transaction");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (missingParams.length !== 0) {
|
|
126
|
+
throw {
|
|
127
|
+
RE_EXN_ID: $$Error,
|
|
128
|
+
_1: {
|
|
129
|
+
TAG: "UnexpectedMissingParams",
|
|
130
|
+
missingParams: missingParams
|
|
131
|
+
},
|
|
132
|
+
Error: new Error()
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
let logUnsanitized = item.log;
|
|
136
|
+
let topics = Stdlib_Array.filterMap(item.log.topics, prim => {
|
|
137
|
+
if (prim == null) {
|
|
138
|
+
return;
|
|
139
|
+
} else {
|
|
140
|
+
return Primitive_option.some(prim);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
let address = item.log.address;
|
|
144
|
+
let log_data = logUnsanitized.data;
|
|
145
|
+
let log_logIndex = logUnsanitized.logIndex;
|
|
146
|
+
let log = {
|
|
147
|
+
address: address,
|
|
148
|
+
data: log_data,
|
|
149
|
+
topics: topics,
|
|
150
|
+
logIndex: log_logIndex
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
log: log,
|
|
154
|
+
block: item.block,
|
|
155
|
+
transaction: item.transaction
|
|
156
|
+
};
|
|
157
|
+
});
|
|
157
158
|
return {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
items: items,
|
|
160
|
+
nextBlock: res.nextBlock,
|
|
161
|
+
archiveHeight: Stdlib_Option.getOr(res.archiveHeight, 0),
|
|
162
|
+
rollbackGuard: res.rollbackGuard,
|
|
163
|
+
events: res.data
|
|
164
|
+
};
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
function makeRequestBody$1(fromBlock, toBlock) {
|
|
167
168
|
return {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
169
|
+
fromBlock: fromBlock,
|
|
170
|
+
toBlock: toBlock + 1 | 0,
|
|
171
|
+
fieldSelection: {
|
|
172
|
+
block: [
|
|
173
|
+
"Number",
|
|
174
|
+
"Hash",
|
|
175
|
+
"Timestamp"
|
|
176
|
+
]
|
|
177
|
+
},
|
|
178
|
+
includeAllBlocks: true
|
|
179
|
+
};
|
|
179
180
|
}
|
|
180
181
|
|
|
181
182
|
function convertResponse(res) {
|
|
182
|
-
return Utils.$$Array.transposeResults(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
})));
|
|
183
|
+
return Utils.$$Array.transposeResults(res.data.blocks.map(block => {
|
|
184
|
+
let blockNumber = block.number;
|
|
185
|
+
if (blockNumber !== undefined) {
|
|
186
|
+
let blockHash = block.hash;
|
|
187
|
+
if (blockHash !== undefined) {
|
|
188
|
+
let blockTimestamp = block.timestamp;
|
|
189
|
+
if (blockTimestamp !== undefined) {
|
|
190
|
+
return {
|
|
191
|
+
TAG: "Ok",
|
|
192
|
+
_0: {
|
|
193
|
+
blockHash: blockHash,
|
|
194
|
+
blockNumber: blockNumber,
|
|
195
|
+
blockTimestamp: blockTimestamp
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
let missingParams = Stdlib_Array.filterMap([
|
|
202
|
+
Utils.Option.mapNone(block.number, "block.number"),
|
|
203
|
+
Utils.Option.mapNone(block.timestamp, "block.timestamp"),
|
|
204
|
+
Utils.Option.mapNone(block.hash, "block.hash")
|
|
205
|
+
], p => p);
|
|
206
|
+
return {
|
|
207
|
+
TAG: "Error",
|
|
208
|
+
_0: {
|
|
209
|
+
TAG: "UnexpectedMissingParams",
|
|
210
|
+
_0: {
|
|
211
|
+
queryName: "query block data HyperSync",
|
|
212
|
+
missingParams: missingParams
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}));
|
|
220
217
|
}
|
|
221
218
|
|
|
222
219
|
async function queryBlockData(client, fromBlock, toBlock, sourceName, chainId, logger) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
220
|
+
let body = makeRequestBody$1(fromBlock, toBlock);
|
|
221
|
+
let logger$1 = Logging.createChildFrom(logger, {
|
|
222
|
+
logType: "HyperSync get block hash query",
|
|
223
|
+
fromBlock: fromBlock,
|
|
224
|
+
toBlock: toBlock
|
|
225
|
+
});
|
|
229
226
|
Prometheus.SourceRequestCount.increment(sourceName, chainId, "getBlockHashes");
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
227
|
+
let maybeSuccessfulRes;
|
|
228
|
+
let exit = 0;
|
|
229
|
+
let res;
|
|
233
230
|
try {
|
|
234
231
|
res = await client.get(body);
|
|
235
232
|
exit = 1;
|
|
236
|
-
}
|
|
237
|
-
catch (exn){
|
|
233
|
+
} catch (exn) {
|
|
238
234
|
maybeSuccessfulRes = undefined;
|
|
239
235
|
}
|
|
240
236
|
if (exit === 1) {
|
|
241
237
|
maybeSuccessfulRes = res.nextBlock <= fromBlock ? undefined : res;
|
|
242
238
|
}
|
|
243
239
|
if (maybeSuccessfulRes !== undefined) {
|
|
244
|
-
|
|
240
|
+
let err = convertResponse(maybeSuccessfulRes);
|
|
245
241
|
if (err.TAG !== "Ok") {
|
|
246
242
|
return err;
|
|
247
243
|
}
|
|
248
244
|
if (maybeSuccessfulRes.nextBlock > toBlock) {
|
|
249
245
|
return err;
|
|
250
246
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return
|
|
254
|
-
return Belt_Array.concat(datas, rest);
|
|
255
|
-
}));
|
|
247
|
+
let datas = err._0;
|
|
248
|
+
let restRes = await queryBlockData(client, maybeSuccessfulRes.nextBlock, toBlock, sourceName, chainId, logger$1);
|
|
249
|
+
return Stdlib_Result.map(restRes, rest => datas.concat(rest));
|
|
256
250
|
}
|
|
257
|
-
Logging.childInfo(logger$1,
|
|
251
|
+
Logging.childInfo(logger$1, `Block #` + fromBlock.toString() + ` not found in HyperSync. HyperSync has multiple instances and it's possible that they drift independently slightly from the head. Indexing should continue correctly after retrying the query in ` + (100).toString() + `ms.`);
|
|
258
252
|
await Time.resolvePromiseAfterDelay(100);
|
|
259
253
|
return await queryBlockData(client, fromBlock, toBlock, sourceName, chainId, logger$1);
|
|
260
254
|
}
|
|
261
255
|
|
|
262
256
|
async function queryBlockDataMulti(client, blockNumbers, sourceName, chainId, logger) {
|
|
263
|
-
|
|
257
|
+
let firstBlock = blockNumbers[0];
|
|
264
258
|
if (firstBlock === undefined) {
|
|
265
259
|
return {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
260
|
+
TAG: "Ok",
|
|
261
|
+
_0: []
|
|
262
|
+
};
|
|
269
263
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
for(
|
|
274
|
-
|
|
264
|
+
let fromBlock = firstBlock;
|
|
265
|
+
let toBlock = firstBlock;
|
|
266
|
+
let set = new Set();
|
|
267
|
+
for (let idx = 0, idx_finish = blockNumbers.length; idx < idx_finish; ++idx) {
|
|
268
|
+
let blockNumber = blockNumbers[idx];
|
|
275
269
|
if (blockNumber < fromBlock) {
|
|
276
270
|
fromBlock = blockNumber;
|
|
277
271
|
}
|
|
@@ -281,41 +275,33 @@ async function queryBlockDataMulti(client, blockNumbers, sourceName, chainId, lo
|
|
|
281
275
|
set.add(blockNumber);
|
|
282
276
|
}
|
|
283
277
|
if ((toBlock - fromBlock | 0) > 1000) {
|
|
284
|
-
|
|
278
|
+
Stdlib_JsError.throwWithMessage(`Invalid block data request. Range of block numbers is too large. Max range is 1000. Requested range: ` + fromBlock.toString() + `-` + toBlock.toString());
|
|
285
279
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return Belt_Array.keep(datas, (function (data) {
|
|
289
|
-
return set.delete(data.blockNumber);
|
|
290
|
-
}));
|
|
291
|
-
}));
|
|
280
|
+
let res = await queryBlockData(client, fromBlock, toBlock, sourceName, chainId, logger);
|
|
281
|
+
let filtered = Stdlib_Result.map(res, datas => datas.filter(data => set.delete(data.blockNumber)));
|
|
292
282
|
if (set.size > 0) {
|
|
293
|
-
|
|
283
|
+
Stdlib_JsError.throwWithMessage(`Invalid response. Failed to get block data for block numbers: ` + Array.from(set).join(", "));
|
|
294
284
|
}
|
|
295
285
|
return filtered;
|
|
296
286
|
}
|
|
297
287
|
|
|
298
288
|
function queryBlockData$1(client, blockNumber, sourceName, chainId, logger) {
|
|
299
|
-
return queryBlockData(client, blockNumber, blockNumber, sourceName, chainId, logger).then(
|
|
300
|
-
return Belt_Result.map(res, (function (res) {
|
|
301
|
-
return Belt_Array.get(res, 0);
|
|
302
|
-
}));
|
|
303
|
-
});
|
|
289
|
+
return queryBlockData(client, blockNumber, blockNumber, sourceName, chainId, logger).then(res => Stdlib_Result.map(res, res => res[0]));
|
|
304
290
|
}
|
|
305
291
|
|
|
306
|
-
|
|
292
|
+
let Log = {};
|
|
307
293
|
|
|
308
|
-
|
|
294
|
+
let GetLogs = {
|
|
309
295
|
$$Error: $$Error,
|
|
310
296
|
query: query
|
|
311
297
|
};
|
|
312
298
|
|
|
313
299
|
export {
|
|
314
|
-
Log
|
|
315
|
-
queryErrorToMsq
|
|
316
|
-
GetLogs
|
|
300
|
+
Log,
|
|
301
|
+
queryErrorToMsq,
|
|
302
|
+
GetLogs,
|
|
317
303
|
queryBlockData$1 as queryBlockData,
|
|
318
|
-
queryBlockDataMulti
|
|
319
|
-
mapExn
|
|
304
|
+
queryBlockDataMulti,
|
|
305
|
+
mapExn,
|
|
320
306
|
}
|
|
321
307
|
/* Time Not a pure module */
|
|
@@ -330,7 +330,6 @@ module ResponseTypes = {
|
|
|
330
330
|
mixHash?: string,
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
@genType
|
|
334
333
|
type accessList = {
|
|
335
334
|
address?: Address.t,
|
|
336
335
|
storageKeys?: array<string>,
|
|
@@ -341,7 +340,6 @@ module ResponseTypes = {
|
|
|
341
340
|
storageKeys: ?s.field("storageKeys", S.option(S.array(S.string))),
|
|
342
341
|
})
|
|
343
342
|
|
|
344
|
-
@genType
|
|
345
343
|
type authorizationList = {
|
|
346
344
|
chainId: bigint,
|
|
347
345
|
address: Address.t,
|
|
@@ -408,7 +406,7 @@ module ResponseTypes = {
|
|
|
408
406
|
blockNumber?: int,
|
|
409
407
|
address?: Address.t,
|
|
410
408
|
data?: string,
|
|
411
|
-
topics?: array<
|
|
409
|
+
topics?: array<Nullable.t<EvmTypes.Hex.t>>,
|
|
412
410
|
}
|
|
413
411
|
|
|
414
412
|
type event = {
|
|
@@ -585,10 +583,10 @@ module Decoder = {
|
|
|
585
583
|
type t = {
|
|
586
584
|
enableChecksummedAddresses: unit => unit,
|
|
587
585
|
disableChecksummedAddresses: unit => unit,
|
|
588
|
-
decodeLogs: array<log> => promise<array<
|
|
589
|
-
decodeLogsSync: array<log> => array<
|
|
590
|
-
decodeEvents: array<ResponseTypes.event> => promise<array<
|
|
591
|
-
decodeEventsSync: array<ResponseTypes.event> => array<
|
|
586
|
+
decodeLogs: array<log> => promise<array<Nullable.t<decodedEvent>>>,
|
|
587
|
+
decodeLogsSync: array<log> => array<Nullable.t<decodedEvent>>,
|
|
588
|
+
decodeEvents: array<ResponseTypes.event> => promise<array<Nullable.t<decodedEvent>>>,
|
|
589
|
+
decodeEventsSync: array<ResponseTypes.event> => array<Nullable.t<decodedEvent>>,
|
|
592
590
|
}
|
|
593
591
|
|
|
594
592
|
@module("@envio-dev/hypersync-client") @scope("Decoder")
|