envio 3.1.2 → 3.2.0
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/evm.schema.json +83 -11
- package/fuel.schema.json +83 -11
- package/index.d.ts +184 -3
- package/package.json +6 -6
- package/src/Batch.res +2 -2
- package/src/ChainFetcher.res +27 -3
- package/src/ChainFetcher.res.mjs +17 -3
- package/src/ChainManager.res +163 -0
- package/src/ChainManager.res.mjs +136 -0
- package/src/Config.res +213 -30
- package/src/Config.res.mjs +102 -41
- package/src/Core.res +16 -10
- package/src/Ecosystem.res +0 -3
- package/src/Env.res +2 -2
- package/src/Env.res.mjs +2 -2
- package/src/Envio.res +101 -2
- package/src/Envio.res.mjs +2 -3
- package/src/EventConfigBuilder.res +52 -0
- package/src/EventConfigBuilder.res.mjs +32 -0
- package/src/EventUtils.res +2 -2
- package/src/FetchState.res +23 -14
- package/src/FetchState.res.mjs +21 -15
- package/src/GlobalState.res +219 -363
- package/src/GlobalState.res.mjs +314 -491
- package/src/GlobalStateManager.res +49 -59
- package/src/GlobalStateManager.res.mjs +5 -4
- package/src/GlobalStateManager.resi +1 -1
- package/src/HandlerLoader.res +12 -1
- package/src/HandlerLoader.res.mjs +6 -1
- package/src/HandlerRegister.res +9 -9
- package/src/HandlerRegister.res.mjs +9 -9
- package/src/Hasura.res +102 -32
- package/src/Hasura.res.mjs +88 -34
- package/src/InMemoryStore.res +10 -1
- package/src/InMemoryStore.res.mjs +4 -1
- package/src/InMemoryTable.res +83 -136
- package/src/InMemoryTable.res.mjs +57 -86
- package/src/Internal.res +54 -5
- package/src/Internal.res.mjs +2 -8
- package/src/LazyLoader.res +2 -2
- package/src/LazyLoader.res.mjs +3 -3
- package/src/LoadLayer.res +47 -60
- package/src/LoadLayer.res.mjs +28 -50
- package/src/LoadLayer.resi +2 -5
- package/src/LogSelection.res +4 -4
- package/src/LogSelection.res.mjs +5 -7
- package/src/Logging.res +1 -1
- package/src/Main.res +61 -2
- package/src/Main.res.mjs +37 -1
- package/src/Persistence.res +3 -16
- package/src/PgStorage.res +125 -114
- package/src/PgStorage.res.mjs +112 -95
- package/src/Ports.res +5 -0
- package/src/Ports.res.mjs +9 -0
- package/src/Prometheus.res +3 -3
- package/src/Prometheus.res.mjs +4 -4
- package/src/ReorgDetection.res +4 -4
- package/src/ReorgDetection.res.mjs +4 -5
- package/src/SafeCheckpointTracking.res +16 -16
- package/src/SafeCheckpointTracking.res.mjs +2 -2
- package/src/SimulateItems.res +10 -14
- package/src/SimulateItems.res.mjs +5 -2
- package/src/Sink.res +1 -1
- package/src/Sink.res.mjs +1 -2
- package/src/SvmTypes.res +9 -0
- package/src/SvmTypes.res.mjs +14 -0
- package/src/TestIndexer.res +17 -57
- package/src/TestIndexer.res.mjs +14 -48
- package/src/TestIndexerProxyStorage.res +23 -23
- package/src/TestIndexerProxyStorage.res.mjs +12 -15
- package/src/Throttler.res +2 -2
- package/src/Time.res +2 -2
- package/src/Time.res.mjs +2 -2
- package/src/UserContext.res +19 -118
- package/src/UserContext.res.mjs +10 -66
- package/src/Utils.res +15 -15
- package/src/Utils.res.mjs +7 -8
- package/src/adapters/MarkBatchProcessedAdapter.res +5 -0
- package/src/adapters/MarkBatchProcessedAdapter.res.mjs +14 -0
- package/src/bindings/BigDecimal.res +1 -1
- package/src/bindings/BigDecimal.res.mjs +2 -2
- package/src/bindings/ClickHouse.res +8 -6
- package/src/bindings/ClickHouse.res.mjs +5 -5
- package/src/bindings/Hrtime.res +1 -1
- package/src/bindings/Pino.res +2 -2
- package/src/bindings/Pino.res.mjs +3 -4
- package/src/db/EntityFilter.res +410 -0
- package/src/db/EntityFilter.res.mjs +424 -0
- package/src/db/EntityHistory.res +1 -1
- package/src/db/EntityHistory.res.mjs +1 -1
- package/src/db/InternalTable.res +10 -10
- package/src/db/InternalTable.res.mjs +41 -45
- package/src/db/Schema.res +2 -2
- package/src/db/Schema.res.mjs +3 -3
- package/src/db/Table.res +106 -22
- package/src/db/Table.res.mjs +84 -35
- package/src/sources/EventRouter.res +67 -2
- package/src/sources/EventRouter.res.mjs +45 -3
- package/src/sources/Evm.res +0 -7
- package/src/sources/Evm.res.mjs +0 -15
- package/src/sources/EvmChain.res +1 -1
- package/src/sources/EvmChain.res.mjs +1 -2
- package/src/sources/EvmRpcClient.res +42 -0
- package/src/sources/EvmRpcClient.res.mjs +64 -0
- package/src/sources/Fuel.res +0 -7
- package/src/sources/Fuel.res.mjs +0 -15
- package/src/sources/HyperFuelSource.res +5 -4
- package/src/sources/HyperFuelSource.res.mjs +2 -2
- package/src/sources/HyperSyncClient.res +9 -5
- package/src/sources/HyperSyncClient.res.mjs +2 -2
- package/src/sources/HyperSyncHeightStream.res +2 -2
- package/src/sources/HyperSyncHeightStream.res.mjs +2 -2
- package/src/sources/HyperSyncSource.res +10 -9
- package/src/sources/HyperSyncSource.res.mjs +4 -4
- package/src/sources/Rpc.res +1 -5
- package/src/sources/Rpc.res.mjs +1 -9
- package/src/sources/RpcSource.res +57 -21
- package/src/sources/RpcSource.res.mjs +47 -20
- package/src/sources/RpcWebSocketHeightStream.res +1 -1
- package/src/sources/SourceManager.res +3 -2
- package/src/sources/SourceManager.res.mjs +1 -1
- package/src/sources/Svm.res +3 -10
- package/src/sources/Svm.res.mjs +4 -18
- package/src/sources/SvmHyperSyncClient.res +265 -0
- package/src/sources/SvmHyperSyncClient.res.mjs +28 -0
- package/src/sources/SvmHyperSyncSource.res +638 -0
- package/src/sources/SvmHyperSyncSource.res.mjs +557 -0
- package/src/tui/Tui.res +9 -2
- package/src/tui/Tui.res.mjs +18 -3
- package/src/tui/components/BufferedProgressBar.res +2 -2
- package/src/tui/components/TuiData.res +3 -0
- package/svm.schema.json +523 -14
- package/src/TableIndices.res +0 -115
- package/src/TableIndices.res.mjs +0 -144
package/src/sources/Evm.res.mjs
CHANGED
|
@@ -74,18 +74,6 @@ let ecosystem_transactionFields = [
|
|
|
74
74
|
"authorizationList"
|
|
75
75
|
];
|
|
76
76
|
|
|
77
|
-
function ecosystem_getNumber(prim) {
|
|
78
|
-
return prim.number;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function ecosystem_getTimestamp(prim) {
|
|
82
|
-
return prim.timestamp;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function ecosystem_getId(prim) {
|
|
86
|
-
return prim.hash;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
77
|
let ecosystem_onBlockFilterSchema = S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("number", S$RescriptSchema.unknown)))));
|
|
90
78
|
|
|
91
79
|
let ecosystem_onEventBlockFilterSchema = S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("number", S$RescriptSchema.unknown)))));
|
|
@@ -97,9 +85,6 @@ let ecosystem = {
|
|
|
97
85
|
blockNumberName: "number",
|
|
98
86
|
blockTimestampName: "timestamp",
|
|
99
87
|
blockHashName: "hash",
|
|
100
|
-
getNumber: ecosystem_getNumber,
|
|
101
|
-
getTimestamp: ecosystem_getTimestamp,
|
|
102
|
-
getId: ecosystem_getId,
|
|
103
88
|
cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace,
|
|
104
89
|
onBlockMethodName: "onBlock",
|
|
105
90
|
onBlockFilterSchema: ecosystem_onBlockFilterSchema,
|
package/src/sources/EvmChain.res
CHANGED
|
@@ -67,7 +67,7 @@ let makeSources = (
|
|
|
67
67
|
) => {
|
|
68
68
|
let eventRouter =
|
|
69
69
|
contracts
|
|
70
|
-
->
|
|
70
|
+
->Array.flatMap(contract => contract.events)
|
|
71
71
|
->EventRouter.fromEvmEventModsOrThrow(~chain)
|
|
72
72
|
|
|
73
73
|
let allEventParams = collectEventParams(contracts)
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import * as Env from "../Env.res.mjs";
|
|
4
4
|
import * as RpcSource from "./RpcSource.res.mjs";
|
|
5
|
-
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
6
5
|
import * as EventRouter from "./EventRouter.res.mjs";
|
|
7
6
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
8
7
|
import * as HyperSyncSource from "./HyperSyncSource.res.mjs";
|
|
@@ -38,7 +37,7 @@ function collectEventParams(contracts) {
|
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
function makeSources(chain, contracts, hyperSync, rpcs, lowercaseAddresses) {
|
|
41
|
-
let eventRouter = EventRouter.fromEvmEventModsOrThrow(
|
|
40
|
+
let eventRouter = EventRouter.fromEvmEventModsOrThrow(contracts.flatMap(contract => contract.events), chain);
|
|
42
41
|
let allEventParams = collectEventParams(contracts);
|
|
43
42
|
let sources = hyperSync !== undefined ? [HyperSyncSource.make({
|
|
44
43
|
chain: chain,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
type cfg = {url: string, httpReqTimeoutMillis?: int}
|
|
2
|
+
|
|
3
|
+
type t = {getHeight: unit => promise<int>}
|
|
4
|
+
|
|
5
|
+
@send
|
|
6
|
+
external classNew: (Core.evmRpcClientCtor, cfg) => t = "new"
|
|
7
|
+
|
|
8
|
+
// Rust encodes JSON-RPC errors as a JSON payload in the napi error's
|
|
9
|
+
// message: `{"kind":"JsonRpcError","code":-32005,"message":"..."}`.
|
|
10
|
+
// Parse it back so callers keep matching on Rpc.JsonRpcError.
|
|
11
|
+
let getJsonRpcError = (exn: exn): option<Rpc.rpcError> =>
|
|
12
|
+
switch exn {
|
|
13
|
+
| JsExn(e) =>
|
|
14
|
+
switch e->JsExn.message {
|
|
15
|
+
| Some(msg) =>
|
|
16
|
+
switch msg->JSON.parseOrThrow->JSON.Decode.object {
|
|
17
|
+
| exception _ => None
|
|
18
|
+
| None => None
|
|
19
|
+
| Some(obj) =>
|
|
20
|
+
switch (obj->Dict.get("kind"), obj->Dict.get("code"), obj->Dict.get("message")) {
|
|
21
|
+
| (Some(String("JsonRpcError")), Some(Number(code)), Some(String(message))) =>
|
|
22
|
+
Some({code: code->Float.toInt, message})
|
|
23
|
+
| _ => None
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
| None => None
|
|
27
|
+
}
|
|
28
|
+
| _ => None
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let coerceErrorOrThrow = exn =>
|
|
32
|
+
switch exn->getJsonRpcError {
|
|
33
|
+
| Some(rpcError) => throw(Rpc.JsonRpcError(rpcError))
|
|
34
|
+
| None => exn->throw
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let make = (~url, ~httpReqTimeoutMillis=?) => {
|
|
38
|
+
let client = Core.getAddon().evmRpcClient->classNew({url, ?httpReqTimeoutMillis})
|
|
39
|
+
{
|
|
40
|
+
getHeight: () => client.getHeight()->Promise.catch(coerceErrorOrThrow),
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Rpc from "./Rpc.res.mjs";
|
|
4
|
+
import * as Core from "../Core.res.mjs";
|
|
5
|
+
import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
6
|
+
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
7
|
+
import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.js";
|
|
8
|
+
|
|
9
|
+
function getJsonRpcError(exn) {
|
|
10
|
+
if (exn.RE_EXN_ID !== "JsExn") {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
let msg = Stdlib_JsExn.message(exn._1);
|
|
14
|
+
if (msg === undefined) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
let obj;
|
|
18
|
+
try {
|
|
19
|
+
obj = Stdlib_JSON.Decode.object(JSON.parse(msg));
|
|
20
|
+
} catch (exn$1) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (obj === undefined) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
let match = obj["kind"];
|
|
27
|
+
let match$1 = obj["code"];
|
|
28
|
+
let match$2 = obj["message"];
|
|
29
|
+
if (match === "JsonRpcError" && typeof match$1 === "number" && typeof match$2 === "string") {
|
|
30
|
+
return {
|
|
31
|
+
code: match$1 | 0,
|
|
32
|
+
message: match$2
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function coerceErrorOrThrow(exn) {
|
|
38
|
+
let rpcError = getJsonRpcError(exn);
|
|
39
|
+
if (rpcError !== undefined) {
|
|
40
|
+
throw {
|
|
41
|
+
RE_EXN_ID: Rpc.JsonRpcError,
|
|
42
|
+
_1: rpcError,
|
|
43
|
+
Error: new Error()
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
throw exn;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function make(url, httpReqTimeoutMillis) {
|
|
50
|
+
let client = Core.getAddon().EvmRpcClient.new({
|
|
51
|
+
url: url,
|
|
52
|
+
httpReqTimeoutMillis: httpReqTimeoutMillis
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
getHeight: () => Stdlib_Promise.$$catch(client.getHeight(), coerceErrorOrThrow)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
getJsonRpcError,
|
|
61
|
+
coerceErrorOrThrow,
|
|
62
|
+
make,
|
|
63
|
+
}
|
|
64
|
+
/* Rpc Not a pure module */
|
package/src/sources/Fuel.res
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
@get external getNumber: Internal.eventBlock => int = "height"
|
|
2
|
-
@get external getTimestamp: Internal.eventBlock => int = "time"
|
|
3
|
-
@get external getId: Internal.eventBlock => string = "id"
|
|
4
|
-
|
|
5
1
|
let cleanUpRawEventFieldsInPlace: JSON.t => unit = %raw(`fields => {
|
|
6
2
|
delete fields.id
|
|
7
3
|
delete fields.height
|
|
@@ -15,9 +11,6 @@ let ecosystem: Ecosystem.t = {
|
|
|
15
11
|
blockNumberName: "height",
|
|
16
12
|
blockTimestampName: "time",
|
|
17
13
|
blockHashName: "id",
|
|
18
|
-
getNumber,
|
|
19
|
-
getTimestamp,
|
|
20
|
-
getId,
|
|
21
14
|
cleanUpRawEventFieldsInPlace,
|
|
22
15
|
onBlockMethodName: "onBlock",
|
|
23
16
|
// Fuel filter shape: `{block: {height: {_gte?, _lte?, _every?}}}`.
|
package/src/sources/Fuel.res.mjs
CHANGED
|
@@ -16,18 +16,6 @@ let ecosystem_blockFields = [
|
|
|
16
16
|
|
|
17
17
|
let ecosystem_transactionFields = ["id"];
|
|
18
18
|
|
|
19
|
-
function ecosystem_getNumber(prim) {
|
|
20
|
-
return prim.height;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function ecosystem_getTimestamp(prim) {
|
|
24
|
-
return prim.time;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function ecosystem_getId(prim) {
|
|
28
|
-
return prim.id;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
19
|
let ecosystem_onBlockFilterSchema = S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("height", S$RescriptSchema.unknown)))));
|
|
32
20
|
|
|
33
21
|
let ecosystem_onEventBlockFilterSchema = S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("height", S$RescriptSchema.unknown)))));
|
|
@@ -39,9 +27,6 @@ let ecosystem = {
|
|
|
39
27
|
blockNumberName: "height",
|
|
40
28
|
blockTimestampName: "time",
|
|
41
29
|
blockHashName: "id",
|
|
42
|
-
getNumber: ecosystem_getNumber,
|
|
43
|
-
getTimestamp: ecosystem_getTimestamp,
|
|
44
|
-
getId: ecosystem_getId,
|
|
45
30
|
cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace,
|
|
46
31
|
onBlockMethodName: "onBlock",
|
|
47
32
|
onBlockFilterSchema: ecosystem_onBlockFilterSchema,
|
|
@@ -163,7 +163,7 @@ let getSelectionConfig = (selection: FetchState.selection, ~chain) => {
|
|
|
163
163
|
wildcardLogDataRbs->Array.push(rb)->ignore
|
|
164
164
|
} else {
|
|
165
165
|
switch nonWildcardLogDataRbsByContract->Utils.Dict.dangerouslyGetNonOption(contractName) {
|
|
166
|
-
| Some(arr) => arr->
|
|
166
|
+
| Some(arr) => arr->Array.push(rb)
|
|
167
167
|
| None => nonWildcardLogDataRbsByContract->Dict.set(contractName, [rb])
|
|
168
168
|
}
|
|
169
169
|
}
|
|
@@ -395,6 +395,7 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
395
395
|
timestamp: block.time,
|
|
396
396
|
chain,
|
|
397
397
|
blockNumber: block.height,
|
|
398
|
+
blockHash: block.id,
|
|
398
399
|
logIndex: receiptIndex,
|
|
399
400
|
event: {
|
|
400
401
|
contractName: eventConfig.contractName,
|
|
@@ -407,7 +408,7 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
407
408
|
block: block->Obj.magic,
|
|
408
409
|
srcAddress: contractAddress,
|
|
409
410
|
logIndex: receiptIndex,
|
|
410
|
-
},
|
|
411
|
+
}->Internal.fromGenericEvent,
|
|
411
412
|
})
|
|
412
413
|
})
|
|
413
414
|
|
|
@@ -420,8 +421,8 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
420
421
|
blockHash: block.id,
|
|
421
422
|
})
|
|
422
423
|
|
|
423
|
-
let latestFetchedBlockTimestamp = switch pageUnsafe.items->
|
|
424
|
-
pageUnsafe.items->
|
|
424
|
+
let latestFetchedBlockTimestamp = switch pageUnsafe.items->Array.get(
|
|
425
|
+
pageUnsafe.items->Array.length - 1,
|
|
425
426
|
) {
|
|
426
427
|
| Some({block}) if block.height == heighestBlockQueried => block.time
|
|
427
428
|
| _ => 0
|
|
@@ -6,7 +6,6 @@ import * as Source from "./Source.res.mjs";
|
|
|
6
6
|
import * as Logging from "../Logging.res.mjs";
|
|
7
7
|
import * as HyperFuel from "./HyperFuel.res.mjs";
|
|
8
8
|
import * as HyperSync from "./HyperSync.res.mjs";
|
|
9
|
-
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
10
9
|
import * as Prometheus from "../Prometheus.res.mjs";
|
|
11
10
|
import * as EventRouter from "./EventRouter.res.mjs";
|
|
12
11
|
import * as ErrorHandling from "../ErrorHandling.res.mjs";
|
|
@@ -338,6 +337,7 @@ function make(param) {
|
|
|
338
337
|
timestamp: block.time,
|
|
339
338
|
chain: chain,
|
|
340
339
|
blockNumber: block.height,
|
|
340
|
+
blockHash: block.id,
|
|
341
341
|
logIndex: receiptIndex,
|
|
342
342
|
event: {
|
|
343
343
|
contractName: eventConfig$1.contractName,
|
|
@@ -361,7 +361,7 @@ function make(param) {
|
|
|
361
361
|
blockNumber: block.height
|
|
362
362
|
};
|
|
363
363
|
});
|
|
364
|
-
let match =
|
|
364
|
+
let match = pageUnsafe.items[pageUnsafe.items.length - 1 | 0];
|
|
365
365
|
let latestFetchedBlockTimestamp;
|
|
366
366
|
if (match !== undefined) {
|
|
367
367
|
let block = match.block;
|
|
@@ -337,13 +337,13 @@ module Decoder = {
|
|
|
337
337
|
|
|
338
338
|
@send
|
|
339
339
|
external classFromParams: (
|
|
340
|
-
Core.
|
|
340
|
+
Core.evmDecoderCtor,
|
|
341
341
|
array<eventParamsInput>,
|
|
342
342
|
~checksumAddresses: bool=?,
|
|
343
343
|
) => tWithParams = "fromParams"
|
|
344
344
|
|
|
345
345
|
let fromParams = (eventParams, ~checksumAddresses=?) =>
|
|
346
|
-
Core.getAddon().
|
|
346
|
+
Core.getAddon().evmDecoder->classFromParams(eventParams, ~checksumAddresses?)
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
module EventItems = {
|
|
@@ -372,11 +372,15 @@ type t = {
|
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
@send
|
|
375
|
-
external classNew: (
|
|
376
|
-
|
|
375
|
+
external classNew: (
|
|
376
|
+
Core.evmHypersyncClientCtor,
|
|
377
|
+
cfg,
|
|
378
|
+
string,
|
|
379
|
+
array<Decoder.eventParamsInput>,
|
|
380
|
+
) => t = "new"
|
|
377
381
|
|
|
378
382
|
let makeWithAgent = (cfg, ~userAgent, ~eventParams) =>
|
|
379
|
-
Core.getAddon().
|
|
383
|
+
Core.getAddon().evmHypersyncClient->classNew(cfg, userAgent, eventParams)
|
|
380
384
|
|
|
381
385
|
type logLevel = [#trace | #debug | #info | #warn | #error]
|
|
382
386
|
let logLevelSchema: S.t<logLevel> = S.enum([#trace, #debug, #info, #warn, #error])
|
|
@@ -59,7 +59,7 @@ let ResponseTypes = {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
function fromParams(eventParams, checksumAddresses) {
|
|
62
|
-
return Core.getAddon().
|
|
62
|
+
return Core.getAddon().EvmDecoder.fromParams(eventParams, checksumAddresses !== undefined ? Primitive_option.valFromOption(checksumAddresses) : undefined);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
let Decoder = {
|
|
@@ -69,7 +69,7 @@ let Decoder = {
|
|
|
69
69
|
let EventItems = {};
|
|
70
70
|
|
|
71
71
|
function makeWithAgent(cfg, userAgent, eventParams) {
|
|
72
|
-
return Core.getAddon().
|
|
72
|
+
return Core.getAddon().EvmHypersyncClient.new(cfg, userAgent, eventParams);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
let logLevelSchema = S$RescriptSchema.$$enum([
|
|
@@ -36,7 +36,7 @@ let subscribe = (~hyperSyncUrl, ~apiToken, ~chainId, ~onHeight: int => unit): (u
|
|
|
36
36
|
// Clear any pending stale/reconnect timeout to avoid double reconnect
|
|
37
37
|
timeoutIdRef.contents->clearTimeout
|
|
38
38
|
let delay =
|
|
39
|
-
baseDuration * Math.pow(2.0, ~exp=errorCount.contents->
|
|
39
|
+
baseDuration * Math.pow(2.0, ~exp=errorCount.contents->Int.toFloat)->Float.toInt
|
|
40
40
|
timeoutIdRef := setTimeout(() => refreshEventSource(), Pervasives.min(delay, 60_000))
|
|
41
41
|
}
|
|
42
42
|
and refreshEventSource = () => {
|
|
@@ -100,7 +100,7 @@ let subscribe = (~hyperSyncUrl, ~apiToken, ~chainId, ~onHeight: int => unit): (u
|
|
|
100
100
|
})
|
|
101
101
|
|
|
102
102
|
es->EventSource.addEventListener("height", event => {
|
|
103
|
-
switch event.data->
|
|
103
|
+
switch event.data->Int.fromString {
|
|
104
104
|
| Some(height) =>
|
|
105
105
|
// Track the SSE height event
|
|
106
106
|
Prometheus.SourceRequestCount.increment(
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import * as Utils from "../Utils.res.mjs";
|
|
4
4
|
import * as Logging from "../Logging.res.mjs";
|
|
5
|
-
import * as Belt_Int from "@rescript/runtime/lib/es6/Belt_Int.js";
|
|
6
5
|
import * as Prometheus from "../Prometheus.res.mjs";
|
|
6
|
+
import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
|
|
7
7
|
import * as Eventsource from "eventsource";
|
|
8
8
|
import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
|
|
9
9
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
@@ -81,7 +81,7 @@ function subscribe(hyperSyncUrl, apiToken, chainId, onHeight) {
|
|
|
81
81
|
};
|
|
82
82
|
es$1.addEventListener("ping", _event => updateTimeoutId());
|
|
83
83
|
es$1.addEventListener("height", event => {
|
|
84
|
-
let height =
|
|
84
|
+
let height = Stdlib_Int.fromString(event.data, undefined);
|
|
85
85
|
if (height !== undefined) {
|
|
86
86
|
Prometheus.SourceRequestCount.increment("HyperSync", chainId, "heightStream");
|
|
87
87
|
updateTimeoutId();
|
|
@@ -201,9 +201,10 @@ Learn more or get a free API token at: https://envio.dev/app/api-tokens`)
|
|
|
201
201
|
|
|
202
202
|
Internal.Event({
|
|
203
203
|
eventConfig: (eventConfig :> Internal.eventConfig),
|
|
204
|
-
timestamp: block.timestamp->
|
|
204
|
+
timestamp: block.timestamp->Option.getUnsafe,
|
|
205
205
|
chain,
|
|
206
|
-
blockNumber: block.number->
|
|
206
|
+
blockNumber: block.number->Option.getUnsafe,
|
|
207
|
+
blockHash: block.hash->Option.getUnsafe,
|
|
207
208
|
logIndex,
|
|
208
209
|
event: {
|
|
209
210
|
contractName: eventConfig.contractName,
|
|
@@ -338,7 +339,7 @@ Learn more or get a free API token at: https://envio.dev/app/api-tokens`)
|
|
|
338
339
|
}
|
|
339
340
|
}
|
|
340
341
|
|
|
341
|
-
pageUnsafe.items->
|
|
342
|
+
pageUnsafe.items->Array.forEach(item => {
|
|
342
343
|
let chainId = chain->ChainMap.Chain.toChainId
|
|
343
344
|
let maybeEventConfig =
|
|
344
345
|
eventRouter->EventRouter.get(
|
|
@@ -348,7 +349,7 @@ Learn more or get a free API token at: https://envio.dev/app/api-tokens`)
|
|
|
348
349
|
),
|
|
349
350
|
~indexingAddresses,
|
|
350
351
|
~contractAddress=item.srcAddress,
|
|
351
|
-
~blockNumber=item.block.number->
|
|
352
|
+
~blockNumber=item.block.number->Option.getUnsafe,
|
|
352
353
|
)
|
|
353
354
|
|
|
354
355
|
switch maybeEventConfig {
|
|
@@ -363,7 +364,7 @@ Learn more or get a free API token at: https://envio.dev/app/api-tokens`)
|
|
|
363
364
|
handleDecodeFailure(
|
|
364
365
|
~eventConfig,
|
|
365
366
|
~logIndex=item.logIndex,
|
|
366
|
-
~blockNumber=item.block.number->
|
|
367
|
+
~blockNumber=item.block.number->Option.getUnsafe,
|
|
367
368
|
~chainId,
|
|
368
369
|
~exn=UndefinedValue,
|
|
369
370
|
)
|
|
@@ -378,7 +379,7 @@ Learn more or get a free API token at: https://envio.dev/app/api-tokens`)
|
|
|
378
379
|
// and the parent of the range's first block. Duplicates are allowed; reorg
|
|
379
380
|
// detection notices same-block-number-different-hash collisions itself.
|
|
380
381
|
let blockHashes = []
|
|
381
|
-
pageUnsafe.items->
|
|
382
|
+
pageUnsafe.items->Array.forEach(({block}) => {
|
|
382
383
|
switch (block.number, block.hash) {
|
|
383
384
|
| (Some(blockNumber), Some(blockHash)) =>
|
|
384
385
|
blockHashes->Array.push({ReorgDetection.blockNumber, blockHash})->ignore
|
|
@@ -405,9 +406,9 @@ Learn more or get a free API token at: https://envio.dev/app/api-tokens`)
|
|
|
405
406
|
let latestFetchedBlockTimestamp = switch pageUnsafe.rollbackGuard {
|
|
406
407
|
| Some({timestamp}) => timestamp
|
|
407
408
|
| None =>
|
|
408
|
-
switch pageUnsafe.items->
|
|
409
|
-
| Some({block}) if block.number->
|
|
410
|
-
block.timestamp->
|
|
409
|
+
switch pageUnsafe.items->Array.get(pageUnsafe.items->Array.length - 1) {
|
|
410
|
+
| Some({block}) if block.number->Option.getUnsafe == heighestBlockQueried =>
|
|
411
|
+
block.timestamp->Option.getUnsafe
|
|
411
412
|
| _ => 0
|
|
412
413
|
}
|
|
413
414
|
}
|
|
@@ -5,7 +5,6 @@ import * as Hrtime from "../bindings/Hrtime.res.mjs";
|
|
|
5
5
|
import * as Source from "./Source.res.mjs";
|
|
6
6
|
import * as Logging from "../Logging.res.mjs";
|
|
7
7
|
import * as HyperSync from "./HyperSync.res.mjs";
|
|
8
|
-
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
9
8
|
import * as Prometheus from "../Prometheus.res.mjs";
|
|
10
9
|
import * as EventRouter from "./EventRouter.res.mjs";
|
|
11
10
|
import * as LogSelection from "../LogSelection.res.mjs";
|
|
@@ -134,6 +133,7 @@ Learn more or get a free API token at: https://envio.dev/app/api-tokens`);
|
|
|
134
133
|
timestamp: block.timestamp,
|
|
135
134
|
chain: chain,
|
|
136
135
|
blockNumber: block.number,
|
|
136
|
+
blockHash: block.hash,
|
|
137
137
|
logIndex: logIndex,
|
|
138
138
|
event: {
|
|
139
139
|
contractName: eventConfig.contractName,
|
|
@@ -214,7 +214,7 @@ Learn more or get a free API token at: https://envio.dev/app/api-tokens`);
|
|
|
214
214
|
let heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
|
|
215
215
|
let parsingTimeRef = Hrtime.makeTimer();
|
|
216
216
|
let parsedQueueItems = [];
|
|
217
|
-
|
|
217
|
+
pageUnsafe.items.forEach(item => {
|
|
218
218
|
let maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(item.topic0, item.topicCount), item.srcAddress, item.block.number, indexingAddresses);
|
|
219
219
|
if (maybeEventConfig === undefined) {
|
|
220
220
|
return;
|
|
@@ -244,7 +244,7 @@ Learn more or get a free API token at: https://envio.dev/app/api-tokens`);
|
|
|
244
244
|
});
|
|
245
245
|
let parsingTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(parsingTimeRef));
|
|
246
246
|
let blockHashes = [];
|
|
247
|
-
|
|
247
|
+
pageUnsafe.items.forEach(param => {
|
|
248
248
|
let block = param.block;
|
|
249
249
|
let match = block.number;
|
|
250
250
|
let match$1 = block.hash;
|
|
@@ -272,7 +272,7 @@ Learn more or get a free API token at: https://envio.dev/app/api-tokens`);
|
|
|
272
272
|
if (match$1 !== undefined) {
|
|
273
273
|
latestFetchedBlockTimestamp = match$1.timestamp;
|
|
274
274
|
} else {
|
|
275
|
-
let match$2 =
|
|
275
|
+
let match$2 = pageUnsafe.items[pageUnsafe.items.length - 1 | 0];
|
|
276
276
|
if (match$2 !== undefined) {
|
|
277
277
|
let block = match$2.block;
|
|
278
278
|
latestFetchedBlockTimestamp = block.number === heighestBlockQueried ? block.timestamp : 0;
|
package/src/sources/Rpc.res
CHANGED
|
@@ -100,7 +100,7 @@ module GetLogs = {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
topics->
|
|
103
|
+
topics->Array.map(toTopicFilter)
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
let mapTopicQuery = ({topic0, topic1, topic2, topic3}: Internal.topicSelection): topicQuery =>
|
|
@@ -214,10 +214,6 @@ module GetBlockByNumber = {
|
|
|
214
214
|
let rawRoute = makeRpcRoute("eth_getBlockByNumber", paramsSchema, S.null(S.json(~validate=false)))
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
module GetBlockHeight = {
|
|
218
|
-
let route = makeRpcRoute("eth_blockNumber", S.tuple(_ => ()), hexIntSchema)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
217
|
module GetTransactionByHash = {
|
|
222
218
|
let rawRoute = makeRpcRoute(
|
|
223
219
|
"eth_getTransactionByHash",
|
package/src/sources/Rpc.res.mjs
CHANGED
|
@@ -4,7 +4,6 @@ import * as Rest from "../vendored/Rest.res.mjs";
|
|
|
4
4
|
import * as Viem from "viem";
|
|
5
5
|
import * as Utils from "../Utils.res.mjs";
|
|
6
6
|
import * as Address from "../Address.res.mjs";
|
|
7
|
-
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
8
7
|
import * as Stdlib_BigInt from "@rescript/runtime/lib/es6/Stdlib_BigInt.js";
|
|
9
8
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
10
9
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
@@ -124,7 +123,7 @@ function makeTopicQuery(topic0Opt, topic1Opt, topic2Opt, topic3Opt) {
|
|
|
124
123
|
let single = topic[0];
|
|
125
124
|
return single;
|
|
126
125
|
};
|
|
127
|
-
return
|
|
126
|
+
return topics.map(toTopicFilter);
|
|
128
127
|
}
|
|
129
128
|
|
|
130
129
|
function mapTopicQuery(param) {
|
|
@@ -210,12 +209,6 @@ let GetBlockByNumber = {
|
|
|
210
209
|
rawRoute: rawRoute
|
|
211
210
|
};
|
|
212
211
|
|
|
213
|
-
let route$2 = makeRpcRoute("eth_blockNumber", S$RescriptSchema.tuple(param => {}), hexIntSchema);
|
|
214
|
-
|
|
215
|
-
let GetBlockHeight = {
|
|
216
|
-
route: route$2
|
|
217
|
-
};
|
|
218
|
-
|
|
219
212
|
let rawRoute$1 = makeRpcRoute("eth_getTransactionByHash", S$RescriptSchema.tuple1(S$RescriptSchema.string), S$RescriptSchema.$$null(S$RescriptSchema.json(false)));
|
|
220
213
|
|
|
221
214
|
let GetTransactionByHash = {
|
|
@@ -257,7 +250,6 @@ export {
|
|
|
257
250
|
decimalFloatSchema,
|
|
258
251
|
GetLogs,
|
|
259
252
|
GetBlockByNumber,
|
|
260
|
-
GetBlockHeight,
|
|
261
253
|
GetTransactionByHash,
|
|
262
254
|
GetTransactionReceipt,
|
|
263
255
|
getLogs,
|