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
|
@@ -2,110 +2,105 @@
|
|
|
2
2
|
|
|
3
3
|
import * as Utils from "../Utils.res.mjs";
|
|
4
4
|
import * as Address from "../Address.res.mjs";
|
|
5
|
-
import * as Belt_Array from "rescript/lib/es6/
|
|
5
|
+
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
6
6
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
7
7
|
import * as HypersyncClient from "@envio-dev/hypersync-client";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
let serializationFormatSchema = S$RescriptSchema.$$enum([
|
|
10
|
+
"Json",
|
|
11
|
+
"CapnProto"
|
|
12
|
+
]);
|
|
13
13
|
|
|
14
14
|
function makeTopicSelection(topic0Opt, topic1Opt, topic2Opt, topic3Opt) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
let topic0 = topic0Opt !== undefined ? topic0Opt : [];
|
|
16
|
+
let topic1 = topic1Opt !== undefined ? topic1Opt : [];
|
|
17
|
+
let topic2 = topic2Opt !== undefined ? topic2Opt : [];
|
|
18
|
+
let topic3 = topic3Opt !== undefined ? topic3Opt : [];
|
|
19
19
|
return [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
topic0,
|
|
21
|
+
topic1,
|
|
22
|
+
topic2,
|
|
23
|
+
topic3
|
|
24
|
+
];
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function makeLogSelection(address, topics) {
|
|
28
28
|
return {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
address: address,
|
|
30
|
+
topics: topics
|
|
31
|
+
};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
let QueryTypes = {
|
|
35
35
|
makeTopicSelection: makeTopicSelection,
|
|
36
36
|
makeLogSelection: makeLogSelection
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
});
|
|
39
|
+
let accessListSchema = S$RescriptSchema.object(s => ({
|
|
40
|
+
address: s.f("address", S$RescriptSchema.option(Address.schema)),
|
|
41
|
+
storageKeys: s.f("storageKeys", S$RescriptSchema.option(S$RescriptSchema.array(S$RescriptSchema.string)))
|
|
42
|
+
}));
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
});
|
|
44
|
+
let authorizationListSchema = S$RescriptSchema.object(s => ({
|
|
45
|
+
chainId: s.f("chainId", S$RescriptSchema.bigint),
|
|
46
|
+
address: s.f("address", Address.schema),
|
|
47
|
+
nonce: s.f("nonce", S$RescriptSchema.int),
|
|
48
|
+
yParity: s.f("yParity", S$RescriptSchema.$$enum([
|
|
49
|
+
0,
|
|
50
|
+
1
|
|
51
|
+
])),
|
|
52
|
+
r: s.f("r", S$RescriptSchema.string),
|
|
53
|
+
s: s.f("s", S$RescriptSchema.string)
|
|
54
|
+
}));
|
|
59
55
|
|
|
60
|
-
|
|
56
|
+
let ResponseTypes = {
|
|
61
57
|
accessListSchema: accessListSchema,
|
|
62
58
|
authorizationListSchema: authorizationListSchema
|
|
63
59
|
};
|
|
64
60
|
|
|
65
|
-
|
|
61
|
+
let HeightStream = {};
|
|
66
62
|
|
|
67
63
|
function make(url, apiToken, httpReqTimeoutMillis, maxNumRetries, enableChecksumAddressesOpt, serializationFormat, enableQueryCaching, retryBaseMs, retryBackoffMs, retryCeilingMs) {
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
let enableChecksumAddresses = enableChecksumAddressesOpt !== undefined ? enableChecksumAddressesOpt : true;
|
|
65
|
+
let envioVersion = Utils.EnvioPackage.value.version;
|
|
70
66
|
return HypersyncClient.HypersyncClient.newWithAgent({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
url: url,
|
|
68
|
+
apiToken: apiToken,
|
|
69
|
+
httpReqTimeoutMillis: httpReqTimeoutMillis,
|
|
70
|
+
maxNumRetries: maxNumRetries,
|
|
71
|
+
retryBackoffMs: retryBackoffMs,
|
|
72
|
+
retryBaseMs: retryBaseMs,
|
|
73
|
+
retryCeilingMs: retryCeilingMs,
|
|
74
|
+
enableChecksumAddresses: enableChecksumAddresses,
|
|
75
|
+
serializationFormat: serializationFormat,
|
|
76
|
+
enableQueryCaching: enableQueryCaching
|
|
77
|
+
}, `hyperindex/` + envioVersion);
|
|
82
78
|
}
|
|
83
79
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
80
|
+
let logLevelSchema = S$RescriptSchema.$$enum([
|
|
81
|
+
"trace",
|
|
82
|
+
"debug",
|
|
83
|
+
"info",
|
|
84
|
+
"warn",
|
|
85
|
+
"error"
|
|
86
|
+
]);
|
|
91
87
|
|
|
92
88
|
function toUnderlying(_d) {
|
|
93
|
-
while(true) {
|
|
94
|
-
|
|
89
|
+
while (true) {
|
|
90
|
+
let d = _d;
|
|
95
91
|
if (Array.isArray(d)) {
|
|
96
92
|
return Belt_Array.map(d, toUnderlying);
|
|
97
93
|
}
|
|
98
94
|
switch (typeof d) {
|
|
99
95
|
case "boolean" :
|
|
100
|
-
|
|
96
|
+
return d;
|
|
101
97
|
case "string" :
|
|
102
|
-
|
|
98
|
+
return d;
|
|
103
99
|
case "bigint" :
|
|
104
|
-
|
|
100
|
+
return d;
|
|
105
101
|
case "object" :
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
102
|
+
_d = d.val;
|
|
103
|
+
continue;
|
|
109
104
|
}
|
|
110
105
|
};
|
|
111
106
|
}
|
|
@@ -114,18 +109,18 @@ function fromSignatures(prim) {
|
|
|
114
109
|
return HypersyncClient.Decoder.fromSignatures(prim);
|
|
115
110
|
}
|
|
116
111
|
|
|
117
|
-
|
|
112
|
+
let Decoder = {
|
|
118
113
|
toUnderlying: toUnderlying,
|
|
119
114
|
fromSignatures: fromSignatures
|
|
120
115
|
};
|
|
121
116
|
|
|
122
117
|
export {
|
|
123
|
-
serializationFormatSchema
|
|
124
|
-
QueryTypes
|
|
125
|
-
ResponseTypes
|
|
126
|
-
HeightStream
|
|
127
|
-
make
|
|
128
|
-
logLevelSchema
|
|
129
|
-
Decoder
|
|
118
|
+
serializationFormatSchema,
|
|
119
|
+
QueryTypes,
|
|
120
|
+
ResponseTypes,
|
|
121
|
+
HeightStream,
|
|
122
|
+
make,
|
|
123
|
+
logLevelSchema,
|
|
124
|
+
Decoder,
|
|
130
125
|
}
|
|
131
126
|
/* serializationFormatSchema Not a pure module */
|
|
@@ -7,17 +7,17 @@ let subscribe = (~hyperSyncUrl, ~apiToken, ~chainId, ~onHeight: int => unit): (u
|
|
|
7
7
|
let errorCount = ref(0)
|
|
8
8
|
let baseDuration = 50
|
|
9
9
|
// Timeout doesn't do anything for initialization
|
|
10
|
-
let timeoutIdRef = ref(
|
|
10
|
+
let timeoutIdRef = ref(setTimeout(() => (), 0))
|
|
11
11
|
|
|
12
12
|
// On every successful ping or height event, clear the timeout and set a new one.
|
|
13
13
|
// If the timeout lapses, close and reconnect the EventSource.
|
|
14
14
|
let rec updateTimeoutId = () => {
|
|
15
|
-
timeoutIdRef.contents->
|
|
15
|
+
timeoutIdRef.contents->clearTimeout
|
|
16
16
|
|
|
17
17
|
// Should receive a ping at least every 5s, so 15s is a safe margin
|
|
18
18
|
// for staleness to restart the EventSource connection
|
|
19
19
|
let staleTimeMillis = 15_000
|
|
20
|
-
let newTimeoutId =
|
|
20
|
+
let newTimeoutId = setTimeout(() => {
|
|
21
21
|
Logging.trace({
|
|
22
22
|
"msg": "Timeout fired for height stream",
|
|
23
23
|
"chainId": chainId,
|
|
@@ -34,11 +34,10 @@ let subscribe = (~hyperSyncUrl, ~apiToken, ~chainId, ~onHeight: int => unit): (u
|
|
|
34
34
|
// and update the timeout.
|
|
35
35
|
and scheduleReconnect = () => {
|
|
36
36
|
// Clear any pending stale/reconnect timeout to avoid double reconnect
|
|
37
|
-
timeoutIdRef.contents->
|
|
37
|
+
timeoutIdRef.contents->clearTimeout
|
|
38
38
|
let delay =
|
|
39
|
-
baseDuration *
|
|
40
|
-
|
|
41
|
-
timeoutIdRef := Js.Global.setTimeout(() => refreshEventSource(), Pervasives.min(delay, 60_000))
|
|
39
|
+
baseDuration * Math.pow(2.0, ~exp=errorCount.contents->Belt.Int.toFloat)->Belt.Float.toInt
|
|
40
|
+
timeoutIdRef := setTimeout(() => refreshEventSource(), Pervasives.min(delay, 60_000))
|
|
42
41
|
}
|
|
43
42
|
and refreshEventSource = () => {
|
|
44
43
|
// Close the old EventSource if it exists (on a new connection after timeout)
|
|
@@ -56,7 +55,7 @@ let subscribe = (~hyperSyncUrl, ~apiToken, ~chainId, ~onHeight: int => unit): (u
|
|
|
56
55
|
url,
|
|
57
56
|
~args={
|
|
58
57
|
...args,
|
|
59
|
-
headers:
|
|
58
|
+
headers: Dict.fromArray([
|
|
60
59
|
("Authorization", `Bearer ${apiToken}`),
|
|
61
60
|
("User-Agent", userAgent),
|
|
62
61
|
]),
|
|
@@ -128,7 +127,7 @@ let subscribe = (~hyperSyncUrl, ~apiToken, ~chainId, ~onHeight: int => unit): (u
|
|
|
128
127
|
|
|
129
128
|
// Return unsubscribe function
|
|
130
129
|
() => {
|
|
131
|
-
timeoutIdRef.contents->
|
|
130
|
+
timeoutIdRef.contents->clearTimeout
|
|
132
131
|
switch eventsourceRef.contents {
|
|
133
132
|
| Some(es) => es->EventSource.close
|
|
134
133
|
| None => ()
|
|
@@ -1,120 +1,112 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Utils from "../Utils.res.mjs";
|
|
4
|
-
import * as Js_dict from "rescript/lib/es6/js_dict.js";
|
|
5
4
|
import * as Logging from "../Logging.res.mjs";
|
|
6
|
-
import * as Belt_Int from "rescript/lib/es6/
|
|
7
|
-
import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
|
|
5
|
+
import * as Belt_Int from "@rescript/runtime/lib/es6/Belt_Int.js";
|
|
8
6
|
import * as Prometheus from "../Prometheus.res.mjs";
|
|
9
|
-
import * as Caml_option from "rescript/lib/es6/caml_option.js";
|
|
10
7
|
import * as Eventsource from "eventsource";
|
|
8
|
+
import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
|
|
9
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
11
10
|
|
|
12
11
|
function subscribe(hyperSyncUrl, apiToken, chainId, onHeight) {
|
|
13
|
-
|
|
12
|
+
let eventsourceRef = {
|
|
14
13
|
contents: undefined
|
|
15
14
|
};
|
|
16
|
-
|
|
15
|
+
let errorCount = {
|
|
17
16
|
contents: 0
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
contents: setTimeout((
|
|
21
|
-
|
|
22
|
-
}), 0)
|
|
18
|
+
let timeoutIdRef = {
|
|
19
|
+
contents: setTimeout(() => {}, 0)
|
|
23
20
|
};
|
|
24
|
-
|
|
21
|
+
let updateTimeoutId = () => {
|
|
25
22
|
clearTimeout(timeoutIdRef.contents);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
let newTimeoutId = setTimeout(() => {
|
|
24
|
+
Logging.trace({
|
|
25
|
+
msg: "Timeout fired for height stream",
|
|
26
|
+
chainId: chainId,
|
|
27
|
+
url: hyperSyncUrl,
|
|
28
|
+
staleTimeMillis: 15000
|
|
29
|
+
});
|
|
30
|
+
refreshEventSource();
|
|
31
|
+
}, 15000);
|
|
35
32
|
timeoutIdRef.contents = newTimeoutId;
|
|
36
33
|
};
|
|
37
|
-
|
|
34
|
+
let scheduleReconnect = () => {
|
|
38
35
|
clearTimeout(timeoutIdRef.contents);
|
|
39
|
-
|
|
40
|
-
timeoutIdRef.contents = setTimeout((
|
|
41
|
-
refreshEventSource();
|
|
42
|
-
}), delay < 60000 ? delay : 60000);
|
|
36
|
+
let delay = 50 * (Math.pow(2.0, errorCount.contents) | 0) | 0;
|
|
37
|
+
timeoutIdRef.contents = setTimeout(() => refreshEventSource(), Primitive_int.min(delay, 60000));
|
|
43
38
|
};
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
let refreshEventSource = () => {
|
|
40
|
+
let es = eventsourceRef.contents;
|
|
46
41
|
if (es !== undefined) {
|
|
47
|
-
|
|
42
|
+
Primitive_option.valFromOption(es).close();
|
|
48
43
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
eventsourceRef.contents =
|
|
44
|
+
let userAgent = `hyperindex/` + Utils.EnvioPackage.value.version;
|
|
45
|
+
let es$1 = new Eventsource.EventSource(hyperSyncUrl + `/height/sse`, {
|
|
46
|
+
fetch: (url, args) => {
|
|
47
|
+
let newrecord = {...args};
|
|
48
|
+
return fetch(url, (newrecord.headers = Object.fromEntries([
|
|
49
|
+
[
|
|
50
|
+
"Authorization",
|
|
51
|
+
`Bearer ` + apiToken
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
"User-Agent",
|
|
55
|
+
userAgent
|
|
56
|
+
]
|
|
57
|
+
]), newrecord));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
eventsourceRef.contents = Primitive_option.some(es$1);
|
|
66
61
|
updateTimeoutId();
|
|
67
|
-
es$1.onopen = (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
});
|
|
62
|
+
es$1.onopen = () => {
|
|
63
|
+
errorCount.contents = 0;
|
|
64
|
+
Logging.trace({
|
|
65
|
+
msg: "SSE connection opened for height stream",
|
|
66
|
+
chainId: chainId,
|
|
67
|
+
url: hyperSyncUrl
|
|
74
68
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
scheduleReconnect();
|
|
69
|
+
};
|
|
70
|
+
es$1.onerror = error => {
|
|
71
|
+
errorCount.contents = errorCount.contents + 1 | 0;
|
|
72
|
+
Logging.trace({
|
|
73
|
+
msg: "EventSource error on height stream, reconnecting",
|
|
74
|
+
chainId: chainId,
|
|
75
|
+
url: hyperSyncUrl,
|
|
76
|
+
status: error.status,
|
|
77
|
+
error: error.message,
|
|
78
|
+
errorCount: errorCount.contents
|
|
86
79
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
es$1.addEventListener("height",
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
80
|
+
scheduleReconnect();
|
|
81
|
+
};
|
|
82
|
+
es$1.addEventListener("ping", _event => updateTimeoutId());
|
|
83
|
+
es$1.addEventListener("height", event => {
|
|
84
|
+
let height = Belt_Int.fromString(event.data);
|
|
85
|
+
if (height !== undefined) {
|
|
86
|
+
Prometheus.SourceRequestCount.increment("HyperSync", chainId, "heightStream");
|
|
87
|
+
updateTimeoutId();
|
|
88
|
+
return onHeight(height);
|
|
89
|
+
} else {
|
|
90
|
+
return Logging.trace({
|
|
91
|
+
msg: "Height was not a number in event.data",
|
|
92
|
+
chainId: chainId,
|
|
93
|
+
data: event.data
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
104
97
|
};
|
|
105
98
|
refreshEventSource();
|
|
106
|
-
return
|
|
99
|
+
return () => {
|
|
107
100
|
clearTimeout(timeoutIdRef.contents);
|
|
108
|
-
|
|
101
|
+
let es = eventsourceRef.contents;
|
|
109
102
|
if (es !== undefined) {
|
|
110
|
-
|
|
111
|
-
return
|
|
103
|
+
Primitive_option.valFromOption(es).close();
|
|
104
|
+
return;
|
|
112
105
|
}
|
|
113
|
-
|
|
114
106
|
};
|
|
115
107
|
}
|
|
116
108
|
|
|
117
109
|
export {
|
|
118
|
-
subscribe
|
|
110
|
+
subscribe,
|
|
119
111
|
}
|
|
120
112
|
/* Utils Not a pure module */
|
|
@@ -231,15 +231,15 @@ module ResponseTypes = {
|
|
|
231
231
|
stateRoot: ?s.field("state_root", S.option(S.string)),
|
|
232
232
|
receiptsRoot: ?s.field("receipts_root", S.option(S.string)),
|
|
233
233
|
miner: ?s.field("miner", S.option(S.string)),
|
|
234
|
-
difficulty: ?s.field("difficulty", S.option(S.null(BigInt.schema))),
|
|
235
|
-
totalDifficulty: ?s.field("total_difficulty", S.option(S.null(BigInt.schema))),
|
|
234
|
+
difficulty: ?s.field("difficulty", S.option(S.null(Utils.BigInt.schema))),
|
|
235
|
+
totalDifficulty: ?s.field("total_difficulty", S.option(S.null(Utils.BigInt.schema))),
|
|
236
236
|
extraData: ?s.field("extra_data", S.option(S.string)),
|
|
237
|
-
size: ?s.field("size", S.option(BigInt.schema)),
|
|
238
|
-
gasLimit: ?s.field("gas_limit", S.option(BigInt.schema)),
|
|
239
|
-
gasUsed: ?s.field("gas_used", S.option(BigInt.schema)),
|
|
240
|
-
timestamp: ?s.field("timestamp", S.option(BigInt.schema)),
|
|
237
|
+
size: ?s.field("size", S.option(Utils.BigInt.schema)),
|
|
238
|
+
gasLimit: ?s.field("gas_limit", S.option(Utils.BigInt.schema)),
|
|
239
|
+
gasUsed: ?s.field("gas_used", S.option(Utils.BigInt.schema)),
|
|
240
|
+
timestamp: ?s.field("timestamp", S.option(Utils.BigInt.schema)),
|
|
241
241
|
uncles: ?s.field("unclus", S.option(S.null(S.string))),
|
|
242
|
-
baseFeePerGas: ?s.field("base_fee_per_gas", S.option(S.null(BigInt.schema))),
|
|
242
|
+
baseFeePerGas: ?s.field("base_fee_per_gas", S.option(S.null(Utils.BigInt.schema))),
|
|
243
243
|
})
|
|
244
244
|
|
|
245
245
|
type transactionData = {
|
|
@@ -275,23 +275,26 @@ module ResponseTypes = {
|
|
|
275
275
|
blockHash: ?s.field("block_hash", S.option(S.string)),
|
|
276
276
|
blockNumber: ?s.field("block_number", S.option(S.int)),
|
|
277
277
|
from: ?s.field("from", S.option(S.null(S.string))),
|
|
278
|
-
gas: ?s.field("gas", S.option(BigInt.schema)),
|
|
279
|
-
gasPrice: ?s.field("gas_price", S.option(S.null(BigInt.schema))),
|
|
278
|
+
gas: ?s.field("gas", S.option(Utils.BigInt.schema)),
|
|
279
|
+
gasPrice: ?s.field("gas_price", S.option(S.null(Utils.BigInt.schema))),
|
|
280
280
|
hash: ?s.field("hash", S.option(S.string)),
|
|
281
281
|
input: ?s.field("input", S.option(S.string)),
|
|
282
282
|
nonce: ?s.field("nonce", S.option(S.int)),
|
|
283
283
|
to: ?s.field("to", S.option(S.null(S.string))),
|
|
284
284
|
transactionIndex: ?s.field("transaction_index", S.option(S.int)),
|
|
285
|
-
value: ?s.field("value", S.option(BigInt.schema)),
|
|
285
|
+
value: ?s.field("value", S.option(Utils.BigInt.schema)),
|
|
286
286
|
v: ?s.field("v", S.option(S.null(S.string))),
|
|
287
287
|
r: ?s.field("r", S.option(S.null(S.string))),
|
|
288
288
|
s: ?s.field("s", S.option(S.null(S.string))),
|
|
289
|
-
maxPriorityFeePerGas: ?s.field(
|
|
290
|
-
|
|
289
|
+
maxPriorityFeePerGas: ?s.field(
|
|
290
|
+
"max_priority_fee_per_gas",
|
|
291
|
+
S.option(S.null(Utils.BigInt.schema)),
|
|
292
|
+
),
|
|
293
|
+
maxFeePerGas: ?s.field("max_fee_per_gas", S.option(S.null(Utils.BigInt.schema))),
|
|
291
294
|
chainId: ?s.field("chain_id", S.option(S.null(S.int))),
|
|
292
|
-
cumulativeGasUsed: ?s.field("cumulative_gas_used", S.option(BigInt.schema)),
|
|
293
|
-
effectiveGasPrice: ?s.field("effective_gas_price", S.option(BigInt.schema)),
|
|
294
|
-
gasUsed: ?s.field("gas_used", S.option(BigInt.schema)),
|
|
295
|
+
cumulativeGasUsed: ?s.field("cumulative_gas_used", S.option(Utils.BigInt.schema)),
|
|
296
|
+
effectiveGasPrice: ?s.field("effective_gas_price", S.option(Utils.BigInt.schema)),
|
|
297
|
+
gasUsed: ?s.field("gas_used", S.option(Utils.BigInt.schema)),
|
|
295
298
|
contractAddress: ?s.field("contract_address", S.option(S.null(S.string))),
|
|
296
299
|
logsBoom: ?s.field("logs_bloom", S.option(S.string)),
|
|
297
300
|
type_: ?s.field("type", S.option(S.null(S.int))),
|