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/Main.res.mjs
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
import * as Env from "./Env.res.mjs";
|
|
4
4
|
import * as Tui from "./tui/Tui.res.mjs";
|
|
5
|
-
import * as
|
|
5
|
+
import * as Core from "./Core.res.mjs";
|
|
6
|
+
import * as Envio from "./Envio.res.mjs";
|
|
6
7
|
import * as Utils from "./Utils.res.mjs";
|
|
7
|
-
import * as
|
|
8
|
+
import * as Config from "./Config.res.mjs";
|
|
8
9
|
import * as Logging from "./Logging.res.mjs";
|
|
9
10
|
import Express from "express";
|
|
10
11
|
import * as Process from "process";
|
|
11
12
|
import * as ChainMap from "./ChainMap.res.mjs";
|
|
12
|
-
import * as
|
|
13
|
+
import * as PgStorage from "./PgStorage.res.mjs";
|
|
13
14
|
import * as FetchState from "./FetchState.res.mjs";
|
|
14
15
|
import * as Prometheus from "./Prometheus.res.mjs";
|
|
15
|
-
import * as Belt_Option from "rescript/lib/es6/
|
|
16
|
-
import * as Caml_option from "rescript/lib/es6/caml_option.js";
|
|
16
|
+
import * as Belt_Option from "@rescript/runtime/lib/es6/Belt_Option.js";
|
|
17
17
|
import * as GlobalState from "./GlobalState.res.mjs";
|
|
18
18
|
import * as Persistence from "./Persistence.res.mjs";
|
|
19
19
|
import * as PromClient from "prom-client";
|
|
@@ -21,156 +21,392 @@ import Yargs from "yargs/yargs";
|
|
|
21
21
|
import * as ChainFetcher from "./ChainFetcher.res.mjs";
|
|
22
22
|
import * as ChainManager from "./ChainManager.res.mjs";
|
|
23
23
|
import * as HandlerLoader from "./HandlerLoader.res.mjs";
|
|
24
|
+
import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
|
|
24
25
|
import * as SourceManager from "./sources/SourceManager.res.mjs";
|
|
26
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
25
27
|
import * as Helpers from "yargs/helpers";
|
|
28
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
29
|
+
import * as HandlerRegister from "./HandlerRegister.res.mjs";
|
|
30
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
26
31
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
27
32
|
import * as GlobalStateManager from "./GlobalStateManager.res.mjs";
|
|
33
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
let chainDataSchema = S$RescriptSchema.schema(s => ({
|
|
36
|
+
chainId: s.m(S$RescriptSchema.float),
|
|
37
|
+
poweredByHyperSync: s.m(S$RescriptSchema.bool),
|
|
38
|
+
firstEventBlockNumber: s.m(S$RescriptSchema.option(S$RescriptSchema.int)),
|
|
39
|
+
latestProcessedBlock: s.m(S$RescriptSchema.option(S$RescriptSchema.int)),
|
|
40
|
+
timestampCaughtUpToHeadOrEndblock: s.m(S$RescriptSchema.option(S$RescriptSchema.datetime(S$RescriptSchema.string, undefined))),
|
|
41
|
+
numEventsProcessed: s.m(S$RescriptSchema.float),
|
|
42
|
+
latestFetchedBlockNumber: s.m(S$RescriptSchema.int),
|
|
43
|
+
currentBlockHeight: s.m(S$RescriptSchema.int),
|
|
44
|
+
numBatchesFetched: s.m(S$RescriptSchema.int),
|
|
45
|
+
startBlock: s.m(S$RescriptSchema.int),
|
|
46
|
+
endBlock: s.m(S$RescriptSchema.option(S$RescriptSchema.int)),
|
|
47
|
+
numAddresses: s.m(S$RescriptSchema.int)
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
let stateSchema = S$RescriptSchema.union([
|
|
51
|
+
S$RescriptSchema.literal({
|
|
52
|
+
status: "disabled"
|
|
53
|
+
}),
|
|
54
|
+
S$RescriptSchema.literal({
|
|
55
|
+
status: "initializing"
|
|
56
|
+
}),
|
|
57
|
+
S$RescriptSchema.schema(s => ({
|
|
58
|
+
status: "active",
|
|
59
|
+
envioVersion: s.m(S$RescriptSchema.string),
|
|
60
|
+
chains: s.m(S$RescriptSchema.array(chainDataSchema)),
|
|
61
|
+
indexerStartTime: s.m(S$RescriptSchema.datetime(S$RescriptSchema.string, undefined)),
|
|
62
|
+
isPreRegisteringDynamicContracts: false,
|
|
63
|
+
isUnorderedMultichainMode: s.m(S$RescriptSchema.bool),
|
|
64
|
+
rollbackOnReorg: s.m(S$RescriptSchema.bool)
|
|
65
|
+
}))
|
|
66
|
+
]);
|
|
45
67
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
chains: s.m(S$RescriptSchema.array(chainDataSchema)),
|
|
58
|
-
indexerStartTime: s.m(S$RescriptSchema.datetime(S$RescriptSchema.string, undefined)),
|
|
59
|
-
isPreRegisteringDynamicContracts: false,
|
|
60
|
-
isUnorderedMultichainMode: s.m(S$RescriptSchema.bool),
|
|
61
|
-
rollbackOnReorg: s.m(S$RescriptSchema.bool)
|
|
62
|
-
};
|
|
63
|
-
})
|
|
64
|
-
]);
|
|
68
|
+
let blockRangeSchema = S$RescriptSchema.strict(S$RescriptSchema.object(s => ({
|
|
69
|
+
_gte: s.f("_gte", S$RescriptSchema.option(S$RescriptSchema.int)),
|
|
70
|
+
_lte: s.f("_lte", S$RescriptSchema.option(S$RescriptSchema.int)),
|
|
71
|
+
_every: s.f("_every", S$RescriptSchema.Option.getOr(S$RescriptSchema.option(S$RescriptSchema.intMin(S$RescriptSchema.int, 1, undefined)), 1))
|
|
72
|
+
})));
|
|
73
|
+
|
|
74
|
+
let defaultBlockRange = {
|
|
75
|
+
_gte: undefined,
|
|
76
|
+
_lte: undefined,
|
|
77
|
+
_every: 1
|
|
78
|
+
};
|
|
65
79
|
|
|
66
|
-
|
|
80
|
+
let globalGsManagerRef = {
|
|
67
81
|
contents: undefined
|
|
68
82
|
};
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
let globalPersistenceRef = {
|
|
85
|
+
contents: undefined
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
function getInitialChainState(chainId) {
|
|
89
|
+
let persistence = globalPersistenceRef.contents;
|
|
90
|
+
if (persistence === undefined) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
let initialState = persistence.storageStatus;
|
|
94
|
+
if (typeof initialState !== "object" || initialState.TAG === "Initializing") {
|
|
95
|
+
return;
|
|
96
|
+
} else {
|
|
97
|
+
return initialState._0.chains.find(c => c.id === chainId);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function buildChainsObject(config) {
|
|
102
|
+
let chainIds = [];
|
|
103
|
+
let chains = Object.create(null);
|
|
104
|
+
ChainMap.values(config.chainMap).forEach(chainConfig => {
|
|
105
|
+
let chainIdStr = chainConfig.id.toString();
|
|
106
|
+
chainIds.push(chainConfig.id);
|
|
107
|
+
let chainObj = Object.create(null);
|
|
108
|
+
Object.defineProperty(Object.defineProperty(Object.defineProperty(Object.defineProperty(Object.defineProperty(chainObj, "id", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
value: chainConfig.id
|
|
111
|
+
}), "startBlock", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
get: () => {
|
|
114
|
+
let chainState = getInitialChainState(chainConfig.id);
|
|
115
|
+
if (chainState !== undefined) {
|
|
116
|
+
return chainState.startBlock;
|
|
117
|
+
} else {
|
|
118
|
+
return chainConfig.startBlock;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}), "endBlock", {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: () => {
|
|
124
|
+
let match = getInitialChainState(chainConfig.id);
|
|
125
|
+
if (match === undefined) {
|
|
126
|
+
return chainConfig.endBlock;
|
|
127
|
+
}
|
|
128
|
+
let eb = match.endBlock;
|
|
129
|
+
if (eb !== undefined) {
|
|
130
|
+
return eb;
|
|
131
|
+
} else {
|
|
132
|
+
return chainConfig.endBlock;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}), "name", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
value: chainConfig.name
|
|
138
|
+
}), "isLive", {
|
|
139
|
+
enumerable: true,
|
|
140
|
+
get: () => {
|
|
141
|
+
let gsManager = globalGsManagerRef.contents;
|
|
142
|
+
if (gsManager !== undefined) {
|
|
143
|
+
let state = GlobalStateManager.getState(Primitive_option.valFromOption(gsManager));
|
|
144
|
+
let chain = ChainMap.Chain.makeUnsafe(chainConfig.id);
|
|
145
|
+
return ChainFetcher.isReady(ChainMap.get(state.chainManager.chainFetchers, chain));
|
|
146
|
+
}
|
|
147
|
+
let chainState = getInitialChainState(chainConfig.id);
|
|
148
|
+
if (chainState !== undefined) {
|
|
149
|
+
return Stdlib_Option.isSome(chainState.timestampCaughtUpToHeadOrEndblock);
|
|
150
|
+
} else {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
chainConfig.contracts.forEach(contract => {
|
|
156
|
+
let contractObj = Object.create(null);
|
|
157
|
+
Object.defineProperty(Object.defineProperty(Object.defineProperty(contractObj, "name", {
|
|
76
158
|
enumerable: true,
|
|
77
|
-
value:
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
var chainIdStr = String(chainConfig.id);
|
|
83
|
-
chainIds.push(chainConfig.id);
|
|
84
|
-
var chainObj = Object.create(null);
|
|
85
|
-
Object.defineProperty(Object.defineProperty(Object.defineProperty(Object.defineProperty(Object.defineProperty(chainObj, "id", {
|
|
86
|
-
enumerable: true,
|
|
87
|
-
value: chainConfig.id
|
|
88
|
-
}), "startBlock", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
value: chainConfig.startBlock
|
|
91
|
-
}), "endBlock", {
|
|
92
|
-
enumerable: true,
|
|
93
|
-
value: chainConfig.endBlock
|
|
94
|
-
}), "name", {
|
|
95
|
-
enumerable: true,
|
|
96
|
-
value: chainConfig.name
|
|
97
|
-
}), "isLive", {
|
|
98
|
-
enumerable: true,
|
|
99
|
-
get: (function () {
|
|
100
|
-
var gsManager = globalGsManagerRef.contents;
|
|
101
|
-
if (gsManager === undefined) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
var state = GlobalStateManager.getState(Caml_option.valFromOption(gsManager));
|
|
105
|
-
var chain = ChainMap.Chain.makeUnsafe(chainConfig.id);
|
|
106
|
-
var chainFetcher = ChainMap.get(state.chainManager.chainFetchers, chain);
|
|
107
|
-
return ChainFetcher.isReady(chainFetcher);
|
|
108
|
-
})
|
|
109
|
-
});
|
|
110
|
-
Belt_Array.forEach(chainConfig.contracts, (function (contract) {
|
|
111
|
-
var contractObj = Object.create(null);
|
|
112
|
-
Object.defineProperty(Object.defineProperty(Object.defineProperty(contractObj, "name", {
|
|
113
|
-
enumerable: true,
|
|
114
|
-
value: contract.name
|
|
115
|
-
}), "abi", {
|
|
116
|
-
enumerable: true,
|
|
117
|
-
value: contract.abi
|
|
118
|
-
}), "addresses", {
|
|
119
|
-
enumerable: true,
|
|
120
|
-
get: (function () {
|
|
121
|
-
var gsManager = globalGsManagerRef.contents;
|
|
122
|
-
if (gsManager === undefined) {
|
|
123
|
-
return contract.addresses;
|
|
124
|
-
}
|
|
125
|
-
var state = GlobalStateManager.getState(Caml_option.valFromOption(gsManager));
|
|
126
|
-
var chain = ChainMap.Chain.makeUnsafe(chainConfig.id);
|
|
127
|
-
var chainFetcher = ChainMap.get(state.chainManager.chainFetchers, chain);
|
|
128
|
-
var indexingContracts = chainFetcher.fetchState.indexingContracts;
|
|
129
|
-
var addresses = [];
|
|
130
|
-
var values = Js_dict.values(indexingContracts);
|
|
131
|
-
for(var idx = 0 ,idx_finish = values.length; idx < idx_finish; ++idx){
|
|
132
|
-
var indexingContract = values[idx];
|
|
133
|
-
if (indexingContract.contractName === contract.name) {
|
|
134
|
-
addresses.push(indexingContract.address);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
return addresses;
|
|
139
|
-
})
|
|
140
|
-
});
|
|
141
|
-
Object.defineProperty(chainObj, contract.name, {
|
|
142
|
-
enumerable: true,
|
|
143
|
-
value: contractObj
|
|
144
|
-
});
|
|
145
|
-
}));
|
|
146
|
-
Object.defineProperty(chains, chainIdStr, {
|
|
147
|
-
enumerable: true,
|
|
148
|
-
value: chainObj
|
|
149
|
-
});
|
|
150
|
-
if (chainConfig.name !== chainIdStr) {
|
|
151
|
-
Object.defineProperty(chains, chainConfig.name, {
|
|
152
|
-
enumerable: false,
|
|
153
|
-
value: chainObj
|
|
154
|
-
});
|
|
155
|
-
return ;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
}));
|
|
159
|
-
Object.defineProperty(indexer, "chainIds", {
|
|
159
|
+
value: contract.name
|
|
160
|
+
}), "abi", {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
value: contract.abi
|
|
163
|
+
}), "addresses", {
|
|
160
164
|
enumerable: true,
|
|
161
|
-
|
|
165
|
+
get: () => {
|
|
166
|
+
let gsManager = globalGsManagerRef.contents;
|
|
167
|
+
if (gsManager !== undefined) {
|
|
168
|
+
let state = GlobalStateManager.getState(Primitive_option.valFromOption(gsManager));
|
|
169
|
+
let chain = ChainMap.Chain.makeUnsafe(chainConfig.id);
|
|
170
|
+
let chainFetcher = ChainMap.get(state.chainManager.chainFetchers, chain);
|
|
171
|
+
let indexingAddresses = chainFetcher.fetchState.indexingAddresses;
|
|
172
|
+
let addresses = [];
|
|
173
|
+
let values = Object.values(indexingAddresses);
|
|
174
|
+
for (let idx = 0, idx_finish = values.length; idx < idx_finish; ++idx) {
|
|
175
|
+
let indexingContract = values[idx];
|
|
176
|
+
if (indexingContract.contractName === contract.name) {
|
|
177
|
+
addresses.push(indexingContract.address);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return addresses;
|
|
181
|
+
}
|
|
182
|
+
let chainState = getInitialChainState(chainConfig.id);
|
|
183
|
+
if (chainState === undefined) {
|
|
184
|
+
return contract.addresses;
|
|
185
|
+
}
|
|
186
|
+
let addresses$1 = contract.addresses.slice();
|
|
187
|
+
chainState.indexingAddresses.forEach(dc => {
|
|
188
|
+
if (dc.contractName === contract.name) {
|
|
189
|
+
addresses$1.push(dc.address);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
return addresses$1;
|
|
194
|
+
}
|
|
162
195
|
});
|
|
163
|
-
|
|
196
|
+
Object.defineProperty(chainObj, contract.name, {
|
|
164
197
|
enumerable: true,
|
|
165
|
-
value:
|
|
198
|
+
value: contractObj
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
Object.defineProperty(chains, chainIdStr, {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
value: chainObj
|
|
204
|
+
});
|
|
205
|
+
if (chainConfig.name !== chainIdStr) {
|
|
206
|
+
Object.defineProperty(chains, chainConfig.name, {
|
|
207
|
+
enumerable: false,
|
|
208
|
+
value: chainObj
|
|
166
209
|
});
|
|
167
|
-
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
return [
|
|
214
|
+
chains,
|
|
215
|
+
chainIds
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function getGlobalIndexer() {
|
|
220
|
+
let parseIdentityConfig = identityConfig => {
|
|
221
|
+
let match;
|
|
222
|
+
if (typeof identityConfig.contract === "string") {
|
|
223
|
+
match = [
|
|
224
|
+
identityConfig.contract,
|
|
225
|
+
identityConfig.event
|
|
226
|
+
];
|
|
227
|
+
} else {
|
|
228
|
+
let event = identityConfig.event;
|
|
229
|
+
match = [
|
|
230
|
+
event.contract,
|
|
231
|
+
event._0
|
|
232
|
+
];
|
|
233
|
+
}
|
|
234
|
+
let wildcard = identityConfig.wildcard;
|
|
235
|
+
let where = identityConfig.where;
|
|
236
|
+
let eventOptions = wildcard !== undefined || where !== undefined ? ({
|
|
237
|
+
wildcard: wildcard,
|
|
238
|
+
where: where
|
|
239
|
+
}) : undefined;
|
|
240
|
+
return [
|
|
241
|
+
match[0],
|
|
242
|
+
match[1],
|
|
243
|
+
eventOptions
|
|
244
|
+
];
|
|
245
|
+
};
|
|
246
|
+
let onEventFn = (identityConfig, handler) => {
|
|
247
|
+
HandlerRegister.throwIfFinishedRegistration("onEvent");
|
|
248
|
+
let match = parseIdentityConfig(identityConfig);
|
|
249
|
+
HandlerRegister.setHandler(match[0], match[1], handler, match[2], undefined);
|
|
250
|
+
};
|
|
251
|
+
let contractRegisterFn = (identityConfig, handler) => {
|
|
252
|
+
HandlerRegister.throwIfFinishedRegistration("contractRegister");
|
|
253
|
+
let match = parseIdentityConfig(identityConfig);
|
|
254
|
+
HandlerRegister.setContractRegister(match[0], match[1], handler, match[2], undefined);
|
|
255
|
+
};
|
|
256
|
+
let extractRange = (filter, name, ecosystem) => {
|
|
257
|
+
try {
|
|
258
|
+
let inner = S$RescriptSchema.parseOrThrow(filter, ecosystem.onBlockFilterSchema);
|
|
259
|
+
if (inner !== undefined) {
|
|
260
|
+
return S$RescriptSchema.parseOrThrow(Primitive_option.valFromOption(inner), blockRangeSchema);
|
|
261
|
+
} else {
|
|
262
|
+
return defaultBlockRange;
|
|
263
|
+
}
|
|
264
|
+
} catch (raw_exn) {
|
|
265
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
266
|
+
if (exn.RE_EXN_ID === S$RescriptSchema.Raised) {
|
|
267
|
+
return Stdlib_JsError.throwWithMessage(`\`indexer.` + ecosystem.onBlockMethodName + `("` + name + `")\` \`where\` returned an invalid filter: ` + Utils.prettifyExn(exn._1));
|
|
268
|
+
}
|
|
269
|
+
throw exn;
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
let onBlockFn = (rawOptions, handler) => {
|
|
273
|
+
HandlerRegister.throwIfFinishedRegistration("onBlock");
|
|
274
|
+
let config = Config.loadWithoutRegistrations();
|
|
275
|
+
let ecosystem = config.ecosystem;
|
|
276
|
+
let match = buildChainsObject(config);
|
|
277
|
+
let chains = match[0];
|
|
278
|
+
let name = rawOptions.name;
|
|
279
|
+
let logger = Logging.createChild({
|
|
280
|
+
onBlock: name
|
|
281
|
+
});
|
|
282
|
+
let w = rawOptions.where;
|
|
283
|
+
let where = w === undefined || w === null ? undefined : (
|
|
284
|
+
typeof w === "function" ? rawOptions.where : Stdlib_JsError.throwWithMessage(`\`indexer.` + ecosystem.onBlockMethodName + `("` + name + `")\` expected \`where\` to be a function or omitted, but got ` + typeof w + `.`)
|
|
285
|
+
);
|
|
286
|
+
let matchedAny = {
|
|
287
|
+
contents: false
|
|
288
|
+
};
|
|
289
|
+
ChainMap.values(config.chainMap).forEach(chainConfig => {
|
|
290
|
+
let chainId = chainConfig.id;
|
|
291
|
+
let chainObj = chains[chainId.toString()];
|
|
292
|
+
let result = where !== undefined ? where({
|
|
293
|
+
chain: chainObj
|
|
294
|
+
}) : true;
|
|
295
|
+
let match = result === true ? [
|
|
296
|
+
true,
|
|
297
|
+
defaultBlockRange
|
|
298
|
+
] : (
|
|
299
|
+
result === false ? [
|
|
300
|
+
false,
|
|
301
|
+
defaultBlockRange
|
|
302
|
+
] : (
|
|
303
|
+
typeof result === "object" && !Array.isArray(result) && result !== null ? [
|
|
304
|
+
true,
|
|
305
|
+
extractRange(result, name, ecosystem)
|
|
306
|
+
] : Stdlib_JsError.throwWithMessage(`\`indexer.` + ecosystem.onBlockMethodName + `("` + name + `")\` \`where\` predicate returned an invalid value of type ` + typeof result + `. Expected boolean or a filter object.`)
|
|
307
|
+
)
|
|
308
|
+
);
|
|
309
|
+
if (!match[0]) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
let range = match[1];
|
|
313
|
+
matchedAny.contents = true;
|
|
314
|
+
HandlerRegister.registerOnBlock(name, chainId, range._every, range._gte, range._lte, handler);
|
|
315
|
+
});
|
|
316
|
+
if (!matchedAny.contents) {
|
|
317
|
+
return Logging.childWarn(logger, `\`indexer.` + ecosystem.onBlockMethodName + `\` matched 0 chains. Check the \`where\` predicate.`);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
let keysMemo = {
|
|
321
|
+
contents: undefined
|
|
322
|
+
};
|
|
323
|
+
let getKeys = () => {
|
|
324
|
+
let k = keysMemo.contents;
|
|
325
|
+
if (k !== undefined) {
|
|
326
|
+
return k;
|
|
327
|
+
}
|
|
328
|
+
let match = Config.loadWithoutRegistrations().ecosystem.name;
|
|
329
|
+
let keys;
|
|
330
|
+
let exit = 0;
|
|
331
|
+
switch (match) {
|
|
332
|
+
case "evm" :
|
|
333
|
+
case "fuel" :
|
|
334
|
+
exit = 1;
|
|
335
|
+
break;
|
|
336
|
+
case "svm" :
|
|
337
|
+
keys = [
|
|
338
|
+
"name",
|
|
339
|
+
"description",
|
|
340
|
+
"chainIds",
|
|
341
|
+
"chains",
|
|
342
|
+
"onSlot"
|
|
343
|
+
];
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
if (exit === 1) {
|
|
347
|
+
keys = [
|
|
348
|
+
"name",
|
|
349
|
+
"description",
|
|
350
|
+
"chainIds",
|
|
351
|
+
"chains",
|
|
352
|
+
"onEvent",
|
|
353
|
+
"contractRegister",
|
|
354
|
+
"onBlock"
|
|
355
|
+
];
|
|
356
|
+
}
|
|
357
|
+
keysMemo.contents = keys;
|
|
358
|
+
return keys;
|
|
359
|
+
};
|
|
360
|
+
let get = prop => {
|
|
361
|
+
switch (prop) {
|
|
362
|
+
case "chainIds" :
|
|
363
|
+
return buildChainsObject(Config.loadWithoutRegistrations())[1];
|
|
364
|
+
case "chains" :
|
|
365
|
+
return buildChainsObject(Config.loadWithoutRegistrations())[0];
|
|
366
|
+
case "contractRegister" :
|
|
367
|
+
return contractRegisterFn;
|
|
368
|
+
case "description" :
|
|
369
|
+
return Config.loadWithoutRegistrations().description;
|
|
370
|
+
case "name" :
|
|
371
|
+
return Config.loadWithoutRegistrations().name;
|
|
372
|
+
case "onEvent" :
|
|
373
|
+
return onEventFn;
|
|
374
|
+
case "onBlock" :
|
|
375
|
+
case "onSlot" :
|
|
376
|
+
return onBlockFn;
|
|
377
|
+
default:
|
|
378
|
+
return Stdlib_JsError.throwWithMessage(`Field \`` + prop + `\` does not exist on \`indexer\`. Available fields: ` + getKeys().join(", ") + `.`);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
let traps_get = (target, prop) => {
|
|
382
|
+
if (typeof prop === "string") {
|
|
383
|
+
return get(prop);
|
|
384
|
+
} else {
|
|
385
|
+
return target[prop];
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
let traps_ownKeys = param => getKeys();
|
|
389
|
+
let traps_getOwnPropertyDescriptor = (param, prop) => {
|
|
390
|
+
if (typeof prop === "string" && getKeys().includes(prop)) {
|
|
391
|
+
return {
|
|
392
|
+
value: get(prop),
|
|
393
|
+
enumerable: true,
|
|
394
|
+
configurable: true
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
let traps = {
|
|
399
|
+
get: traps_get,
|
|
400
|
+
ownKeys: traps_ownKeys,
|
|
401
|
+
getOwnPropertyDescriptor: traps_getOwnPropertyDescriptor
|
|
402
|
+
};
|
|
403
|
+
return new Proxy(Object.create(null), traps);
|
|
168
404
|
}
|
|
169
405
|
|
|
170
406
|
function startServer(getState, ctx, isDevelopmentMode) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
407
|
+
let app = Express();
|
|
408
|
+
let consoleCorsMiddleware = (req, res, next) => {
|
|
409
|
+
let origin = req.headers["origin"];
|
|
174
410
|
if (origin !== undefined && (origin === Env.prodEnvioAppUrl || origin === Env.envioAppUrl)) {
|
|
175
411
|
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
176
412
|
}
|
|
@@ -178,7 +414,7 @@ function startServer(getState, ctx, isDevelopmentMode) {
|
|
|
178
414
|
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
|
179
415
|
if (req.method === "OPTIONS") {
|
|
180
416
|
res.sendStatus(200);
|
|
181
|
-
return
|
|
417
|
+
return;
|
|
182
418
|
} else {
|
|
183
419
|
return next();
|
|
184
420
|
}
|
|
@@ -186,156 +422,177 @@ function startServer(getState, ctx, isDevelopmentMode) {
|
|
|
186
422
|
app.use("/console", consoleCorsMiddleware);
|
|
187
423
|
app.use("/metrics", consoleCorsMiddleware);
|
|
188
424
|
app.use("/metrics/runtime", consoleCorsMiddleware);
|
|
189
|
-
app.get("/healthz", (
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
app.get("/console/state", (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
});
|
|
196
|
-
res.json(S$RescriptSchema.reverseConvertToJsonOrThrow(state, stateSchema));
|
|
197
|
-
}));
|
|
198
|
-
app.post("/console/syncCache", (function (_req, res) {
|
|
199
|
-
if (isDevelopmentMode) {
|
|
200
|
-
Persistence.getInitializedStorageOrThrow(ctx.persistence).dumpEffectCache().then(function () {
|
|
201
|
-
res.json(true);
|
|
202
|
-
});
|
|
203
|
-
} else {
|
|
204
|
-
res.json(false);
|
|
205
|
-
}
|
|
206
|
-
}));
|
|
207
|
-
var runtimeRegistry = new PromClient.Registry();
|
|
208
|
-
PromClient.collectDefaultMetrics({
|
|
209
|
-
register: runtimeRegistry
|
|
425
|
+
app.get("/healthz", (_req, res) => {
|
|
426
|
+
res.sendStatus(200);
|
|
427
|
+
});
|
|
428
|
+
app.get("/console/state", (_req, res) => {
|
|
429
|
+
let state = isDevelopmentMode ? getState() : ({
|
|
430
|
+
status: "disabled"
|
|
210
431
|
});
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
432
|
+
res.json(S$RescriptSchema.reverseConvertToJsonOrThrow(state, stateSchema));
|
|
433
|
+
});
|
|
434
|
+
app.post("/console/syncCache", (_req, res) => {
|
|
435
|
+
if (isDevelopmentMode) {
|
|
436
|
+
Persistence.getInitializedStorageOrThrow(ctx.persistence).dumpEffectCache().then(() => {
|
|
437
|
+
res.json(true);
|
|
438
|
+
});
|
|
439
|
+
} else {
|
|
440
|
+
res.json(false);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
let runtimeRegistry = new PromClient.Registry();
|
|
444
|
+
PromClient.collectDefaultMetrics({
|
|
445
|
+
register: runtimeRegistry
|
|
446
|
+
});
|
|
447
|
+
app.get("/metrics", (_req, res) => {
|
|
448
|
+
res.set("Content-Type", PromClient.register.contentType);
|
|
449
|
+
PromClient.register.metrics().then(metrics => res.end(metrics));
|
|
450
|
+
});
|
|
451
|
+
app.get("/metrics/runtime", (_req, res) => {
|
|
452
|
+
res.set("Content-Type", runtimeRegistry.contentType);
|
|
453
|
+
runtimeRegistry.metrics().then(metrics => res.end(metrics));
|
|
454
|
+
});
|
|
455
|
+
let server = app.listen(Env.serverPort);
|
|
456
|
+
server.on("error", err => {
|
|
457
|
+
let code = err.code;
|
|
458
|
+
if (code === "EADDRINUSE") {
|
|
459
|
+
Logging.error(`Port ` + Env.serverPort.toString() + ` is already in use. To fix this either:` + (`\n 1. Kill the process using the port: lsof -ti :` + Env.serverPort.toString() + ` | xargs kill -9`) + `\n 2. Use a different port by setting the ENVIO_INDEXER_PORT environment variable: ENVIO_INDEXER_PORT=9899 envio start`);
|
|
460
|
+
} else {
|
|
461
|
+
Logging.errorWithExn(err, "Failed to start indexer server");
|
|
462
|
+
}
|
|
463
|
+
Process.exit(1);
|
|
464
|
+
});
|
|
233
465
|
}
|
|
234
466
|
|
|
235
|
-
async function
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
467
|
+
async function migrate(reset, persistedState) {
|
|
468
|
+
let config = Config.loadWithoutRegistrations();
|
|
469
|
+
let persistence = PgStorage.makePersistenceFromConfig(config, undefined);
|
|
470
|
+
await Persistence.init(persistence, ChainMap.values(config.chainMap), reset);
|
|
471
|
+
return await Core.upsertPersistedState(JSON.stringify(persistedState));
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
async function dropSchema() {
|
|
475
|
+
let config = Config.loadWithoutRegistrations();
|
|
476
|
+
let persistence = PgStorage.makePersistenceFromConfig(config, undefined);
|
|
477
|
+
return await persistence.storage.reset();
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
async function start(persistence, migrate, isTestOpt, exitAfterFirstEventBlockOpt, patchConfig) {
|
|
481
|
+
let isTest = isTestOpt !== undefined ? isTestOpt : false;
|
|
482
|
+
let exitAfterFirstEventBlock = exitAfterFirstEventBlockOpt !== undefined ? exitAfterFirstEventBlockOpt : false;
|
|
483
|
+
let mainArgs = Yargs(Helpers.hideBin(process.argv)).argv;
|
|
484
|
+
let shouldUseTui = !isTest && !Belt_Option.getWithDefault(mainArgs["tui-off"], Env.tuiOffEnvVar);
|
|
485
|
+
let isDevelopmentMode = !isTest && Envio.isDevMode();
|
|
486
|
+
let configWithoutRegistrations = Config.loadWithoutRegistrations();
|
|
487
|
+
let persistence$1 = persistence !== undefined ? persistence : PgStorage.makePersistenceFromConfig(configWithoutRegistrations, undefined);
|
|
488
|
+
globalPersistenceRef.contents = persistence$1;
|
|
489
|
+
let reset = Stdlib_Option.getOr(Stdlib_Option.map(migrate, m => m.reset), false);
|
|
490
|
+
await Persistence.init(persistence$1, ChainMap.values(configWithoutRegistrations.chainMap), reset);
|
|
491
|
+
if (migrate !== undefined) {
|
|
492
|
+
await Core.upsertPersistedState(JSON.stringify(migrate.persistedState));
|
|
493
|
+
}
|
|
494
|
+
let match = await HandlerLoader.registerAllHandlers(configWithoutRegistrations);
|
|
495
|
+
let registrations = match[1];
|
|
496
|
+
let config = match[0];
|
|
497
|
+
let config$1 = isTest ? ({
|
|
498
|
+
name: config.name,
|
|
499
|
+
description: config.description,
|
|
500
|
+
handlers: config.handlers,
|
|
501
|
+
contractHandlers: config.contractHandlers,
|
|
502
|
+
shouldRollbackOnReorg: false,
|
|
503
|
+
shouldSaveFullHistory: config.shouldSaveFullHistory,
|
|
504
|
+
storage: config.storage,
|
|
505
|
+
multichain: config.multichain,
|
|
506
|
+
chainMap: config.chainMap,
|
|
507
|
+
defaultChain: config.defaultChain,
|
|
508
|
+
ecosystem: config.ecosystem,
|
|
509
|
+
enableRawEvents: config.enableRawEvents,
|
|
510
|
+
maxAddrInPartition: config.maxAddrInPartition,
|
|
511
|
+
batchSize: config.batchSize,
|
|
512
|
+
lowercaseAddresses: config.lowercaseAddresses,
|
|
513
|
+
userEntitiesByName: config.userEntitiesByName,
|
|
514
|
+
userEntities: config.userEntities,
|
|
515
|
+
allEntities: config.allEntities,
|
|
516
|
+
allEnums: config.allEnums
|
|
517
|
+
}) : config;
|
|
518
|
+
let config$2 = patchConfig !== undefined ? patchConfig(config$1, registrations) : config$1;
|
|
519
|
+
let ctx = {
|
|
267
520
|
registrations: registrations,
|
|
268
521
|
config: config$2,
|
|
269
|
-
persistence: persistence
|
|
522
|
+
persistence: persistence$1
|
|
270
523
|
};
|
|
271
|
-
|
|
524
|
+
let envioVersion = Utils.EnvioPackage.value.version;
|
|
272
525
|
Prometheus.Info.set(envioVersion);
|
|
273
526
|
Prometheus.ProcessStartTimeSeconds.set();
|
|
274
527
|
Prometheus.RollbackEnabled.set(config$2.shouldRollbackOnReorg);
|
|
275
528
|
if (!isTest) {
|
|
276
|
-
startServer((
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
529
|
+
startServer(() => {
|
|
530
|
+
let gsManager = globalGsManagerRef.contents;
|
|
531
|
+
if (gsManager === undefined) {
|
|
532
|
+
return {
|
|
533
|
+
status: "initializing"
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
let state = GlobalStateManager.getState(Primitive_option.valFromOption(gsManager));
|
|
537
|
+
let chains = ChainMap.values(state.chainManager.chainFetchers).map(cf => {
|
|
538
|
+
let latestFetchedBlockNumber = Primitive_int.max(FetchState.bufferBlockNumber(cf.fetchState), 0);
|
|
539
|
+
let knownHeight = ChainFetcher.hasProcessedToEndblock(cf) ? Stdlib_Option.getOr(cf.fetchState.endBlock, cf.fetchState.knownHeight) : cf.fetchState.knownHeight;
|
|
540
|
+
return {
|
|
541
|
+
chainId: cf.chainConfig.id,
|
|
542
|
+
poweredByHyperSync: SourceManager.getActiveSource(cf.sourceManager).poweredByHyperSync,
|
|
543
|
+
firstEventBlockNumber: cf.fetchState.firstEventBlock,
|
|
544
|
+
latestProcessedBlock: cf.committedProgressBlockNumber === -1 ? undefined : cf.committedProgressBlockNumber,
|
|
545
|
+
timestampCaughtUpToHeadOrEndblock: cf.timestampCaughtUpToHeadOrEndblock,
|
|
546
|
+
numEventsProcessed: cf.numEventsProcessed,
|
|
547
|
+
latestFetchedBlockNumber: latestFetchedBlockNumber,
|
|
548
|
+
currentBlockHeight: knownHeight,
|
|
549
|
+
numBatchesFetched: 0,
|
|
550
|
+
startBlock: cf.fetchState.startBlock,
|
|
551
|
+
endBlock: cf.fetchState.endBlock,
|
|
552
|
+
numAddresses: FetchState.numAddresses(cf.fetchState)
|
|
553
|
+
};
|
|
554
|
+
});
|
|
555
|
+
let match = config$2.multichain;
|
|
556
|
+
let tmp;
|
|
557
|
+
tmp = match !== "ordered";
|
|
558
|
+
return {
|
|
559
|
+
status: "active",
|
|
560
|
+
envioVersion: envioVersion,
|
|
561
|
+
chains: chains,
|
|
562
|
+
indexerStartTime: state.indexerStartTime,
|
|
563
|
+
isPreRegisteringDynamicContracts: false,
|
|
564
|
+
isUnorderedMultichainMode: tmp,
|
|
565
|
+
rollbackOnReorg: config$2.shouldRollbackOnReorg
|
|
566
|
+
};
|
|
567
|
+
}, ctx, isDevelopmentMode);
|
|
315
568
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
var gsManager = GlobalStateManager.make(globalState, undefined);
|
|
569
|
+
let chainManager = ChainManager.makeFromDbState(Persistence.getInitializedState(persistence$1), config$2, registrations);
|
|
570
|
+
let globalState = GlobalState.make(ctx, chainManager, isDevelopmentMode, shouldUseTui, exitAfterFirstEventBlock);
|
|
571
|
+
let gsManager = GlobalStateManager.make(globalState, undefined);
|
|
320
572
|
if (shouldUseTui) {
|
|
321
|
-
Tui.start(
|
|
322
|
-
return GlobalStateManager.getState(gsManager);
|
|
323
|
-
});
|
|
573
|
+
Tui.start(() => GlobalStateManager.getState(gsManager));
|
|
324
574
|
}
|
|
325
|
-
globalGsManagerRef.contents =
|
|
575
|
+
globalGsManagerRef.contents = Primitive_option.some(gsManager);
|
|
326
576
|
GlobalStateManager.dispatchTask(gsManager, {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
577
|
+
TAG: "NextQuery",
|
|
578
|
+
_0: "CheckAllChains"
|
|
579
|
+
});
|
|
330
580
|
return GlobalStateManager.dispatchTask(gsManager, "ProcessEventBatch");
|
|
331
581
|
}
|
|
332
582
|
|
|
333
583
|
export {
|
|
334
|
-
chainDataSchema
|
|
335
|
-
stateSchema
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
584
|
+
chainDataSchema,
|
|
585
|
+
stateSchema,
|
|
586
|
+
blockRangeSchema,
|
|
587
|
+
defaultBlockRange,
|
|
588
|
+
globalGsManagerRef,
|
|
589
|
+
globalPersistenceRef,
|
|
590
|
+
getInitialChainState,
|
|
591
|
+
buildChainsObject,
|
|
592
|
+
getGlobalIndexer,
|
|
593
|
+
startServer,
|
|
594
|
+
migrate,
|
|
595
|
+
dropSchema,
|
|
596
|
+
start,
|
|
340
597
|
}
|
|
341
598
|
/* chainDataSchema Not a pure module */
|