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
|
@@ -3,64 +3,62 @@
|
|
|
3
3
|
import * as Rest from "../vendored/Rest.res.mjs";
|
|
4
4
|
import * as Utils from "../Utils.res.mjs";
|
|
5
5
|
import * as Hrtime from "../bindings/Hrtime.res.mjs";
|
|
6
|
-
import * as Js_exn from "rescript/lib/es6/js_exn.js";
|
|
7
6
|
import * as Source from "./Source.res.mjs";
|
|
8
7
|
import * as Logging from "../Logging.res.mjs";
|
|
9
8
|
import * as Internal from "../Internal.res.mjs";
|
|
10
9
|
import * as HyperSync from "./HyperSync.res.mjs";
|
|
11
|
-
import * as Belt_Array from "rescript/lib/es6/
|
|
10
|
+
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
12
11
|
import * as Prometheus from "../Prometheus.res.mjs";
|
|
13
|
-
import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
|
|
14
12
|
import * as EventRouter from "./EventRouter.res.mjs";
|
|
15
13
|
import * as LogSelection from "../LogSelection.res.mjs";
|
|
16
14
|
import * as ErrorHandling from "../ErrorHandling.res.mjs";
|
|
17
|
-
import * as
|
|
15
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
16
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
18
17
|
import * as HyperSyncClient from "./HyperSyncClient.res.mjs";
|
|
19
|
-
import * as Caml_splice_call from "rescript/lib/es6/caml_splice_call.js";
|
|
20
18
|
import * as HyperSyncJsonApi from "./HyperSyncJsonApi.res.mjs";
|
|
21
|
-
import * as
|
|
19
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
22
20
|
import * as HyperSyncHeightStream from "./HyperSyncHeightStream.res.mjs";
|
|
23
21
|
|
|
24
22
|
function getSelectionConfig(selection, chain) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
23
|
+
let nonOptionalBlockFieldNames = new Set();
|
|
24
|
+
let nonOptionalTransactionFieldNames = new Set();
|
|
25
|
+
let capitalizedBlockFields = new Set();
|
|
26
|
+
let capitalizedTransactionFields = new Set();
|
|
27
|
+
let staticTopicSelectionsByContract = {};
|
|
28
|
+
let dynamicEventFiltersByContract = {};
|
|
29
|
+
let dynamicWildcardEventFiltersByContract = {};
|
|
30
|
+
let noAddressesTopicSelections = [];
|
|
31
|
+
let contractNames = new Set();
|
|
32
|
+
selection.eventConfigs.forEach(param => {
|
|
33
|
+
let contractName = param.contractName;
|
|
34
|
+
Array.from(param.selectedBlockFields).forEach(name => {
|
|
35
|
+
if (!Internal.evmNullableBlockFields.has(name)) {
|
|
36
|
+
nonOptionalBlockFieldNames.add(name);
|
|
37
|
+
}
|
|
38
|
+
capitalizedBlockFields.add(Utils.$$String.capitalize(name));
|
|
39
|
+
});
|
|
40
|
+
Array.from(param.selectedTransactionFields).forEach(name => {
|
|
41
|
+
if (!Internal.evmNullableTransactionFields.has(name)) {
|
|
42
|
+
nonOptionalTransactionFieldNames.add(name);
|
|
43
|
+
}
|
|
44
|
+
capitalizedTransactionFields.add(Utils.$$String.capitalize(name));
|
|
45
|
+
});
|
|
46
|
+
let eventFilters = param.getEventFiltersOrThrow(chain);
|
|
47
|
+
if (param.dependsOnAddresses) {
|
|
48
|
+
contractNames.add(contractName);
|
|
49
|
+
if (eventFilters.TAG === "Static") {
|
|
50
|
+
return Utils.Dict.pushMany(staticTopicSelectionsByContract, contractName, eventFilters._0);
|
|
51
|
+
} else {
|
|
52
|
+
return Utils.Dict.push(param.isWildcard ? dynamicWildcardEventFiltersByContract : dynamicEventFiltersByContract, contractName, eventFilters._0);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
let tmp;
|
|
56
|
+
tmp = eventFilters.TAG === "Static" ? eventFilters._0 : eventFilters._0([]);
|
|
57
|
+
noAddressesTopicSelections.push(...tmp);
|
|
58
|
+
});
|
|
59
|
+
let fieldSelection_block = Array.from(capitalizedBlockFields);
|
|
60
|
+
let fieldSelection_transaction = Array.from(capitalizedTransactionFields);
|
|
61
|
+
let fieldSelection_log = [
|
|
64
62
|
"Address",
|
|
65
63
|
"Data",
|
|
66
64
|
"LogIndex",
|
|
@@ -69,85 +67,79 @@ function getSelectionConfig(selection, chain) {
|
|
|
69
67
|
"Topic2",
|
|
70
68
|
"Topic3"
|
|
71
69
|
];
|
|
72
|
-
|
|
70
|
+
let fieldSelection = {
|
|
73
71
|
block: fieldSelection_block,
|
|
74
72
|
transaction: fieldSelection_transaction,
|
|
75
73
|
log: fieldSelection_log
|
|
76
74
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
let noAddressesLogSelection = LogSelection.make([], noAddressesTopicSelections);
|
|
76
|
+
let getLogSelectionOrThrow = addressesByContractName => {
|
|
77
|
+
let logSelections = [];
|
|
80
78
|
if (!Utils.$$Array.isEmpty(noAddressesLogSelection.topicSelections)) {
|
|
81
79
|
logSelections.push(noAddressesLogSelection);
|
|
82
80
|
}
|
|
83
|
-
contractNames.forEach(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}))));
|
|
106
|
-
return ;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
});
|
|
81
|
+
contractNames.forEach(contractName => {
|
|
82
|
+
let addresses = addressesByContractName[contractName];
|
|
83
|
+
if (addresses === undefined) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (addresses.length === 0) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let topicSelections = staticTopicSelectionsByContract[contractName];
|
|
90
|
+
if (topicSelections !== undefined) {
|
|
91
|
+
logSelections.push(LogSelection.make(addresses, topicSelections));
|
|
92
|
+
}
|
|
93
|
+
let fns = dynamicEventFiltersByContract[contractName];
|
|
94
|
+
if (fns !== undefined) {
|
|
95
|
+
logSelections.push(LogSelection.make(addresses, fns.flatMap(fn => fn(addresses))));
|
|
96
|
+
}
|
|
97
|
+
let fns$1 = dynamicWildcardEventFiltersByContract[contractName];
|
|
98
|
+
if (fns$1 !== undefined) {
|
|
99
|
+
logSelections.push(LogSelection.make([], fns$1.flatMap(fn => fn(addresses))));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
110
103
|
return logSelections;
|
|
111
104
|
};
|
|
112
105
|
return {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
getLogSelectionOrThrow: getLogSelectionOrThrow,
|
|
107
|
+
fieldSelection: fieldSelection,
|
|
108
|
+
nonOptionalBlockFieldNames: Array.from(nonOptionalBlockFieldNames),
|
|
109
|
+
nonOptionalTransactionFieldNames: Array.from(nonOptionalTransactionFieldNames)
|
|
110
|
+
};
|
|
118
111
|
}
|
|
119
112
|
|
|
120
113
|
function memoGetSelectionConfig(chain) {
|
|
121
|
-
return Utils.$$WeakMap.memoize(
|
|
122
|
-
return getSelectionConfig(selection, chain);
|
|
123
|
-
});
|
|
114
|
+
return Utils.$$WeakMap.memoize(selection => getSelectionConfig(selection, chain));
|
|
124
115
|
}
|
|
125
116
|
|
|
126
117
|
function make(param) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
118
|
+
let lowercaseAddresses = param.lowercaseAddresses;
|
|
119
|
+
let apiToken = param.apiToken;
|
|
120
|
+
let eventRouter = param.eventRouter;
|
|
121
|
+
let allEventSignatures = param.allEventSignatures;
|
|
122
|
+
let endpointUrl = param.endpointUrl;
|
|
123
|
+
let chain = param.chain;
|
|
124
|
+
let name = "HyperSync";
|
|
125
|
+
let getSelectionConfig = memoGetSelectionConfig(chain);
|
|
126
|
+
let apiToken$1 = apiToken !== undefined ? apiToken : Stdlib_JsError.throwWithMessage(`An API token is required for using HyperSync as a data-source.
|
|
127
|
+
Set the ENVIO_API_TOKEN environment variable in your .env file.
|
|
128
|
+
Learn more or get a free API token at: https://envio.dev/app/api-tokens`);
|
|
129
|
+
let client = HyperSyncClient.make(endpointUrl, apiToken$1, param.clientTimeoutMillis, param.clientMaxRetries, !lowercaseAddresses, param.serializationFormat, param.enableQueryCaching, undefined, undefined, undefined);
|
|
130
|
+
let hscDecoder = {
|
|
138
131
|
contents: undefined
|
|
139
132
|
};
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
let getHscDecoder = () => {
|
|
134
|
+
let decoder = hscDecoder.contents;
|
|
142
135
|
if (decoder !== undefined) {
|
|
143
136
|
return decoder;
|
|
144
137
|
}
|
|
145
|
-
|
|
138
|
+
let decoder$1;
|
|
146
139
|
try {
|
|
147
140
|
decoder$1 = HyperSyncClient.Decoder.fromSignatures(allEventSignatures);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
141
|
+
} catch (raw_exn) {
|
|
142
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
151
143
|
return ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate a decoder from hypersync client, please double check your ABI", exn);
|
|
152
144
|
}
|
|
153
145
|
if (lowercaseAddresses) {
|
|
@@ -157,115 +149,111 @@ function make(param) {
|
|
|
157
149
|
}
|
|
158
150
|
return decoder$1;
|
|
159
151
|
};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
152
|
+
let UndefinedValue = /* @__PURE__ */Primitive_exceptions.create("UndefinedValue");
|
|
153
|
+
let makeEventBatchQueueItem = (item, params, eventConfig) => {
|
|
154
|
+
let block = item.block;
|
|
155
|
+
let log = item.log;
|
|
164
156
|
return {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
};
|
|
182
|
-
};
|
|
183
|
-
var getItemsOrThrow = async function (fromBlock, toBlock, addressesByContractName, indexingContracts, knownHeight, param, selection, retry, logger) {
|
|
184
|
-
var mkLogAndRaise = function (extra, extra$1) {
|
|
185
|
-
return ErrorHandling.mkLogAndRaise(logger, extra, extra$1);
|
|
157
|
+
kind: 0,
|
|
158
|
+
eventConfig: eventConfig,
|
|
159
|
+
timestamp: block.timestamp,
|
|
160
|
+
chain: chain,
|
|
161
|
+
blockNumber: block.number,
|
|
162
|
+
logIndex: log.logIndex,
|
|
163
|
+
event: {
|
|
164
|
+
contractName: eventConfig.contractName,
|
|
165
|
+
eventName: eventConfig.name,
|
|
166
|
+
params: params,
|
|
167
|
+
chainId: chain,
|
|
168
|
+
srcAddress: log.address,
|
|
169
|
+
logIndex: log.logIndex,
|
|
170
|
+
transaction: item.transaction,
|
|
171
|
+
block: block
|
|
172
|
+
}
|
|
186
173
|
};
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
174
|
+
};
|
|
175
|
+
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, indexingAddresses, knownHeight, param, selection, retry, logger) => {
|
|
176
|
+
let mkLogAndRaise = (extra, extra$1) => ErrorHandling.mkLogAndRaise(logger, extra, extra$1);
|
|
177
|
+
let totalTimeRef = Hrtime.makeTimer();
|
|
178
|
+
let selectionConfig = getSelectionConfig(selection);
|
|
179
|
+
let logSelections;
|
|
190
180
|
try {
|
|
191
181
|
logSelections = selectionConfig.getLogSelectionOrThrow(addressesByContractName);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
182
|
+
} catch (raw_exn) {
|
|
183
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
195
184
|
logSelections = ErrorHandling.mkLogAndRaise(logger, "Failed getting log selection for the query", exn);
|
|
196
185
|
}
|
|
197
|
-
|
|
186
|
+
let startFetchingBatchTimeRef = Hrtime.makeTimer();
|
|
198
187
|
Prometheus.SourceRequestCount.increment(name, chain, "getLogs");
|
|
199
|
-
|
|
188
|
+
let pageUnsafe;
|
|
200
189
|
try {
|
|
201
190
|
pageUnsafe = await HyperSync.GetLogs.query(client, fromBlock, toBlock, logSelections, selectionConfig.fieldSelection, selectionConfig.nonOptionalBlockFieldNames, selectionConfig.nonOptionalTransactionFieldNames);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
var error = Caml_js_exceptions.internalToOCamlException(raw_error);
|
|
191
|
+
} catch (raw_error) {
|
|
192
|
+
let error = Primitive_exceptions.internalToException(raw_error);
|
|
205
193
|
if (error.RE_EXN_ID === HyperSync.GetLogs.$$Error) {
|
|
206
|
-
|
|
207
|
-
|
|
194
|
+
let error$1 = error._1;
|
|
195
|
+
let tmp;
|
|
208
196
|
if (typeof error$1 !== "object") {
|
|
209
|
-
|
|
197
|
+
let backoffMillis = retry !== 0 ? 500 * retry | 0 : 100;
|
|
210
198
|
tmp = {
|
|
211
199
|
TAG: "WithBackoff",
|
|
212
|
-
message:
|
|
200
|
+
message: `Block #` + fromBlock.toString() + ` not found in HyperSync. HyperSync has multiple instances and it's possible that they drift independently slightly from the head. Indexing should continue correctly after retrying the query in ` + backoffMillis.toString() + `ms.`,
|
|
213
201
|
backoffMillis: backoffMillis
|
|
214
202
|
};
|
|
215
203
|
} else {
|
|
216
204
|
tmp = {
|
|
217
205
|
TAG: "ImpossibleForTheQuery",
|
|
218
|
-
message:
|
|
206
|
+
message: `Source returned invalid data with missing required fields: ` + error$1.missingParams.join(", ")
|
|
219
207
|
};
|
|
220
208
|
}
|
|
221
209
|
throw {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
210
|
+
RE_EXN_ID: Source.GetItemsError,
|
|
211
|
+
_1: {
|
|
212
|
+
TAG: "FailedGettingItems",
|
|
213
|
+
exn: null,
|
|
214
|
+
attemptedToBlock: Stdlib_Option.getOr(toBlock, knownHeight),
|
|
215
|
+
retry: tmp
|
|
216
|
+
},
|
|
217
|
+
Error: new Error()
|
|
218
|
+
};
|
|
231
219
|
}
|
|
232
220
|
throw {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
221
|
+
RE_EXN_ID: Source.GetItemsError,
|
|
222
|
+
_1: {
|
|
223
|
+
TAG: "FailedGettingItems",
|
|
224
|
+
exn: error,
|
|
225
|
+
attemptedToBlock: Stdlib_Option.getOr(toBlock, knownHeight),
|
|
226
|
+
retry: {
|
|
227
|
+
TAG: "WithBackoff",
|
|
228
|
+
message: `Unexpected issue while fetching events from HyperSync client. Attempt a retry.`,
|
|
229
|
+
backoffMillis: retry !== 0 ? 1000 * retry | 0 : 500
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
Error: new Error()
|
|
233
|
+
};
|
|
246
234
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
235
|
+
let pageFetchTime = Hrtime.toSecondsFloat(Hrtime.timeSince(startFetchingBatchTimeRef));
|
|
236
|
+
let knownHeight$1 = pageUnsafe.archiveHeight;
|
|
237
|
+
let heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
|
|
238
|
+
let match = pageUnsafe.rollbackGuard;
|
|
239
|
+
let lastBlockQueriedPromise;
|
|
252
240
|
if (match !== undefined) {
|
|
253
241
|
lastBlockQueriedPromise = Promise.resolve({
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
242
|
+
blockHash: match.hash,
|
|
243
|
+
blockNumber: match.blockNumber,
|
|
244
|
+
blockTimestamp: match.timestamp
|
|
245
|
+
});
|
|
258
246
|
} else {
|
|
259
|
-
|
|
260
|
-
|
|
247
|
+
let match$1 = Belt_Array.get(pageUnsafe.items, pageUnsafe.items.length - 1 | 0);
|
|
248
|
+
let exit = 0;
|
|
261
249
|
if (match$1 !== undefined) {
|
|
262
|
-
|
|
250
|
+
let block = match$1.block;
|
|
263
251
|
if (block.number === heighestBlockQueried) {
|
|
264
252
|
lastBlockQueriedPromise = Promise.resolve({
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
253
|
+
blockHash: block.hash,
|
|
254
|
+
blockNumber: block.number,
|
|
255
|
+
blockTimestamp: block.timestamp
|
|
256
|
+
});
|
|
269
257
|
} else {
|
|
270
258
|
exit = 1;
|
|
271
259
|
}
|
|
@@ -273,135 +261,125 @@ function make(param) {
|
|
|
273
261
|
exit = 1;
|
|
274
262
|
}
|
|
275
263
|
if (exit === 1) {
|
|
276
|
-
lastBlockQueriedPromise = HyperSync.queryBlockData(client, heighestBlockQueried, name, chain, logger).then(
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
});
|
|
287
|
-
}
|
|
264
|
+
lastBlockQueriedPromise = HyperSync.queryBlockData(client, heighestBlockQueried, name, chain, logger).then(res => {
|
|
265
|
+
if (res.TAG !== "Ok") {
|
|
266
|
+
return mkLogAndRaise(`Failed to query blockData for block ` + heighestBlockQueried.toString(), HyperSync.queryErrorToMsq(res._0));
|
|
267
|
+
}
|
|
268
|
+
let blockData = res._0;
|
|
269
|
+
if (blockData !== undefined) {
|
|
270
|
+
return blockData;
|
|
271
|
+
} else {
|
|
272
|
+
return mkLogAndRaise(`Failure, blockData for block ` + heighestBlockQueried.toString() + ` unexpectedly returned None`, {
|
|
273
|
+
RE_EXN_ID: "Not_found"
|
|
288
274
|
});
|
|
275
|
+
}
|
|
276
|
+
});
|
|
289
277
|
}
|
|
290
|
-
|
|
291
278
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
279
|
+
let parsingTimeRef = Hrtime.makeTimer();
|
|
280
|
+
let parsedQueueItems = [];
|
|
281
|
+
let parsedEvents;
|
|
295
282
|
try {
|
|
296
283
|
parsedEvents = await getHscDecoder().decodeEvents(pageUnsafe.events);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1);
|
|
284
|
+
} catch (raw_exn$1) {
|
|
285
|
+
let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
|
|
300
286
|
parsedEvents = mkLogAndRaise("Failed to parse events using hypersync client, please double check your ABI.", exn$1);
|
|
301
287
|
}
|
|
302
|
-
Belt_Array.forEachWithIndex(pageUnsafe.items, (
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}));
|
|
342
|
-
var reorgGuard = {
|
|
288
|
+
Belt_Array.forEachWithIndex(pageUnsafe.items, (index, item) => {
|
|
289
|
+
let block = item.block;
|
|
290
|
+
let log = item.log;
|
|
291
|
+
let topic0 = Utils.$$Array.firstUnsafe(log.topics);
|
|
292
|
+
let maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), log.address, block.number, indexingAddresses);
|
|
293
|
+
let maybeDecodedEvent = parsedEvents[index];
|
|
294
|
+
if (maybeEventConfig === undefined) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (maybeDecodedEvent == null) {
|
|
298
|
+
maybeDecodedEvent === null;
|
|
299
|
+
} else {
|
|
300
|
+
parsedQueueItems.push(makeEventBatchQueueItem(item, maybeEventConfig.convertHyperSyncEventArgs(maybeDecodedEvent), maybeEventConfig));
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
let logIndex = log.logIndex;
|
|
304
|
+
let blockNumber = block.number;
|
|
305
|
+
let exn = {
|
|
306
|
+
RE_EXN_ID: UndefinedValue
|
|
307
|
+
};
|
|
308
|
+
if (maybeEventConfig.isWildcard) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
let msg = `Event ` + maybeEventConfig.name + ` was unexpectedly parsed as undefined`;
|
|
312
|
+
let logger$1 = Logging.createChildFrom(logger, {
|
|
313
|
+
chainId: chain,
|
|
314
|
+
blockNumber: blockNumber,
|
|
315
|
+
logIndex: logIndex,
|
|
316
|
+
decoder: "hypersync-client"
|
|
317
|
+
});
|
|
318
|
+
ErrorHandling.mkLogAndRaise(logger$1, msg, exn);
|
|
319
|
+
});
|
|
320
|
+
let parsingTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(parsingTimeRef));
|
|
321
|
+
let rangeLastBlock = await lastBlockQueriedPromise;
|
|
322
|
+
let reorgGuard_prevRangeLastBlock = Stdlib_Option.map(pageUnsafe.rollbackGuard, v => ({
|
|
323
|
+
blockHash: v.firstParentHash,
|
|
324
|
+
blockNumber: v.firstBlockNumber - 1 | 0
|
|
325
|
+
}));
|
|
326
|
+
let reorgGuard = {
|
|
343
327
|
rangeLastBlock: rangeLastBlock,
|
|
344
328
|
prevRangeLastBlock: reorgGuard_prevRangeLastBlock
|
|
345
329
|
};
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
330
|
+
let totalTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(totalTimeRef));
|
|
331
|
+
let stats_parsing$unknowntime$unknown$lpars$rpar = parsingTimeElapsed;
|
|
332
|
+
let stats_page$unknownfetch$unknowntime$unknown$lpars$rpar = pageFetchTime;
|
|
333
|
+
let stats = {
|
|
350
334
|
"total time elapsed (s)": totalTimeElapsed,
|
|
351
335
|
"parsing time (s)": stats_parsing$unknowntime$unknown$lpars$rpar,
|
|
352
336
|
"page fetch time (s)": stats_page$unknownfetch$unknowntime$unknown$lpars$rpar
|
|
353
337
|
};
|
|
354
338
|
return {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
};
|
|
364
|
-
var getBlockHashes = function (blockNumbers, logger) {
|
|
365
|
-
return HyperSync.queryBlockDataMulti(client, blockNumbers, name, chain, logger).then(HyperSync.mapExn);
|
|
339
|
+
knownHeight: knownHeight$1,
|
|
340
|
+
reorgGuard: reorgGuard,
|
|
341
|
+
parsedQueueItems: parsedQueueItems,
|
|
342
|
+
fromBlockQueried: fromBlock,
|
|
343
|
+
latestFetchedBlockNumber: rangeLastBlock.blockNumber,
|
|
344
|
+
latestFetchedBlockTimestamp: rangeLastBlock.blockTimestamp,
|
|
345
|
+
stats: stats
|
|
346
|
+
};
|
|
366
347
|
};
|
|
367
|
-
|
|
348
|
+
let getBlockHashes = (blockNumbers, logger) => HyperSync.queryBlockDataMulti(client, blockNumbers, name, chain, logger).then(HyperSync.mapExn);
|
|
349
|
+
let jsonApiClient = Rest.client(endpointUrl, undefined);
|
|
368
350
|
return {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
createHeightSubscription: (function (onHeight) {
|
|
397
|
-
return HyperSyncHeightStream.subscribe(endpointUrl, apiToken$1, chain, onHeight);
|
|
398
|
-
})
|
|
399
|
-
};
|
|
351
|
+
name: name,
|
|
352
|
+
sourceFor: "Sync",
|
|
353
|
+
chain: chain,
|
|
354
|
+
poweredByHyperSync: true,
|
|
355
|
+
pollingInterval: 100,
|
|
356
|
+
getBlockHashes: getBlockHashes,
|
|
357
|
+
getHeightOrThrow: async () => {
|
|
358
|
+
let timerRef = Hrtime.makeTimer();
|
|
359
|
+
let height = await Rest.fetch(HyperSyncJsonApi.heightRoute, apiToken$1, jsonApiClient);
|
|
360
|
+
let result;
|
|
361
|
+
if (typeof height === "number") {
|
|
362
|
+
result = height;
|
|
363
|
+
} else if (height === `Your token is malformed. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens.`) {
|
|
364
|
+
Logging.error(`Your ENVIO_API_TOKEN is malformed. The indexer will not be able to fetch events. Update the token and restart the indexer using 'pnpm envio start'. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens`);
|
|
365
|
+
await new Promise((param, param$1) => {});
|
|
366
|
+
result = 0;
|
|
367
|
+
} else {
|
|
368
|
+
result = Stdlib_JsError.throwWithMessage(height);
|
|
369
|
+
}
|
|
370
|
+
let seconds = Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef));
|
|
371
|
+
Prometheus.SourceRequestCount.increment(name, chain, "getHeight");
|
|
372
|
+
Prometheus.SourceRequestCount.addSeconds(name, chain, "getHeight", seconds);
|
|
373
|
+
return result;
|
|
374
|
+
},
|
|
375
|
+
getItemsOrThrow: getItemsOrThrow,
|
|
376
|
+
createHeightSubscription: onHeight => HyperSyncHeightStream.subscribe(endpointUrl, apiToken$1, chain, onHeight)
|
|
377
|
+
};
|
|
400
378
|
}
|
|
401
379
|
|
|
402
380
|
export {
|
|
403
|
-
getSelectionConfig
|
|
404
|
-
memoGetSelectionConfig
|
|
405
|
-
make
|
|
381
|
+
getSelectionConfig,
|
|
382
|
+
memoGetSelectionConfig,
|
|
383
|
+
make,
|
|
406
384
|
}
|
|
407
385
|
/* Rest Not a pure module */
|