envio 3.0.0-alpha.21 → 3.0.0-alpha.23
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/README.md +3 -3
- 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 +430 -51
- package/src/Main.res.mjs +530 -271
- package/src/Persistence.res +80 -84
- package/src/Persistence.res.mjs +131 -132
- package/src/PgStorage.res +294 -167
- package/src/PgStorage.res.mjs +799 -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 +16 -16
- package/src/TestIndexerProxyStorage.res.mjs +99 -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 +7 -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/TestIndexer.res.mjs
CHANGED
|
@@ -5,348 +5,335 @@ import * as Main from "./Main.res.mjs";
|
|
|
5
5
|
import * as Table from "./db/Table.res.mjs";
|
|
6
6
|
import * as Utils from "./Utils.res.mjs";
|
|
7
7
|
import * as Config from "./Config.res.mjs";
|
|
8
|
-
import * as Js_exn from "rescript/lib/es6/js_exn.js";
|
|
9
|
-
import * as Js_dict from "rescript/lib/es6/js_dict.js";
|
|
10
8
|
import * as Logging from "./Logging.res.mjs";
|
|
11
|
-
import * as $$Promise from "./bindings/Promise.res.mjs";
|
|
12
9
|
import * as Process from "process";
|
|
13
|
-
import * as Belt_Int from "rescript/lib/es6/belt_Int.js";
|
|
14
10
|
import * as ChainMap from "./ChainMap.res.mjs";
|
|
15
|
-
import * as
|
|
16
|
-
import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
|
|
17
|
-
import * as Caml_option from "rescript/lib/es6/caml_option.js";
|
|
11
|
+
import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
|
|
18
12
|
import * as Persistence from "./Persistence.res.mjs";
|
|
13
|
+
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
19
14
|
import * as TableIndices from "./TableIndices.res.mjs";
|
|
20
15
|
import * as InternalTable from "./db/InternalTable.res.mjs";
|
|
16
|
+
import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
|
|
21
17
|
import * as SimulateItems from "./SimulateItems.res.mjs";
|
|
18
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
19
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
20
|
+
import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.js";
|
|
22
21
|
import * as Worker_threads from "worker_threads";
|
|
22
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
23
23
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
24
|
-
import * as
|
|
24
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
25
25
|
import * as TestIndexerProxyStorage from "./TestIndexerProxyStorage.res.mjs";
|
|
26
26
|
|
|
27
|
-
function
|
|
27
|
+
function toIndexingAddress(dc) {
|
|
28
28
|
return {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
29
|
+
address: Config.EnvioAddresses.getAddress(dc),
|
|
30
|
+
contractName: dc.contract_name,
|
|
31
|
+
registrationBlock: dc.registration_block
|
|
32
|
+
};
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
function handleLoadByIds(state, tableName, ids) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
let entityDict = Stdlib_Option.getOr(state.entities[tableName], {});
|
|
37
|
+
let entityConfig = state.entityConfigs[tableName];
|
|
38
|
+
let results = [];
|
|
39
|
+
ids.forEach(id => {
|
|
40
|
+
let entity = entityDict[id];
|
|
41
|
+
if (entity === undefined) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let jsonEntity = S$RescriptSchema.reverseConvertToJsonOrThrow(entity, entityConfig.schema);
|
|
45
|
+
results.push(jsonEntity);
|
|
46
|
+
});
|
|
48
47
|
return results;
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
function handleLoadByField(state, tableName, fieldName, fieldValue, operator) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
let entityDict = Stdlib_Option.getOr(state.entities[tableName], {});
|
|
52
|
+
let entityConfig = state.entityConfigs[tableName];
|
|
53
|
+
let results = [];
|
|
54
|
+
let match = Table.getFieldByName(entityConfig.table, fieldName);
|
|
55
|
+
let fieldSchema;
|
|
56
|
+
let exit = 0;
|
|
58
57
|
if (match !== undefined && match.TAG === "Field") {
|
|
59
58
|
fieldSchema = match._0.fieldSchema;
|
|
60
59
|
} else {
|
|
61
60
|
exit = 1;
|
|
62
61
|
}
|
|
63
62
|
if (exit === 1) {
|
|
64
|
-
fieldSchema =
|
|
63
|
+
fieldSchema = Stdlib_JsError.throwWithMessage(`Field ` + fieldName + ` not found in entity ` + tableName);
|
|
65
64
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
65
|
+
let parsedFieldValue = S$RescriptSchema.convertOrThrow(fieldValue, fieldSchema);
|
|
66
|
+
Object.values(entityDict).forEach(entity => {
|
|
67
|
+
let entityFieldValue = entity[fieldName];
|
|
68
|
+
if (entityFieldValue === undefined) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
let entityFieldValue$1 = Primitive_option.valFromOption(entityFieldValue);
|
|
72
|
+
let matches = operator === "=" ? TableIndices.FieldValue.eq(entityFieldValue$1, parsedFieldValue) : (
|
|
73
|
+
operator === ">" ? TableIndices.FieldValue.gt(entityFieldValue$1, parsedFieldValue) : TableIndices.FieldValue.lt(entityFieldValue$1, parsedFieldValue)
|
|
74
|
+
);
|
|
75
|
+
if (!matches) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
let jsonEntity = S$RescriptSchema.reverseConvertToJsonOrThrow(entity, entityConfig.schema);
|
|
79
|
+
results.push(jsonEntity);
|
|
80
|
+
});
|
|
82
81
|
return results;
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
function handleWriteBatch(state, updatedEntities, checkpointIds, checkpointChainIds, checkpointBlockNumbers, checkpointEventsProcessed) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
let changesByCheckpoint = {};
|
|
86
|
+
updatedEntities.forEach(param => {
|
|
87
|
+
let entityName = param.entityName;
|
|
88
|
+
let dict = state.entities[entityName];
|
|
89
|
+
let entityDict;
|
|
90
|
+
if (dict !== undefined) {
|
|
91
|
+
entityDict = dict;
|
|
92
|
+
} else {
|
|
93
|
+
let dict$1 = {};
|
|
94
|
+
state.entities[entityName] = dict$1;
|
|
95
|
+
entityDict = dict$1;
|
|
96
|
+
}
|
|
97
|
+
let entityConfig = state.entityConfigs[entityName];
|
|
98
|
+
param.updates.forEach(update => {
|
|
99
|
+
let processChange = change => {
|
|
100
|
+
if (change.type === "SET") {
|
|
101
|
+
let parsedEntity = S$RescriptSchema.parseOrThrow(change.entity, entityConfig.schema);
|
|
102
|
+
entityDict[change.entityId] = parsedEntity;
|
|
103
|
+
let checkpointKey = change.checkpointId.toString();
|
|
104
|
+
let changes = changesByCheckpoint[checkpointKey];
|
|
105
|
+
let entityChanges;
|
|
106
|
+
if (changes !== undefined) {
|
|
107
|
+
entityChanges = changes;
|
|
93
108
|
} else {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
109
|
+
let changes$1 = {};
|
|
110
|
+
changesByCheckpoint[checkpointKey] = changes$1;
|
|
111
|
+
entityChanges = changes$1;
|
|
97
112
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
};
|
|
154
|
-
entityChanges$1[entityName] = change$4;
|
|
155
|
-
entityChange$1 = change$4;
|
|
156
|
-
}
|
|
157
|
-
entityChange$1.deleted.push(entityId);
|
|
158
|
-
};
|
|
159
|
-
Belt_Array.forEach(update.history, processChange);
|
|
160
|
-
if (update.history.length === 0) {
|
|
161
|
-
return processChange(update.latestChange);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
}));
|
|
165
|
-
}));
|
|
166
|
-
for(var i = 0 ,i_finish = checkpointIds.length; i < i_finish; ++i){
|
|
167
|
-
var checkpointId = checkpointIds[i];
|
|
168
|
-
var change = {};
|
|
169
|
-
state.progressBlockByChain[String(checkpointChainIds[i])] = checkpointBlockNumbers[i];
|
|
113
|
+
let change$1 = entityChanges[entityName];
|
|
114
|
+
let entityChange;
|
|
115
|
+
if (change$1 !== undefined) {
|
|
116
|
+
entityChange = change$1;
|
|
117
|
+
} else {
|
|
118
|
+
let change_sets = [];
|
|
119
|
+
let change_deleted = [];
|
|
120
|
+
let change$2 = {
|
|
121
|
+
sets: change_sets,
|
|
122
|
+
deleted: change_deleted
|
|
123
|
+
};
|
|
124
|
+
entityChanges[entityName] = change$2;
|
|
125
|
+
entityChange = change$2;
|
|
126
|
+
}
|
|
127
|
+
entityChange.sets.push(parsedEntity);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
let entityId = change.entityId;
|
|
131
|
+
Stdlib_Dict.$$delete(entityDict, entityId);
|
|
132
|
+
let checkpointKey$1 = change.checkpointId.toString();
|
|
133
|
+
let changes$2 = changesByCheckpoint[checkpointKey$1];
|
|
134
|
+
let entityChanges$1;
|
|
135
|
+
if (changes$2 !== undefined) {
|
|
136
|
+
entityChanges$1 = changes$2;
|
|
137
|
+
} else {
|
|
138
|
+
let changes$3 = {};
|
|
139
|
+
changesByCheckpoint[checkpointKey$1] = changes$3;
|
|
140
|
+
entityChanges$1 = changes$3;
|
|
141
|
+
}
|
|
142
|
+
let change$3 = entityChanges$1[entityName];
|
|
143
|
+
let entityChange$1;
|
|
144
|
+
if (change$3 !== undefined) {
|
|
145
|
+
entityChange$1 = change$3;
|
|
146
|
+
} else {
|
|
147
|
+
let change_sets$1 = [];
|
|
148
|
+
let change_deleted$1 = [];
|
|
149
|
+
let change$4 = {
|
|
150
|
+
sets: change_sets$1,
|
|
151
|
+
deleted: change_deleted$1
|
|
152
|
+
};
|
|
153
|
+
entityChanges$1[entityName] = change$4;
|
|
154
|
+
entityChange$1 = change$4;
|
|
155
|
+
}
|
|
156
|
+
entityChange$1.deleted.push(entityId);
|
|
157
|
+
};
|
|
158
|
+
update.history.forEach(processChange);
|
|
159
|
+
if (update.history.length === 0) {
|
|
160
|
+
return processChange(update.latestChange);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
for (let i = 0, i_finish = checkpointIds.length; i < i_finish; ++i) {
|
|
165
|
+
let checkpointId = checkpointIds[i];
|
|
166
|
+
let change = {};
|
|
167
|
+
state.progressBlockByChain[checkpointChainIds[i].toString()] = checkpointBlockNumbers[i];
|
|
170
168
|
change["block"] = checkpointBlockNumbers[i];
|
|
171
169
|
change["chainId"] = checkpointChainIds[i];
|
|
172
170
|
change["eventsProcessed"] = checkpointEventsProcessed[i];
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
let checkpointKey = checkpointId.toString();
|
|
172
|
+
let entityChanges = changesByCheckpoint[checkpointKey];
|
|
175
173
|
if (entityChanges !== undefined) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
};
|
|
190
|
-
}));
|
|
191
|
-
entityObj["sets"] = simplifiedSets;
|
|
192
|
-
}
|
|
193
|
-
change["addresses"] = entityObj;
|
|
194
|
-
return ;
|
|
195
|
-
}
|
|
196
|
-
var entityObj$1 = {};
|
|
197
|
-
if (sets.length !== 0) {
|
|
198
|
-
entityObj$1["sets"] = sets;
|
|
199
|
-
}
|
|
200
|
-
if (deleted.length !== 0) {
|
|
201
|
-
entityObj$1["deleted"] = deleted;
|
|
202
|
-
}
|
|
203
|
-
change[entityName] = entityObj$1;
|
|
174
|
+
Object.entries(entityChanges).forEach(param => {
|
|
175
|
+
let match = param[1];
|
|
176
|
+
let deleted = match.deleted;
|
|
177
|
+
let sets = match.sets;
|
|
178
|
+
let entityName = param[0];
|
|
179
|
+
if (entityName === Config.EnvioAddresses.name) {
|
|
180
|
+
let entityObj = {};
|
|
181
|
+
if (sets.length !== 0) {
|
|
182
|
+
let simplifiedSets = sets.map(entity => ({
|
|
183
|
+
address: Config.EnvioAddresses.getAddress(entity),
|
|
184
|
+
contract: entity.contract_name
|
|
185
|
+
}));
|
|
186
|
+
entityObj["sets"] = simplifiedSets;
|
|
204
187
|
}
|
|
205
|
-
|
|
188
|
+
change["addresses"] = entityObj;
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
let entityObj$1 = {};
|
|
192
|
+
if (sets.length !== 0) {
|
|
193
|
+
entityObj$1["sets"] = sets;
|
|
194
|
+
}
|
|
195
|
+
if (deleted.length !== 0) {
|
|
196
|
+
entityObj$1["deleted"] = deleted;
|
|
197
|
+
}
|
|
198
|
+
change[entityName] = entityObj$1;
|
|
199
|
+
});
|
|
206
200
|
}
|
|
207
201
|
state.processChanges.push(change);
|
|
208
202
|
}
|
|
209
203
|
}
|
|
210
204
|
|
|
211
|
-
function makeInitialState(config, processConfigChains,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
205
|
+
function makeInitialState(config, processConfigChains, indexingAddressesByChain) {
|
|
206
|
+
let chainKeys = Object.keys(processConfigChains);
|
|
207
|
+
let chains = chainKeys.map(chainIdStr => {
|
|
208
|
+
let chainId = Stdlib_Option.getOr(Stdlib_Int.fromString(chainIdStr, undefined), 0);
|
|
209
|
+
let chain = ChainMap.Chain.makeUnsafe(chainId);
|
|
210
|
+
if (!ChainMap.has(config.chainMap, chain)) {
|
|
211
|
+
Stdlib_JsError.throwWithMessage(`Chain ` + chainIdStr + ` is not configured in config.yaml`);
|
|
212
|
+
}
|
|
213
|
+
let processChainConfig = processConfigChains[chainIdStr];
|
|
214
|
+
let indexingAddresses = Stdlib_Option.getOr(indexingAddressesByChain[chainIdStr], []);
|
|
215
|
+
return {
|
|
216
|
+
id: chainId,
|
|
217
|
+
startBlock: processChainConfig.startBlock,
|
|
218
|
+
endBlock: processChainConfig.endBlock,
|
|
219
|
+
maxReorgDepth: 0,
|
|
220
|
+
progressBlockNumber: -1,
|
|
221
|
+
numEventsProcessed: 0,
|
|
222
|
+
firstEventBlockNumber: undefined,
|
|
223
|
+
timestampCaughtUpToHeadOrEndblock: undefined,
|
|
224
|
+
indexingAddresses: indexingAddresses,
|
|
225
|
+
sourceBlockNumber: Stdlib_Option.getOr(processChainConfig.endBlock, 0)
|
|
226
|
+
};
|
|
227
|
+
});
|
|
234
228
|
return {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
229
|
+
cleanRun: true,
|
|
230
|
+
cache: {},
|
|
231
|
+
chains: chains,
|
|
232
|
+
checkpointId: InternalTable.Checkpoints.initialCheckpointId,
|
|
233
|
+
reorgCheckpoints: []
|
|
234
|
+
};
|
|
241
235
|
}
|
|
242
236
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
};
|
|
249
|
-
});
|
|
237
|
+
let rawChainConfigSchema = S$RescriptSchema.schema(s => ({
|
|
238
|
+
startBlock: s.m(S$RescriptSchema.option(S$RescriptSchema.int)),
|
|
239
|
+
endBlock: s.m(S$RescriptSchema.option(S$RescriptSchema.int)),
|
|
240
|
+
simulate: s.m(S$RescriptSchema.option(S$RescriptSchema.array(S$RescriptSchema.json(false))))
|
|
241
|
+
}));
|
|
250
242
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
};
|
|
255
|
-
});
|
|
243
|
+
let processConfigSchema = S$RescriptSchema.schema(s => ({
|
|
244
|
+
chains: s.m(S$RescriptSchema.dict(rawChainConfigSchema))
|
|
245
|
+
}));
|
|
256
246
|
|
|
257
247
|
function getSimulateEndBlock(simulateItems, config, startBlock) {
|
|
258
|
-
|
|
248
|
+
let maxBlock = {
|
|
259
249
|
contents: startBlock
|
|
260
250
|
};
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}));
|
|
251
|
+
simulateItems.forEach(rawJson => {
|
|
252
|
+
let blockJson = rawJson.block;
|
|
253
|
+
if (blockJson == null) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
let n = Stdlib_Option.flatMap(blockJson[config.ecosystem.blockNumberName], v => {
|
|
257
|
+
if (v == null) {
|
|
258
|
+
return;
|
|
259
|
+
} else {
|
|
260
|
+
return Primitive_option.some(v);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
if (n !== undefined && n > maxBlock.contents) {
|
|
264
|
+
maxBlock.contents = n;
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
279
268
|
return maxBlock.contents;
|
|
280
269
|
}
|
|
281
270
|
|
|
282
271
|
function parseBlockRange(chainIdStr, config, rawChainConfig, progressBlock) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
272
|
+
let id = Stdlib_Int.fromString(chainIdStr, undefined);
|
|
273
|
+
let chainId = id !== undefined ? id : Stdlib_JsError.throwWithMessage(`Invalid chain ID "` + chainIdStr + `": expected a numeric chain ID`);
|
|
274
|
+
let chain = ChainMap.Chain.makeUnsafe(chainId);
|
|
286
275
|
if (!ChainMap.has(config.chainMap, chain)) {
|
|
287
|
-
|
|
276
|
+
Stdlib_JsError.throwWithMessage(`Chain ` + chainIdStr + ` is not configured in config.yaml`);
|
|
288
277
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
278
|
+
let configChain = ChainMap.get(config.chainMap, chain);
|
|
279
|
+
let sb = rawChainConfig.startBlock;
|
|
280
|
+
let startBlock = sb !== undefined ? sb : (
|
|
292
281
|
progressBlock !== undefined ? progressBlock + 1 | 0 : configChain.startBlock
|
|
293
282
|
);
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
283
|
+
let eb = rawChainConfig.endBlock;
|
|
284
|
+
let endBlock = eb !== undefined ? eb : (
|
|
285
|
+
Stdlib_Option.isSome(rawChainConfig.simulate) ? getSimulateEndBlock(Stdlib_Option.getOrThrow(rawChainConfig.simulate, undefined), config, startBlock) : undefined
|
|
297
286
|
);
|
|
298
287
|
if (startBlock < configChain.startBlock) {
|
|
299
|
-
|
|
288
|
+
Stdlib_JsError.throwWithMessage(`Invalid block range for chain ` + chainIdStr + `: startBlock (` + startBlock.toString() + `) is less than config.startBlock (` + configChain.startBlock.toString() + `). ` + (`Either use startBlock >= ` + configChain.startBlock.toString() + ` or create a new test indexer with createTestIndexer().`));
|
|
300
289
|
}
|
|
301
|
-
|
|
290
|
+
let match = configChain.endBlock;
|
|
302
291
|
if (endBlock !== undefined && match !== undefined && endBlock > match) {
|
|
303
|
-
|
|
292
|
+
Stdlib_JsError.throwWithMessage(`Invalid block range for chain ` + chainIdStr + `: endBlock (` + endBlock.toString() + `) exceeds config.endBlock (` + match.toString() + `). ` + (`Either use endBlock <= ` + match.toString() + ` or create a new test indexer with createTestIndexer().`));
|
|
304
293
|
}
|
|
305
294
|
if (progressBlock !== undefined && startBlock <= progressBlock) {
|
|
306
|
-
|
|
295
|
+
Stdlib_JsError.throwWithMessage(`Invalid block range for chain ` + chainIdStr + `: startBlock (` + startBlock.toString() + `) must be greater than previously processed endBlock (` + progressBlock.toString() + `). ` + (`Either use startBlock > ` + progressBlock.toString() + ` or create a new test indexer with createTestIndexer().`));
|
|
307
296
|
}
|
|
308
297
|
return {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
298
|
+
startBlock: startBlock,
|
|
299
|
+
endBlock: endBlock
|
|
300
|
+
};
|
|
312
301
|
}
|
|
313
302
|
|
|
314
303
|
function getEntityFromState(state, entityConfig, entityId, methodName) {
|
|
315
304
|
if (state.processInProgress) {
|
|
316
|
-
|
|
305
|
+
Stdlib_JsError.throwWithMessage(`Cannot call ` + entityConfig.name + `.` + methodName + `() while indexer.process() is running. ` + "Wait for process() to complete before accessing entities directly.");
|
|
317
306
|
}
|
|
318
|
-
|
|
319
|
-
return
|
|
307
|
+
let entityDict = Stdlib_Option.getOr(state.entities[entityConfig.name], {});
|
|
308
|
+
return entityDict[entityId];
|
|
320
309
|
}
|
|
321
310
|
|
|
322
311
|
function makeEntityGet(state, entityConfig) {
|
|
323
|
-
return
|
|
324
|
-
return Promise.resolve(getEntityFromState(state, entityConfig, entityId, "get"));
|
|
325
|
-
};
|
|
312
|
+
return entityId => Promise.resolve(getEntityFromState(state, entityConfig, entityId, "get"));
|
|
326
313
|
}
|
|
327
314
|
|
|
328
315
|
function makeEntityGetOrThrow(state, entityConfig) {
|
|
329
|
-
return
|
|
330
|
-
|
|
316
|
+
return (entityId, message) => {
|
|
317
|
+
let entity = getEntityFromState(state, entityConfig, entityId, "getOrThrow");
|
|
331
318
|
if (entity !== undefined) {
|
|
332
319
|
return Promise.resolve(entity);
|
|
333
320
|
} else {
|
|
334
|
-
return
|
|
321
|
+
return Stdlib_JsError.throwWithMessage(message !== undefined ? message : `Entity ` + entityConfig.name + ` with id ` + entityId + ` not found`);
|
|
335
322
|
}
|
|
336
323
|
};
|
|
337
324
|
}
|
|
338
325
|
|
|
339
326
|
function makeEntitySet(state, entityConfig) {
|
|
340
|
-
return
|
|
327
|
+
return entity => {
|
|
341
328
|
if (state.processInProgress) {
|
|
342
|
-
|
|
329
|
+
Stdlib_JsError.throwWithMessage(`Cannot call ` + entityConfig.name + `.set() while indexer.process() is running. ` + "Wait for process() to complete before modifying entities directly.");
|
|
343
330
|
}
|
|
344
|
-
|
|
345
|
-
|
|
331
|
+
let dict = state.entities[entityConfig.name];
|
|
332
|
+
let entityDict;
|
|
346
333
|
if (dict !== undefined) {
|
|
347
334
|
entityDict = dict;
|
|
348
335
|
} else {
|
|
349
|
-
|
|
336
|
+
let dict$1 = {};
|
|
350
337
|
state.entities[entityConfig.name] = dict$1;
|
|
351
338
|
entityDict = dict$1;
|
|
352
339
|
}
|
|
@@ -355,276 +342,289 @@ function makeEntitySet(state, entityConfig) {
|
|
|
355
342
|
}
|
|
356
343
|
|
|
357
344
|
function makeEntityGetAll(state, entityConfig) {
|
|
358
|
-
return
|
|
345
|
+
return () => {
|
|
359
346
|
if (state.processInProgress) {
|
|
360
|
-
|
|
347
|
+
Stdlib_JsError.throwWithMessage(`Cannot call ` + entityConfig.name + `.getAll() while indexer.process() is running. ` + "Wait for process() to complete before accessing entities directly.");
|
|
361
348
|
}
|
|
362
|
-
|
|
363
|
-
return Promise.resolve(
|
|
349
|
+
let entityDict = Stdlib_Option.getOr(state.entities[entityConfig.name], {});
|
|
350
|
+
return Promise.resolve(Object.values(entityDict));
|
|
364
351
|
};
|
|
365
352
|
}
|
|
366
353
|
|
|
367
|
-
function makeCreateTestIndexer(config, workerPath
|
|
368
|
-
return
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
354
|
+
function makeCreateTestIndexer(config, workerPath) {
|
|
355
|
+
return () => {
|
|
356
|
+
let allEntities = config.allEntities;
|
|
357
|
+
let entities = {};
|
|
358
|
+
let entityConfigs = {};
|
|
359
|
+
allEntities.forEach(entityConfig => {
|
|
360
|
+
entities[entityConfig.name] = {};
|
|
361
|
+
entityConfigs[entityConfig.name] = entityConfig;
|
|
362
|
+
});
|
|
363
|
+
let envioAddressesDict = entities[Config.EnvioAddresses.name];
|
|
364
|
+
ChainMap.values(config.chainMap).forEach(chainConfig => {
|
|
365
|
+
chainConfig.contracts.forEach(contract => {
|
|
366
|
+
contract.addresses.forEach(address => {
|
|
367
|
+
let entity_id = Config.EnvioAddresses.makeId(chainConfig.id, address);
|
|
368
|
+
let entity_chain_id = chainConfig.id;
|
|
369
|
+
let entity_contract_name = contract.name;
|
|
370
|
+
let entity = {
|
|
371
|
+
id: entity_id,
|
|
372
|
+
chain_id: entity_chain_id,
|
|
373
|
+
registration_block: -1,
|
|
374
|
+
registration_log_index: -1,
|
|
375
|
+
contract_name: entity_contract_name
|
|
376
|
+
};
|
|
377
|
+
envioAddressesDict[entity_id] = entity;
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
let state = {
|
|
376
382
|
processInProgress: false,
|
|
377
383
|
progressBlockByChain: {},
|
|
378
384
|
entities: entities,
|
|
379
385
|
entityConfigs: entityConfigs,
|
|
380
386
|
processChanges: []
|
|
381
387
|
};
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
388
|
+
let entityOpsDict = {};
|
|
389
|
+
allEntities.forEach(entityConfig => {
|
|
390
|
+
if (entityConfig.name !== Config.EnvioAddresses.name) {
|
|
391
|
+
entityOpsDict[entityConfig.name] = {
|
|
392
|
+
get: makeEntityGet(state, entityConfig),
|
|
393
|
+
getAll: makeEntityGetAll(state, entityConfig),
|
|
394
|
+
getOrThrow: makeEntityGetOrThrow(state, entityConfig),
|
|
395
|
+
set: makeEntitySet(state, entityConfig)
|
|
396
|
+
};
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
let chainIds = [];
|
|
401
|
+
let chains = Object.create(null);
|
|
402
|
+
ChainMap.values(config.chainMap).forEach(chainConfig => {
|
|
403
|
+
let chainIdStr = chainConfig.id.toString();
|
|
404
|
+
chainIds.push(chainConfig.id);
|
|
405
|
+
let chainObj = Object.create(null);
|
|
406
|
+
Object.defineProperty(Object.defineProperty(Object.defineProperty(Object.defineProperty(Object.defineProperty(chainObj, "id", {
|
|
407
|
+
enumerable: true,
|
|
408
|
+
value: chainConfig.id
|
|
409
|
+
}), "startBlock", {
|
|
410
|
+
enumerable: true,
|
|
411
|
+
value: chainConfig.startBlock
|
|
412
|
+
}), "endBlock", {
|
|
413
|
+
enumerable: true,
|
|
414
|
+
value: chainConfig.endBlock
|
|
415
|
+
}), "name", {
|
|
416
|
+
enumerable: true,
|
|
417
|
+
value: chainConfig.name
|
|
418
|
+
}), "isLive", {
|
|
419
|
+
enumerable: true,
|
|
420
|
+
value: false
|
|
421
|
+
});
|
|
422
|
+
chainConfig.contracts.forEach(contract => {
|
|
423
|
+
let contractObj = Object.create(null);
|
|
424
|
+
Object.defineProperty(Object.defineProperty(Object.defineProperty(contractObj, "name", {
|
|
425
|
+
enumerable: true,
|
|
426
|
+
value: contract.name
|
|
427
|
+
}), "abi", {
|
|
428
|
+
enumerable: true,
|
|
429
|
+
value: contract.abi
|
|
430
|
+
}), "addresses", {
|
|
431
|
+
enumerable: true,
|
|
432
|
+
get: () => {
|
|
433
|
+
if (state.processInProgress) {
|
|
434
|
+
Stdlib_JsError.throwWithMessage(`Cannot access ` + contract.name + `.addresses while indexer.process() is running. ` + "Wait for process() to complete before reading contract addresses.");
|
|
392
435
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
enumerable: true,
|
|
403
|
-
value: chainConfig.id
|
|
404
|
-
}), "startBlock", {
|
|
405
|
-
enumerable: true,
|
|
406
|
-
value: chainConfig.startBlock
|
|
407
|
-
}), "endBlock", {
|
|
408
|
-
enumerable: true,
|
|
409
|
-
value: chainConfig.endBlock
|
|
410
|
-
}), "name", {
|
|
411
|
-
enumerable: true,
|
|
412
|
-
value: chainConfig.name
|
|
413
|
-
}), "isLive", {
|
|
414
|
-
enumerable: true,
|
|
415
|
-
value: false
|
|
416
|
-
});
|
|
417
|
-
Belt_Array.forEach(chainConfig.contracts, (function (contract) {
|
|
418
|
-
var contractObj = Object.create(null);
|
|
419
|
-
Object.defineProperty(Object.defineProperty(Object.defineProperty(contractObj, "name", {
|
|
420
|
-
enumerable: true,
|
|
421
|
-
value: contract.name
|
|
422
|
-
}), "abi", {
|
|
423
|
-
enumerable: true,
|
|
424
|
-
value: contract.abi
|
|
425
|
-
}), "addresses", {
|
|
426
|
-
enumerable: true,
|
|
427
|
-
get: (function () {
|
|
428
|
-
if (state.processInProgress) {
|
|
429
|
-
Js_exn.raiseError("Cannot access " + contract.name + ".addresses while indexer.process() is running. Wait for process() to complete before reading contract addresses.");
|
|
430
|
-
}
|
|
431
|
-
var addresses = contract.addresses.slice(0);
|
|
432
|
-
var dcDict = Js_dict.get(state.entities, Config.DynamicContractRegistry.name);
|
|
433
|
-
if (dcDict !== undefined) {
|
|
434
|
-
Belt_Array.forEach(Js_dict.values(dcDict), (function (entity) {
|
|
435
|
-
if (entity.contract_name === contract.name && entity.chain_id === chainConfig.id) {
|
|
436
|
-
addresses.push(entity.contract_address);
|
|
437
|
-
return ;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
}));
|
|
441
|
-
}
|
|
442
|
-
return addresses;
|
|
443
|
-
})
|
|
444
|
-
});
|
|
445
|
-
Object.defineProperty(chainObj, contract.name, {
|
|
446
|
-
enumerable: true,
|
|
447
|
-
value: contractObj
|
|
448
|
-
});
|
|
449
|
-
}));
|
|
450
|
-
Object.defineProperty(chains, chainIdStr, {
|
|
451
|
-
enumerable: true,
|
|
452
|
-
value: chainObj
|
|
453
|
-
});
|
|
454
|
-
if (chainConfig.name !== chainIdStr) {
|
|
455
|
-
Object.defineProperty(chains, chainConfig.name, {
|
|
456
|
-
enumerable: false,
|
|
457
|
-
value: chainObj
|
|
458
|
-
});
|
|
459
|
-
return ;
|
|
436
|
+
let addresses = [];
|
|
437
|
+
let dcDict = state.entities[Config.EnvioAddresses.name];
|
|
438
|
+
if (dcDict !== undefined) {
|
|
439
|
+
Object.values(dcDict).forEach(entity => {
|
|
440
|
+
if (entity.contract_name === contract.name && entity.chain_id === chainConfig.id) {
|
|
441
|
+
addresses.push(Config.EnvioAddresses.getAddress(entity));
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
});
|
|
460
445
|
}
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
|
|
446
|
+
return addresses;
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
Object.defineProperty(chainObj, contract.name, {
|
|
450
|
+
enumerable: true,
|
|
451
|
+
value: contractObj
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
Object.defineProperty(chains, chainIdStr, {
|
|
455
|
+
enumerable: true,
|
|
456
|
+
value: chainObj
|
|
457
|
+
});
|
|
458
|
+
if (chainConfig.name !== chainIdStr) {
|
|
459
|
+
Object.defineProperty(chains, chainConfig.name, {
|
|
460
|
+
enumerable: false,
|
|
461
|
+
value: chainObj
|
|
462
|
+
});
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
let result = {};
|
|
464
467
|
result["chainIds"] = chainIds;
|
|
465
468
|
result["chains"] = chains;
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
result["process"] =
|
|
470
|
-
|
|
471
|
-
|
|
469
|
+
Object.entries(entityOpsDict).forEach(param => {
|
|
470
|
+
result[param[0]] = param[1];
|
|
471
|
+
});
|
|
472
|
+
result["process"] = processConfig => {
|
|
473
|
+
if (state.processInProgress) {
|
|
474
|
+
Stdlib_JsError.throwWithMessage("createTestIndexer process is already running. Only one process call is allowed at a time");
|
|
475
|
+
}
|
|
476
|
+
let parsedConfig;
|
|
477
|
+
try {
|
|
478
|
+
parsedConfig = S$RescriptSchema.parseOrThrow(processConfig, processConfigSchema);
|
|
479
|
+
} catch (raw_exn) {
|
|
480
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
481
|
+
if (exn.RE_EXN_ID === S$RescriptSchema.Raised) {
|
|
482
|
+
parsedConfig = Stdlib_JsError.throwWithMessage(`Invalid processConfig: ` + Utils.prettifyExn(exn._1));
|
|
483
|
+
} else {
|
|
484
|
+
throw exn;
|
|
472
485
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
486
|
+
}
|
|
487
|
+
let rawChains = parsedConfig.chains;
|
|
488
|
+
let chainKeys = Object.keys(rawChains);
|
|
489
|
+
if (chainKeys.length === 0) {
|
|
490
|
+
Stdlib_JsError.throwWithMessage("createTestIndexer requires at least one chain to be defined");
|
|
491
|
+
}
|
|
492
|
+
let sortedChainKeys = chainKeys.slice();
|
|
493
|
+
sortedChainKeys.sort((a, b) => {
|
|
494
|
+
let aId = Stdlib_Option.getOr(Stdlib_Int.fromString(a, undefined), 0);
|
|
495
|
+
let bId = Stdlib_Option.getOr(Stdlib_Int.fromString(b, undefined), 0);
|
|
496
|
+
return Primitive_int.compare(aId, bId);
|
|
497
|
+
});
|
|
498
|
+
let chainEntries = sortedChainKeys.map(chainIdStr => {
|
|
499
|
+
let rawChainConfig = rawChains[chainIdStr];
|
|
500
|
+
let id = Stdlib_Int.fromString(chainIdStr, undefined);
|
|
501
|
+
let chainId = id !== undefined ? id : Stdlib_JsError.throwWithMessage(`Invalid chain ID "` + chainIdStr + `": expected a numeric chain ID`);
|
|
502
|
+
let processChainConfig = parseBlockRange(chainIdStr, config, rawChainConfig, state.progressBlockByChain[chainIdStr]);
|
|
503
|
+
return [
|
|
504
|
+
chainIdStr,
|
|
505
|
+
chainId,
|
|
506
|
+
rawChainConfig,
|
|
507
|
+
processChainConfig
|
|
508
|
+
];
|
|
509
|
+
});
|
|
510
|
+
state.processChanges = [];
|
|
511
|
+
let runChainWorker = param => {
|
|
512
|
+
let processChainConfig = param[3];
|
|
513
|
+
let rawChainConfig = param[2];
|
|
514
|
+
let chainId = param[1];
|
|
515
|
+
let chains = {};
|
|
516
|
+
chains[param[0]] = processChainConfig;
|
|
517
|
+
let indexingAddressesByChain = {};
|
|
518
|
+
let dcDict = state.entities[Config.EnvioAddresses.name];
|
|
519
|
+
if (dcDict !== undefined) {
|
|
520
|
+
Object.values(dcDict).forEach(entity => {
|
|
521
|
+
let dcChainIdStr = entity.chain_id.toString();
|
|
522
|
+
let arr = indexingAddressesByChain[dcChainIdStr];
|
|
523
|
+
let contracts;
|
|
524
|
+
if (arr !== undefined) {
|
|
525
|
+
contracts = arr;
|
|
526
|
+
} else {
|
|
527
|
+
let arr$1 = [];
|
|
528
|
+
indexingAddressesByChain[dcChainIdStr] = arr$1;
|
|
529
|
+
contracts = arr$1;
|
|
530
|
+
}
|
|
531
|
+
contracts.push(toIndexingAddress(entity));
|
|
532
|
+
});
|
|
476
533
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
534
|
+
let initialState = makeInitialState(config, chains, indexingAddressesByChain);
|
|
535
|
+
return new Promise((resolve, reject) => {
|
|
536
|
+
let workerData_startBlock = processChainConfig.startBlock;
|
|
537
|
+
let workerData_endBlock = processChainConfig.endBlock;
|
|
538
|
+
let workerData_simulate = rawChainConfig.simulate;
|
|
539
|
+
let workerData = {
|
|
540
|
+
chainId: chainId,
|
|
541
|
+
startBlock: workerData_startBlock,
|
|
542
|
+
endBlock: workerData_endBlock,
|
|
543
|
+
simulate: workerData_simulate,
|
|
544
|
+
initialState: initialState
|
|
545
|
+
};
|
|
546
|
+
let worker;
|
|
547
|
+
try {
|
|
548
|
+
worker = new Worker_threads.Worker(workerPath, {
|
|
549
|
+
workerData: workerData,
|
|
550
|
+
env: process.env
|
|
551
|
+
});
|
|
552
|
+
} catch (raw_exn) {
|
|
553
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
554
|
+
reject(exn);
|
|
482
555
|
throw exn;
|
|
483
556
|
}
|
|
557
|
+
worker.on("message", msg => {
|
|
558
|
+
let respond = data => {
|
|
559
|
+
worker.postMessage({
|
|
560
|
+
id: msg.id,
|
|
561
|
+
payload: {
|
|
562
|
+
type: "response",
|
|
563
|
+
data: data
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
};
|
|
567
|
+
let match = msg.payload;
|
|
568
|
+
switch (match.type) {
|
|
569
|
+
case "loadByIds" :
|
|
570
|
+
return respond(handleLoadByIds(state, match.tableName, match.ids));
|
|
571
|
+
case "loadByField" :
|
|
572
|
+
return respond(handleLoadByField(state, match.tableName, match.fieldName, match.fieldValue, match.operator));
|
|
573
|
+
case "writeBatch" :
|
|
574
|
+
handleWriteBatch(state, match.updatedEntities, match.checkpointIds, match.checkpointChainIds, match.checkpointBlockNumbers, match.checkpointEventsProcessed);
|
|
575
|
+
return respond(null);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
worker.on("error", err => {
|
|
579
|
+
worker.terminate();
|
|
580
|
+
reject(err);
|
|
581
|
+
});
|
|
582
|
+
worker.on("exit", code => {
|
|
583
|
+
if (code !== 0) {
|
|
584
|
+
return reject(new Error(`Worker exited with code ` + code.toString()));
|
|
585
|
+
} else {
|
|
586
|
+
return resolve();
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
};
|
|
591
|
+
state.processInProgress = true;
|
|
592
|
+
let runChains = idx => {
|
|
593
|
+
if (idx >= chainEntries.length) {
|
|
594
|
+
state.processInProgress = false;
|
|
595
|
+
return Promise.resolve({
|
|
596
|
+
changes: state.processChanges
|
|
597
|
+
});
|
|
598
|
+
} else {
|
|
599
|
+
return runChainWorker(chainEntries[idx]).then(() => runChains(idx + 1 | 0));
|
|
484
600
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
}
|
|
490
|
-
var sortedChainKeys = chainKeys.slice(0).sort(function (a, b) {
|
|
491
|
-
var aId = Belt_Option.getWithDefault(Belt_Int.fromString(a), 0);
|
|
492
|
-
var bId = Belt_Option.getWithDefault(Belt_Int.fromString(b), 0);
|
|
493
|
-
return aId - bId | 0;
|
|
494
|
-
});
|
|
495
|
-
var chainEntries = Belt_Array.map(sortedChainKeys, (function (chainIdStr) {
|
|
496
|
-
var rawChainConfig = rawChains[chainIdStr];
|
|
497
|
-
var id = Belt_Int.fromString(chainIdStr);
|
|
498
|
-
var chainId = id !== undefined ? id : Js_exn.raiseError("Invalid chain ID \"" + chainIdStr + "\": expected a numeric chain ID");
|
|
499
|
-
var processChainConfig = parseBlockRange(chainIdStr, config, rawChainConfig, Js_dict.get(state.progressBlockByChain, chainIdStr));
|
|
500
|
-
return [
|
|
501
|
-
chainIdStr,
|
|
502
|
-
chainId,
|
|
503
|
-
rawChainConfig,
|
|
504
|
-
processChainConfig
|
|
505
|
-
];
|
|
506
|
-
}));
|
|
507
|
-
state.processChanges = [];
|
|
508
|
-
var runChainWorker = function (param) {
|
|
509
|
-
var processChainConfig = param[3];
|
|
510
|
-
var rawChainConfig = param[2];
|
|
511
|
-
var chainId = param[1];
|
|
512
|
-
var chains = {};
|
|
513
|
-
chains[param[0]] = processChainConfig;
|
|
514
|
-
var dynamicContractsByChain = {};
|
|
515
|
-
var dcDict = Js_dict.get(state.entities, Config.DynamicContractRegistry.name);
|
|
516
|
-
if (dcDict !== undefined) {
|
|
517
|
-
Belt_Array.forEach(Js_dict.values(dcDict), (function (entity) {
|
|
518
|
-
var dcChainIdStr = String(entity.chain_id);
|
|
519
|
-
var arr = Js_dict.get(dynamicContractsByChain, dcChainIdStr);
|
|
520
|
-
var contracts;
|
|
521
|
-
if (arr !== undefined) {
|
|
522
|
-
contracts = arr;
|
|
523
|
-
} else {
|
|
524
|
-
var arr$1 = [];
|
|
525
|
-
dynamicContractsByChain[dcChainIdStr] = arr$1;
|
|
526
|
-
contracts = arr$1;
|
|
527
|
-
}
|
|
528
|
-
contracts.push(toIndexingContract(entity));
|
|
529
|
-
}));
|
|
530
|
-
}
|
|
531
|
-
var initialState = makeInitialState(config, chains, dynamicContractsByChain);
|
|
532
|
-
return new Promise((function (resolve, reject) {
|
|
533
|
-
var workerData_startBlock = processChainConfig.startBlock;
|
|
534
|
-
var workerData_endBlock = processChainConfig.endBlock;
|
|
535
|
-
var workerData_simulate = rawChainConfig.simulate;
|
|
536
|
-
var workerData = {
|
|
537
|
-
chainId: chainId,
|
|
538
|
-
startBlock: workerData_startBlock,
|
|
539
|
-
endBlock: workerData_endBlock,
|
|
540
|
-
simulate: workerData_simulate,
|
|
541
|
-
initialState: initialState
|
|
542
|
-
};
|
|
543
|
-
var worker;
|
|
544
|
-
try {
|
|
545
|
-
worker = new Worker_threads.Worker(workerPath, {
|
|
546
|
-
workerData: workerData
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
catch (raw_exn){
|
|
550
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
551
|
-
reject(exn);
|
|
552
|
-
throw exn;
|
|
553
|
-
}
|
|
554
|
-
worker.on("message", (function (msg) {
|
|
555
|
-
var respond = function (data) {
|
|
556
|
-
worker.postMessage({
|
|
557
|
-
id: msg.id,
|
|
558
|
-
payload: {
|
|
559
|
-
type: "response",
|
|
560
|
-
data: data
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
};
|
|
564
|
-
var match = msg.payload;
|
|
565
|
-
switch (match.type) {
|
|
566
|
-
case "loadByIds" :
|
|
567
|
-
return respond(handleLoadByIds(state, match.tableName, match.ids));
|
|
568
|
-
case "loadByField" :
|
|
569
|
-
return respond(handleLoadByField(state, match.tableName, match.fieldName, match.fieldValue, match.operator));
|
|
570
|
-
case "writeBatch" :
|
|
571
|
-
handleWriteBatch(state, match.updatedEntities, match.checkpointIds, match.checkpointChainIds, match.checkpointBlockNumbers, match.checkpointEventsProcessed);
|
|
572
|
-
return respond(null);
|
|
573
|
-
|
|
574
|
-
}
|
|
575
|
-
}));
|
|
576
|
-
worker.on("error", (function (err) {
|
|
577
|
-
worker.terminate();
|
|
578
|
-
reject(err);
|
|
579
|
-
}));
|
|
580
|
-
worker.on("exit", (function (code) {
|
|
581
|
-
if (code !== 0) {
|
|
582
|
-
return reject(new Error("Worker exited with code " + String(code)));
|
|
583
|
-
} else {
|
|
584
|
-
return resolve();
|
|
585
|
-
}
|
|
586
|
-
}));
|
|
587
|
-
}));
|
|
588
|
-
};
|
|
589
|
-
state.processInProgress = true;
|
|
590
|
-
var runChains = function (idx) {
|
|
591
|
-
if (idx >= chainEntries.length) {
|
|
592
|
-
state.processInProgress = false;
|
|
593
|
-
return Promise.resolve({
|
|
594
|
-
changes: state.processChanges
|
|
595
|
-
});
|
|
596
|
-
} else {
|
|
597
|
-
return runChainWorker(chainEntries[idx]).then(function () {
|
|
598
|
-
return runChains(idx + 1 | 0);
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
return $$Promise.$$catch(runChains(0), (function (err) {
|
|
603
|
-
state.processInProgress = false;
|
|
604
|
-
return Promise.reject(Utils.prettifyExn(err));
|
|
605
|
-
}));
|
|
601
|
+
};
|
|
602
|
+
return Stdlib_Promise.$$catch(runChains(0), err => {
|
|
603
|
+
state.processInProgress = false;
|
|
604
|
+
return Promise.reject(Utils.prettifyExn(err));
|
|
606
605
|
});
|
|
606
|
+
};
|
|
607
607
|
return result;
|
|
608
608
|
};
|
|
609
609
|
}
|
|
610
610
|
|
|
611
|
-
function initTestWorker(
|
|
611
|
+
function initTestWorker() {
|
|
612
612
|
if (Worker_threads.isMainThread) {
|
|
613
|
-
|
|
613
|
+
Stdlib_JsError.throwWithMessage("initTestWorker must be called from a worker thread");
|
|
614
614
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
615
|
+
let port = Worker_threads.parentPort;
|
|
616
|
+
let parentPort = (port == null) ? Stdlib_JsError.throwWithMessage("initTestWorker: No parent port available") : port;
|
|
617
|
+
let workerData = Worker_threads.workerData;
|
|
618
618
|
if (workerData == null) {
|
|
619
619
|
Logging.error("TestIndexerWorker: No worker data provided");
|
|
620
620
|
Process.exit(1);
|
|
621
|
-
return
|
|
621
|
+
return;
|
|
622
622
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
623
|
+
let simulate = workerData.simulate;
|
|
624
|
+
let endBlock = workerData.endBlock;
|
|
625
|
+
let chainIdStr = workerData.chainId.toString();
|
|
626
|
+
let exitAfterFirstEventBlock = Stdlib_Option.isNone(endBlock);
|
|
627
|
+
let resolvedChainDict = {};
|
|
628
628
|
resolvedChainDict["startBlock"] = workerData.startBlock;
|
|
629
629
|
if (endBlock !== undefined) {
|
|
630
630
|
resolvedChainDict["endBlock"] = endBlock;
|
|
@@ -632,67 +632,67 @@ function initTestWorker(makeGeneratedConfig) {
|
|
|
632
632
|
if (simulate !== undefined) {
|
|
633
633
|
resolvedChainDict["simulate"] = simulate;
|
|
634
634
|
}
|
|
635
|
-
|
|
635
|
+
let resolvedChainsDict = {};
|
|
636
636
|
resolvedChainsDict[chainIdStr] = resolvedChainDict;
|
|
637
|
-
|
|
637
|
+
let processConfig = {
|
|
638
638
|
chains: resolvedChainsDict
|
|
639
639
|
};
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
640
|
+
let proxy = TestIndexerProxyStorage.make(parentPort, workerData.initialState);
|
|
641
|
+
let storage = TestIndexerProxyStorage.makeStorage(proxy);
|
|
642
|
+
let config = Config.loadWithoutRegistrations();
|
|
643
|
+
let persistence = Persistence.make(config.userEntities, config.allEnums, storage);
|
|
644
644
|
if (Env.userLogLevel !== undefined) {
|
|
645
645
|
|
|
646
646
|
} else {
|
|
647
647
|
Logging.setLogLevel("silent");
|
|
648
648
|
}
|
|
649
|
-
|
|
650
|
-
|
|
649
|
+
let patchConfig = (config, _registrations) => {
|
|
650
|
+
let config$1 = SimulateItems.patchConfig(config, processConfig);
|
|
651
651
|
if (exitAfterFirstEventBlock) {
|
|
652
652
|
return {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
653
|
+
name: config$1.name,
|
|
654
|
+
description: config$1.description,
|
|
655
|
+
handlers: config$1.handlers,
|
|
656
|
+
contractHandlers: config$1.contractHandlers,
|
|
657
|
+
shouldRollbackOnReorg: config$1.shouldRollbackOnReorg,
|
|
658
|
+
shouldSaveFullHistory: config$1.shouldSaveFullHistory,
|
|
659
|
+
storage: config$1.storage,
|
|
660
|
+
multichain: config$1.multichain,
|
|
661
|
+
chainMap: config$1.chainMap,
|
|
662
|
+
defaultChain: config$1.defaultChain,
|
|
663
|
+
ecosystem: config$1.ecosystem,
|
|
664
|
+
enableRawEvents: config$1.enableRawEvents,
|
|
665
|
+
maxAddrInPartition: config$1.maxAddrInPartition,
|
|
666
|
+
batchSize: 1,
|
|
667
|
+
lowercaseAddresses: config$1.lowercaseAddresses,
|
|
668
|
+
userEntitiesByName: config$1.userEntitiesByName,
|
|
669
|
+
userEntities: config$1.userEntities,
|
|
670
|
+
allEntities: config$1.allEntities,
|
|
671
|
+
allEnums: config$1.allEnums
|
|
672
|
+
};
|
|
673
673
|
} else {
|
|
674
674
|
return config$1;
|
|
675
675
|
}
|
|
676
676
|
};
|
|
677
|
-
Main.start(
|
|
677
|
+
Main.start(persistence, undefined, true, exitAfterFirstEventBlock, patchConfig);
|
|
678
678
|
}
|
|
679
679
|
|
|
680
680
|
export {
|
|
681
|
-
|
|
682
|
-
handleLoadByIds
|
|
683
|
-
handleLoadByField
|
|
684
|
-
handleWriteBatch
|
|
685
|
-
makeInitialState
|
|
686
|
-
rawChainConfigSchema
|
|
687
|
-
processConfigSchema
|
|
688
|
-
getSimulateEndBlock
|
|
689
|
-
parseBlockRange
|
|
690
|
-
getEntityFromState
|
|
691
|
-
makeEntityGet
|
|
692
|
-
makeEntityGetOrThrow
|
|
693
|
-
makeEntitySet
|
|
694
|
-
makeEntityGetAll
|
|
695
|
-
makeCreateTestIndexer
|
|
696
|
-
initTestWorker
|
|
681
|
+
toIndexingAddress,
|
|
682
|
+
handleLoadByIds,
|
|
683
|
+
handleLoadByField,
|
|
684
|
+
handleWriteBatch,
|
|
685
|
+
makeInitialState,
|
|
686
|
+
rawChainConfigSchema,
|
|
687
|
+
processConfigSchema,
|
|
688
|
+
getSimulateEndBlock,
|
|
689
|
+
parseBlockRange,
|
|
690
|
+
getEntityFromState,
|
|
691
|
+
makeEntityGet,
|
|
692
|
+
makeEntityGetOrThrow,
|
|
693
|
+
makeEntitySet,
|
|
694
|
+
makeEntityGetAll,
|
|
695
|
+
makeCreateTestIndexer,
|
|
696
|
+
initTestWorker,
|
|
697
697
|
}
|
|
698
698
|
/* rawChainConfigSchema Not a pure module */
|