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
package/src/Bin.res.mjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Core from "./Core.res.mjs";
|
|
4
|
+
import * as Main from "./Main.res.mjs";
|
|
5
|
+
import * as Utils from "./Utils.res.mjs";
|
|
6
|
+
import * as Config from "./Config.res.mjs";
|
|
7
|
+
import * as Logging from "./Logging.res.mjs";
|
|
8
|
+
import * as Process from "process";
|
|
9
|
+
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
10
|
+
import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
11
|
+
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
12
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
13
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
14
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
15
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
16
|
+
|
|
17
|
+
let setEnvVar = ((k, v) => { process.env[k] = v; });
|
|
18
|
+
|
|
19
|
+
process.on("unhandledRejection", reason => {
|
|
20
|
+
Logging.errorWithExn(Utils.prettifyExn(reason), "Unhandled promise rejection");
|
|
21
|
+
Process.exit(1);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function decodeCommand(json) {
|
|
25
|
+
let o = Stdlib_JSON.Decode.object(json);
|
|
26
|
+
let obj = o !== undefined ? o : Stdlib_JsError.throwWithMessage("Invalid command payload: not an object");
|
|
27
|
+
let k = Stdlib_Option.flatMap(obj["kind"], Stdlib_JSON.Decode.string);
|
|
28
|
+
let kind = k !== undefined ? k : Stdlib_JsError.throwWithMessage("Invalid command payload: missing kind");
|
|
29
|
+
switch (kind) {
|
|
30
|
+
case "drop-schema" :
|
|
31
|
+
return {
|
|
32
|
+
TAG: "DropSchema",
|
|
33
|
+
_0: json
|
|
34
|
+
};
|
|
35
|
+
case "migrate" :
|
|
36
|
+
return {
|
|
37
|
+
TAG: "Migrate",
|
|
38
|
+
_0: json
|
|
39
|
+
};
|
|
40
|
+
case "start" :
|
|
41
|
+
return {
|
|
42
|
+
TAG: "Start",
|
|
43
|
+
_0: json
|
|
44
|
+
};
|
|
45
|
+
default:
|
|
46
|
+
return Stdlib_JsError.throwWithMessage(`Unknown command kind: ` + kind);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function applyEnv(env) {
|
|
51
|
+
Stdlib_Dict.forEachWithKey(env, (value, key) => {
|
|
52
|
+
let v = Stdlib_JSON.Decode.string(value);
|
|
53
|
+
if (v !== undefined) {
|
|
54
|
+
return setEnvVar(key, v);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function run(args) {
|
|
60
|
+
try {
|
|
61
|
+
let json = await Core.runCli(args);
|
|
62
|
+
if (json === null) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
let match = decodeCommand(JSON.parse(json));
|
|
66
|
+
switch (match.TAG) {
|
|
67
|
+
case "Start" :
|
|
68
|
+
let match$1 = match._0;
|
|
69
|
+
Config.prime(match$1.config);
|
|
70
|
+
process.chdir(match$1.cwd);
|
|
71
|
+
applyEnv(match$1.env);
|
|
72
|
+
return await Main.start(undefined, Primitive_option.fromNull(match$1.migrate), undefined, undefined, undefined);
|
|
73
|
+
case "Migrate" :
|
|
74
|
+
let match$2 = match._0;
|
|
75
|
+
Config.prime(match$2.config);
|
|
76
|
+
return await Main.migrate(match$2.reset, match$2.persistedState);
|
|
77
|
+
case "DropSchema" :
|
|
78
|
+
Config.prime(match._0.config);
|
|
79
|
+
return await Main.dropSchema();
|
|
80
|
+
}
|
|
81
|
+
} catch (raw_exn) {
|
|
82
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
83
|
+
let e = Primitive_exceptions.internalToException(exn);
|
|
84
|
+
let message = e.RE_EXN_ID === "JsExn" ? Stdlib_Option.getOr(Stdlib_JsExn.message(e._1), "Failed at initialization") : "Failed at initialization";
|
|
85
|
+
Logging.error(message);
|
|
86
|
+
Process.exit(1);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
setEnvVar,
|
|
93
|
+
decodeCommand,
|
|
94
|
+
applyEnv,
|
|
95
|
+
run,
|
|
96
|
+
}
|
|
97
|
+
/* Not a pure module */
|
package/src/ChainFetcher.res
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
open Belt
|
|
2
|
-
|
|
3
1
|
//A filter should return true if the event should be kept and isValid should return
|
|
4
2
|
//false when the filter should be removed/cleaned up
|
|
5
3
|
type processingFilter = {
|
|
@@ -13,7 +11,7 @@ type t = {
|
|
|
13
11
|
sourceManager: SourceManager.t,
|
|
14
12
|
chainConfig: Config.chain,
|
|
15
13
|
isProgressAtHead: bool,
|
|
16
|
-
timestampCaughtUpToHeadOrEndblock: option<
|
|
14
|
+
timestampCaughtUpToHeadOrEndblock: option<Date.t>,
|
|
17
15
|
committedProgressBlockNumber: int,
|
|
18
16
|
numEventsProcessed: float,
|
|
19
17
|
reorgDetection: ReorgDetection.t,
|
|
@@ -21,9 +19,23 @@ type t = {
|
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
//CONSTRUCTION
|
|
22
|
+
let configAddresses = (chainConfig: Config.chain): array<Internal.indexingAddress> => {
|
|
23
|
+
let addresses = []
|
|
24
|
+
chainConfig.contracts->Array.forEach(contract => {
|
|
25
|
+
contract.addresses->Array.forEach(address => {
|
|
26
|
+
addresses->Array.push({
|
|
27
|
+
Internal.address,
|
|
28
|
+
contractName: contract.name,
|
|
29
|
+
registrationBlock: -1,
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
addresses
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
let make = (
|
|
25
37
|
~chainConfig: Config.chain,
|
|
26
|
-
~
|
|
38
|
+
~indexingAddresses: array<Internal.indexingAddress>,
|
|
27
39
|
~startBlock,
|
|
28
40
|
~endBlock,
|
|
29
41
|
~firstEventBlock=None,
|
|
@@ -46,7 +58,6 @@ let make = (
|
|
|
46
58
|
let eventRouter = EventRouter.empty()
|
|
47
59
|
|
|
48
60
|
// Aggregate events we want to fetch
|
|
49
|
-
let contracts = []
|
|
50
61
|
let eventConfigs: array<Internal.eventConfig> = []
|
|
51
62
|
|
|
52
63
|
let notRegisteredEvents = []
|
|
@@ -80,7 +91,8 @@ let make = (
|
|
|
80
91
|
isRegistered
|
|
81
92
|
}
|
|
82
93
|
|
|
83
|
-
// Check if event has Static([]) filters (from
|
|
94
|
+
// Check if event has Static([]) filters (from a dynamic where
|
|
95
|
+
// callback returning `false` / SkipAll for this chain).
|
|
84
96
|
// If so, skip it entirely - it should never be fetched
|
|
85
97
|
let shouldSkip = try {
|
|
86
98
|
let getEventFiltersOrThrow = (
|
|
@@ -111,27 +123,13 @@ let make = (
|
|
|
111
123
|
|
|
112
124
|
switch contract.startBlock {
|
|
113
125
|
| Some(startBlock) if startBlock < chainConfig.startBlock =>
|
|
114
|
-
|
|
126
|
+
JsError.throwWithMessage(
|
|
115
127
|
`The start block for contract "${contractName}" is less than the chain start block. This is not supported yet.`,
|
|
116
128
|
)
|
|
117
129
|
| _ => ()
|
|
118
130
|
}
|
|
119
|
-
|
|
120
|
-
contract.addresses->Array.forEach(address => {
|
|
121
|
-
contracts->Array.push({
|
|
122
|
-
Internal.address,
|
|
123
|
-
contractName: contract.name,
|
|
124
|
-
startBlock: switch contract.startBlock {
|
|
125
|
-
| Some(startBlock) => startBlock
|
|
126
|
-
| None => chainConfig.startBlock
|
|
127
|
-
},
|
|
128
|
-
registrationBlock: None,
|
|
129
|
-
})
|
|
130
|
-
})
|
|
131
131
|
})
|
|
132
132
|
|
|
133
|
-
dynamicContracts->Array.forEach(dc => contracts->Array.push(dc))
|
|
134
|
-
|
|
135
133
|
if notRegisteredEvents->Utils.Array.notEmpty {
|
|
136
134
|
logger->Logging.childInfo(
|
|
137
135
|
`The event${if notRegisteredEvents->Array.length > 1 {
|
|
@@ -140,7 +138,7 @@ let make = (
|
|
|
140
138
|
""
|
|
141
139
|
}} ${notRegisteredEvents
|
|
142
140
|
->Array.map(eventConfig => `${eventConfig.contractName}.${eventConfig.name}`)
|
|
143
|
-
->
|
|
141
|
+
->Array.joinUnsafe(", ")} don't have an event handler and skipped for indexing.`,
|
|
144
142
|
)
|
|
145
143
|
}
|
|
146
144
|
|
|
@@ -151,15 +149,15 @@ let make = (
|
|
|
151
149
|
// TODO: Move it to the HandlerRegister module
|
|
152
150
|
// so the error is thrown with better stack trace
|
|
153
151
|
onBlockConfigs->Array.forEach(onBlockConfig => {
|
|
154
|
-
if onBlockConfig.startBlock->Option.
|
|
155
|
-
|
|
152
|
+
if onBlockConfig.startBlock->Option.getOr(startBlock) < startBlock {
|
|
153
|
+
JsError.throwWithMessage(
|
|
156
154
|
`The start block for onBlock handler "${onBlockConfig.name}" is less than the chain start block (${startBlock->Belt.Int.toString}). This is not supported yet.`,
|
|
157
155
|
)
|
|
158
156
|
}
|
|
159
157
|
switch endBlock {
|
|
160
158
|
| Some(chainEndBlock) =>
|
|
161
|
-
if onBlockConfig.endBlock->Option.
|
|
162
|
-
|
|
159
|
+
if onBlockConfig.endBlock->Option.getOr(chainEndBlock) > chainEndBlock {
|
|
160
|
+
JsError.throwWithMessage(
|
|
163
161
|
`The end block for onBlock handler "${onBlockConfig.name}" is greater than the chain end block (${chainEndBlock->Belt.Int.toString}). This is not supported yet.`,
|
|
164
162
|
)
|
|
165
163
|
}
|
|
@@ -171,7 +169,7 @@ let make = (
|
|
|
171
169
|
|
|
172
170
|
let fetchState = FetchState.make(
|
|
173
171
|
~maxAddrInPartition=config.maxAddrInPartition,
|
|
174
|
-
~
|
|
172
|
+
~addresses=indexingAddresses,
|
|
175
173
|
~progressBlockNumber,
|
|
176
174
|
~startBlock,
|
|
177
175
|
~endBlock,
|
|
@@ -188,7 +186,7 @@ let make = (
|
|
|
188
186
|
~firstEventBlock,
|
|
189
187
|
)
|
|
190
188
|
|
|
191
|
-
let chainReorgCheckpoints = reorgCheckpoints->Array.
|
|
189
|
+
let chainReorgCheckpoints = reorgCheckpoints->Array.filterMap(reorgCheckpoint => {
|
|
192
190
|
if reorgCheckpoint.chainId === chainConfig.id {
|
|
193
191
|
Some(reorgCheckpoint)
|
|
194
192
|
} else {
|
|
@@ -287,7 +285,7 @@ let makeFromConfig = (
|
|
|
287
285
|
~numEventsProcessed=0.,
|
|
288
286
|
~targetBufferSize,
|
|
289
287
|
~logger,
|
|
290
|
-
~
|
|
288
|
+
~indexingAddresses=configAddresses(chainConfig),
|
|
291
289
|
~isInReorgThreshold=false,
|
|
292
290
|
~knownHeight,
|
|
293
291
|
)
|
|
@@ -296,7 +294,7 @@ let makeFromConfig = (
|
|
|
296
294
|
/**
|
|
297
295
|
* This function allows a chain fetcher to be created from metadata, in particular this is useful for restarting an indexer and making sure it fetches blocks from the same place.
|
|
298
296
|
*/
|
|
299
|
-
let makeFromDbState =
|
|
297
|
+
let makeFromDbState = (
|
|
300
298
|
chainConfig: Config.chain,
|
|
301
299
|
~resumedChainState: Persistence.initialChainState,
|
|
302
300
|
~reorgCheckpoints,
|
|
@@ -317,7 +315,7 @@ let makeFromDbState = async (
|
|
|
317
315
|
: resumedChainState.startBlock - 1
|
|
318
316
|
|
|
319
317
|
make(
|
|
320
|
-
~
|
|
318
|
+
~indexingAddresses=resumedChainState.indexingAddresses,
|
|
321
319
|
~chainConfig,
|
|
322
320
|
~startBlock=resumedChainState.startBlock,
|
|
323
321
|
~endBlock=resumedChainState.endBlock,
|
|
@@ -338,23 +336,8 @@ let makeFromDbState = async (
|
|
|
338
336
|
)
|
|
339
337
|
}
|
|
340
338
|
|
|
341
|
-
/**
|
|
342
|
-
* Helper function to get the configured start block for a contract from config
|
|
343
|
-
*/
|
|
344
|
-
let getContractStartBlock = (
|
|
345
|
-
config: Config.t,
|
|
346
|
-
~chain: ChainMap.Chain.t,
|
|
347
|
-
~contractName: string,
|
|
348
|
-
): option<int> => {
|
|
349
|
-
let chainConfig = config.chainMap->ChainMap.get(chain)
|
|
350
|
-
chainConfig.contracts
|
|
351
|
-
->Js.Array2.find(contract => contract.name === contractName)
|
|
352
|
-
->Option.flatMap(contract => contract.startBlock)
|
|
353
|
-
}
|
|
354
|
-
|
|
355
339
|
let runContractRegistersOrThrow = async (
|
|
356
340
|
~itemsWithContractRegister: array<Internal.item>,
|
|
357
|
-
~chain: ChainMap.Chain.t,
|
|
358
341
|
~config: Config.t,
|
|
359
342
|
) => {
|
|
360
343
|
let itemsWithDcs = []
|
|
@@ -363,17 +346,10 @@ let runContractRegistersOrThrow = async (
|
|
|
363
346
|
let eventItem = item->Internal.castUnsafeEventItem
|
|
364
347
|
let {blockNumber} = eventItem
|
|
365
348
|
|
|
366
|
-
|
|
367
|
-
let contractStartBlock = switch getContractStartBlock(config, ~chain, ~contractName) {
|
|
368
|
-
| Some(configuredStartBlock) => configuredStartBlock
|
|
369
|
-
| None => blockNumber
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
let dc: Internal.indexingContract = {
|
|
349
|
+
let dc: Internal.indexingAddress = {
|
|
373
350
|
address: contractAddress,
|
|
374
351
|
contractName,
|
|
375
|
-
|
|
376
|
-
registrationBlock: Some(blockNumber),
|
|
352
|
+
registrationBlock: blockNumber,
|
|
377
353
|
}
|
|
378
354
|
|
|
379
355
|
switch item->Internal.getItemDcs {
|
|
@@ -393,7 +369,7 @@ let runContractRegistersOrThrow = async (
|
|
|
393
369
|
| {eventConfig: {contractRegister: Some(contractRegister)}} => contractRegister
|
|
394
370
|
| {eventConfig: {contractRegister: None, name: eventName}} =>
|
|
395
371
|
// Unexpected case, since we should pass only events with contract register to this function
|
|
396
|
-
|
|
372
|
+
JsError.throwWithMessage("Contract register is not set for event " ++ eventName)
|
|
397
373
|
}
|
|
398
374
|
|
|
399
375
|
let errorMessage = "Event contractRegister failed, please fix the error to keep the indexer running smoothly"
|
|
@@ -410,7 +386,7 @@ let runContractRegistersOrThrow = async (
|
|
|
410
386
|
|
|
411
387
|
// Even though `contractRegister` always returns a promise,
|
|
412
388
|
// in the ReScript type, but it might return a non-promise value for TS API.
|
|
413
|
-
if result->Promise.isCatchable {
|
|
389
|
+
if result->Utils.Promise.isCatchable {
|
|
414
390
|
promises->Array.push(
|
|
415
391
|
result
|
|
416
392
|
->Promise.thenResolve(r => {
|