envio 2.32.6 → 2.32.8
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/package.json +6 -6
- package/src/bindings/EventSource.res +8 -1
- package/src/bindings/EventSource.res.js +7 -1
- package/src/sources/HyperSync.res +10 -2
- package/src/sources/HyperSync.res.js +9 -4
- package/src/sources/HyperSyncClient.res +2 -2
- package/src/sources/HyperSyncHeightStream.res +40 -114
- package/src/sources/HyperSyncHeightStream.res.js +44 -73
- package/src/sources/HyperSyncSource.res +15 -14
- package/src/sources/HyperSyncSource.res.js +27 -21
- package/src/sources/RpcSource.res +14 -15
- package/src/sources/RpcSource.res.js +15 -19
- package/src/sources/Source.res +1 -0
- package/src/sources/SourceManager.res +172 -95
- package/src/sources/SourceManager.res.js +150 -87
- package/src/sources/SourceManager.resi +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "envio",
|
|
3
|
-
"version": "v2.32.
|
|
3
|
+
"version": "v2.32.8",
|
|
4
4
|
"description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
|
|
5
5
|
"bin": "./bin.js",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://envio.dev",
|
|
27
27
|
"optionalDependencies": {
|
|
28
|
-
"envio-linux-x64": "v2.32.
|
|
29
|
-
"envio-linux-arm64": "v2.32.
|
|
30
|
-
"envio-darwin-x64": "v2.32.
|
|
31
|
-
"envio-darwin-arm64": "v2.32.
|
|
28
|
+
"envio-linux-x64": "v2.32.8",
|
|
29
|
+
"envio-linux-arm64": "v2.32.8",
|
|
30
|
+
"envio-darwin-x64": "v2.32.8",
|
|
31
|
+
"envio-darwin-arm64": "v2.32.8"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@elastic/ecs-pino-format": "1.4.0",
|
|
35
|
-
"@envio-dev/hypersync-client": "
|
|
35
|
+
"@envio-dev/hypersync-client": "1.1.0",
|
|
36
36
|
"@envio-dev/hyperfuel-client": "1.2.2",
|
|
37
37
|
"bignumber.js": "9.1.2",
|
|
38
38
|
"eventsource": "4.1.0",
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
type t
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
module Fetch = {
|
|
4
|
+
type args = {body?: unknown, headers?: dict<string>, method?: string, path?: string}
|
|
5
|
+
type t = (string, ~args: args) => promise<unknown>
|
|
6
|
+
// NOTE: don't try make the type t. Rescript 11 will curry the args which breaks
|
|
7
|
+
// keet the type inline. This is a workaround for now.
|
|
8
|
+
external fetch: (string, ~args: args) => promise<unknown> = "fetch"
|
|
9
|
+
}
|
|
10
|
+
type options = {fetch?: Fetch.t}
|
|
4
11
|
|
|
5
12
|
@module("eventsource") @new
|
|
6
13
|
external create: (~url: string, ~options: options=?) => t = "EventSource"
|
|
@@ -101,12 +101,20 @@ module GetLogs = {
|
|
|
101
101
|
~nonOptionalBlockFieldNames,
|
|
102
102
|
~nonOptionalTransactionFieldNames,
|
|
103
103
|
): logsQueryPageItem => {
|
|
104
|
+
// Remap "type" -> "kind" on the transaction object at runtime before validation.
|
|
105
|
+
// The latest hypersync client renamed "kind" to "type" but v2 consumers expect "kind".
|
|
106
|
+
let transaction: Js.Dict.t<unknown> = event.transaction->Utils.magic
|
|
107
|
+
switch transaction->Js.Dict.get("type") {
|
|
108
|
+
| Some(v) => transaction->Js.Dict.set("kind", v)
|
|
109
|
+
| None => ()
|
|
110
|
+
}
|
|
111
|
+
|
|
104
112
|
let missingParams = []
|
|
105
113
|
missingParams->addMissingParams(Log.fieldNames, event.log, ~prefix="log")
|
|
106
114
|
missingParams->addMissingParams(nonOptionalBlockFieldNames, event.block, ~prefix="block")
|
|
107
115
|
missingParams->addMissingParams(
|
|
108
116
|
nonOptionalTransactionFieldNames,
|
|
109
|
-
|
|
117
|
+
transaction->Utils.magic,
|
|
110
118
|
~prefix="transaction",
|
|
111
119
|
)
|
|
112
120
|
if missingParams->Array.length > 0 {
|
|
@@ -126,7 +134,7 @@ module GetLogs = {
|
|
|
126
134
|
{
|
|
127
135
|
log,
|
|
128
136
|
block: event.block->Utils.magic,
|
|
129
|
-
transaction:
|
|
137
|
+
transaction: transaction->Utils.magic,
|
|
130
138
|
}
|
|
131
139
|
}
|
|
132
140
|
|
|
@@ -6,6 +6,7 @@ var Time = require("../Time.res.js");
|
|
|
6
6
|
var Utils = require("../Utils.res.js");
|
|
7
7
|
var $$BigInt = require("../bindings/BigInt.res.js");
|
|
8
8
|
var Js_exn = require("rescript/lib/js/js_exn.js");
|
|
9
|
+
var Js_dict = require("rescript/lib/js/js_dict.js");
|
|
9
10
|
var Logging = require("../Logging.res.js");
|
|
10
11
|
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
11
12
|
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
|
@@ -75,6 +76,11 @@ async function query(client, fromBlock, toBlock, logSelections, fieldSelection,
|
|
|
75
76
|
};
|
|
76
77
|
}
|
|
77
78
|
var items = Belt_Array.map(res.data, (function (item) {
|
|
79
|
+
var transaction = item.transaction;
|
|
80
|
+
var v = Js_dict.get(transaction, "type");
|
|
81
|
+
if (v !== undefined) {
|
|
82
|
+
transaction["kind"] = Caml_option.valFromOption(v);
|
|
83
|
+
}
|
|
78
84
|
var missingParams = [];
|
|
79
85
|
var returnedObj = item.log;
|
|
80
86
|
if (Utils.$$Array.notEmpty(fieldNames)) {
|
|
@@ -108,12 +114,11 @@ async function query(client, fromBlock, toBlock, logSelections, fieldSelection,
|
|
|
108
114
|
missingParams.push("block");
|
|
109
115
|
}
|
|
110
116
|
}
|
|
111
|
-
var returnedObj$2 = item.transaction;
|
|
112
117
|
if (Utils.$$Array.notEmpty(nonOptionalTransactionFieldNames)) {
|
|
113
|
-
if (
|
|
118
|
+
if (transaction) {
|
|
114
119
|
for(var idx$2 = 0 ,idx_finish$2 = nonOptionalTransactionFieldNames.length; idx$2 < idx_finish$2; ++idx$2){
|
|
115
120
|
var fieldName$2 = nonOptionalTransactionFieldNames[idx$2];
|
|
116
|
-
var match$2 =
|
|
121
|
+
var match$2 = transaction[fieldName$2];
|
|
117
122
|
if (match$2 !== undefined) {
|
|
118
123
|
|
|
119
124
|
} else {
|
|
@@ -154,7 +159,7 @@ async function query(client, fromBlock, toBlock, logSelections, fieldSelection,
|
|
|
154
159
|
return {
|
|
155
160
|
log: log,
|
|
156
161
|
block: item.block,
|
|
157
|
-
transaction:
|
|
162
|
+
transaction: transaction
|
|
158
163
|
};
|
|
159
164
|
}));
|
|
160
165
|
return {
|
|
@@ -88,7 +88,7 @@ module QueryTypes = {
|
|
|
88
88
|
| GasUsed
|
|
89
89
|
| ContractAddress
|
|
90
90
|
| LogsBloom
|
|
91
|
-
|
|
|
91
|
+
| Type
|
|
92
92
|
| Root
|
|
93
93
|
| Status
|
|
94
94
|
| L1Fee
|
|
@@ -383,7 +383,7 @@ module ResponseTypes = {
|
|
|
383
383
|
gasUsed?: bigint,
|
|
384
384
|
contractAddress?: string,
|
|
385
385
|
logsBloom?: string,
|
|
386
|
-
|
|
386
|
+
@as("type") type_?: int,
|
|
387
387
|
root?: string,
|
|
388
388
|
status?: int,
|
|
389
389
|
l1Fee?: bigint,
|
|
@@ -1,28 +1,15 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Pure
|
|
2
|
+
Pure subscription-based implementation of the HyperSync height stream.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
timeoutIdRef
|
|
9
|
-
eventsourceRef: ref<option<EventSource.t>>,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
let make = (~hyperSyncUrl, ~apiToken) => {
|
|
13
|
-
/**
|
|
14
|
-
On every successful ping or height event, clear the timeout and set a new one.
|
|
5
|
+
let subscribe = (~hyperSyncUrl, ~apiToken, ~onHeight: int => unit): (unit => unit) => {
|
|
6
|
+
let eventsourceRef = ref(None)
|
|
7
|
+
// Timeout doesn't do anything for initialization
|
|
8
|
+
let timeoutIdRef = ref(Js.Global.setTimeout(() => (), 0))
|
|
15
9
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let rec updateTimeoutId = (
|
|
19
|
-
~eventsourceRef: ref<option<EventSource.t>>,
|
|
20
|
-
~timeoutIdRef: ref<Js.Global.timeoutId>,
|
|
21
|
-
~hyperSyncUrl,
|
|
22
|
-
~apiToken,
|
|
23
|
-
~heightRef: ref<int>,
|
|
24
|
-
~errorRef: ref<option<string>>,
|
|
25
|
-
) => {
|
|
10
|
+
// On every successful ping or height event, clear the timeout and set a new one.
|
|
11
|
+
// If the timeout lapses, close and reconnect the EventSource.
|
|
12
|
+
let rec updateTimeoutId = () => {
|
|
26
13
|
timeoutIdRef.contents->Js.Global.clearTimeout
|
|
27
14
|
|
|
28
15
|
// Should receive a ping at least every 5s, so 15s is a safe margin
|
|
@@ -34,31 +21,15 @@ let make = (~hyperSyncUrl, ~apiToken) => {
|
|
|
34
21
|
"url": hyperSyncUrl,
|
|
35
22
|
"staleTimeMillis": staleTimeMillis,
|
|
36
23
|
})
|
|
37
|
-
refreshEventSource(
|
|
38
|
-
~eventsourceRef,
|
|
39
|
-
~hyperSyncUrl,
|
|
40
|
-
~apiToken,
|
|
41
|
-
~heightRef,
|
|
42
|
-
~errorRef,
|
|
43
|
-
~timeoutIdRef,
|
|
44
|
-
)
|
|
24
|
+
refreshEventSource()
|
|
45
25
|
}, staleTimeMillis)
|
|
46
26
|
|
|
47
27
|
timeoutIdRef := newTimeoutId
|
|
48
28
|
}
|
|
49
|
-
and
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*/
|
|
54
|
-
refreshEventSource = (
|
|
55
|
-
~eventsourceRef: ref<option<EventSource.t>>,
|
|
56
|
-
~hyperSyncUrl,
|
|
57
|
-
~apiToken,
|
|
58
|
-
~heightRef: ref<int>,
|
|
59
|
-
~errorRef: ref<option<string>>,
|
|
60
|
-
~timeoutIdRef: ref<Js.Global.timeoutId>,
|
|
61
|
-
) => {
|
|
29
|
+
// Instantiate a new EventSource and set it to the shared refs.
|
|
30
|
+
// Add the necessary event listeners, handle errors
|
|
31
|
+
// and update the timeout.
|
|
32
|
+
and refreshEventSource = () => {
|
|
62
33
|
// Close the old EventSource if it exists (on a new connection after timeout)
|
|
63
34
|
switch eventsourceRef.contents {
|
|
64
35
|
| Some(es) => es->EventSource.close
|
|
@@ -69,17 +40,25 @@ let make = (~hyperSyncUrl, ~apiToken) => {
|
|
|
69
40
|
let es = EventSource.create(
|
|
70
41
|
~url=`${hyperSyncUrl}/height/sse`,
|
|
71
42
|
~options={
|
|
72
|
-
|
|
73
|
-
(
|
|
74
|
-
|
|
75
|
-
|
|
43
|
+
fetch: (url, ~args) => {
|
|
44
|
+
EventSource.Fetch.fetch(
|
|
45
|
+
url,
|
|
46
|
+
~args={
|
|
47
|
+
...args,
|
|
48
|
+
headers: Js.Dict.fromArray([
|
|
49
|
+
("Authorization", `Bearer ${apiToken}`),
|
|
50
|
+
("User-Agent", userAgent),
|
|
51
|
+
]),
|
|
52
|
+
},
|
|
53
|
+
)
|
|
54
|
+
},
|
|
76
55
|
},
|
|
77
56
|
)
|
|
78
57
|
|
|
79
58
|
// Set the new EventSource to the shared ref
|
|
80
59
|
eventsourceRef := Some(es)
|
|
81
60
|
// Update the timeout in case connection goes stale
|
|
82
|
-
updateTimeoutId(
|
|
61
|
+
updateTimeoutId()
|
|
83
62
|
|
|
84
63
|
es->EventSource.onopen(_ => {
|
|
85
64
|
Logging.trace({"msg": "SSE connection opened for height stream", "url": hyperSyncUrl})
|
|
@@ -90,90 +69,37 @@ let make = (~hyperSyncUrl, ~apiToken) => {
|
|
|
90
69
|
"msg": "EventSource error",
|
|
91
70
|
"error": error->Js.Exn.message,
|
|
92
71
|
})
|
|
93
|
-
// On errors, set the error ref
|
|
94
|
-
// so that getHeight can raise an error
|
|
95
|
-
errorRef :=
|
|
96
|
-
Some(error->Js.Exn.message->Belt.Option.getWithDefault("Unexpected no error.message"))
|
|
97
72
|
})
|
|
98
73
|
|
|
99
74
|
es->EventSource.addEventListener("ping", _event => {
|
|
100
75
|
// ping lets us know from the server that the connection is still alive
|
|
101
|
-
// and that the height hasn't updated for
|
|
76
|
+
// and that the height hasn't updated for 5 seconds
|
|
102
77
|
// update the timeout on each successful ping received
|
|
103
|
-
updateTimeoutId(
|
|
104
|
-
~eventsourceRef,
|
|
105
|
-
~timeoutIdRef,
|
|
106
|
-
~hyperSyncUrl,
|
|
107
|
-
~apiToken,
|
|
108
|
-
~heightRef,
|
|
109
|
-
~errorRef,
|
|
110
|
-
)
|
|
111
|
-
// reset the error ref, since we had a successful ping
|
|
112
|
-
errorRef := None
|
|
78
|
+
updateTimeoutId()
|
|
113
79
|
})
|
|
114
80
|
|
|
115
81
|
es->EventSource.addEventListener("height", event => {
|
|
116
82
|
switch event.data->Belt.Int.fromString {
|
|
117
83
|
| Some(height) =>
|
|
118
84
|
// On a successful height event, update the timeout
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
~timeoutIdRef,
|
|
123
|
-
~hyperSyncUrl,
|
|
124
|
-
~apiToken,
|
|
125
|
-
~heightRef,
|
|
126
|
-
~errorRef,
|
|
127
|
-
)
|
|
128
|
-
errorRef := None
|
|
129
|
-
// Set the actual height ref
|
|
130
|
-
heightRef := height
|
|
85
|
+
updateTimeoutId()
|
|
86
|
+
// Call the callback with the new height
|
|
87
|
+
onHeight(height)
|
|
131
88
|
| None =>
|
|
132
89
|
Logging.trace({"msg": "Height was not a number in event.data", "data": event.data})
|
|
133
|
-
errorRef := Some("Height was not a number in event.data")
|
|
134
90
|
}
|
|
135
91
|
})
|
|
136
92
|
}
|
|
137
93
|
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
let heightRef = ref(0)
|
|
141
|
-
let errorRef = ref(None)
|
|
142
|
-
let eventsourceRef = ref(None)
|
|
143
|
-
// Timeout doesn't do anything for initalization
|
|
144
|
-
let timeoutIdRef = ref(Js.Global.setTimeout(() => (), 0))
|
|
145
|
-
refreshEventSource(
|
|
146
|
-
~eventsourceRef,
|
|
147
|
-
~hyperSyncUrl,
|
|
148
|
-
~apiToken,
|
|
149
|
-
~heightRef,
|
|
150
|
-
~errorRef,
|
|
151
|
-
~timeoutIdRef,
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
{
|
|
155
|
-
heightRef,
|
|
156
|
-
errorRef,
|
|
157
|
-
timeoutIdRef,
|
|
158
|
-
eventsourceRef,
|
|
159
|
-
}
|
|
160
|
-
}
|
|
94
|
+
// Start the EventSource connection
|
|
95
|
+
refreshEventSource()
|
|
161
96
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
| Some(error) => Js.Exn.raiseError(error)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
let close = t => {
|
|
174
|
-
t.timeoutIdRef.contents->Js.Global.clearTimeout
|
|
175
|
-
switch t.eventsourceRef.contents {
|
|
176
|
-
| Some(es) => es->EventSource.close
|
|
177
|
-
| None => ()
|
|
97
|
+
// Return unsubscribe function
|
|
98
|
+
() => {
|
|
99
|
+
timeoutIdRef.contents->Js.Global.clearTimeout
|
|
100
|
+
switch eventsourceRef.contents {
|
|
101
|
+
| Some(es) => es->EventSource.close
|
|
102
|
+
| None => ()
|
|
103
|
+
}
|
|
178
104
|
}
|
|
179
105
|
}
|
|
@@ -2,16 +2,23 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var Utils = require("../Utils.res.js");
|
|
5
|
-
var Js_exn = require("rescript/lib/js/js_exn.js");
|
|
6
5
|
var Js_dict = require("rescript/lib/js/js_dict.js");
|
|
7
6
|
var Logging = require("../Logging.res.js");
|
|
8
7
|
var Belt_Int = require("rescript/lib/js/belt_Int.js");
|
|
9
|
-
var
|
|
8
|
+
var Caml_obj = require("rescript/lib/js/caml_obj.js");
|
|
10
9
|
var Caml_option = require("rescript/lib/js/caml_option.js");
|
|
11
10
|
var Eventsource = require("eventsource");
|
|
12
11
|
|
|
13
|
-
function
|
|
14
|
-
var
|
|
12
|
+
function subscribe(hyperSyncUrl, apiToken, onHeight) {
|
|
13
|
+
var eventsourceRef = {
|
|
14
|
+
contents: undefined
|
|
15
|
+
};
|
|
16
|
+
var timeoutIdRef = {
|
|
17
|
+
contents: setTimeout((function () {
|
|
18
|
+
|
|
19
|
+
}), 0)
|
|
20
|
+
};
|
|
21
|
+
var updateTimeoutId = function () {
|
|
15
22
|
clearTimeout(timeoutIdRef.contents);
|
|
16
23
|
var newTimeoutId = setTimeout((function () {
|
|
17
24
|
Logging.trace({
|
|
@@ -19,30 +26,33 @@ function make(hyperSyncUrl, apiToken) {
|
|
|
19
26
|
url: hyperSyncUrl,
|
|
20
27
|
staleTimeMillis: 15000
|
|
21
28
|
});
|
|
22
|
-
refreshEventSource(
|
|
29
|
+
refreshEventSource();
|
|
23
30
|
}), 15000);
|
|
24
31
|
timeoutIdRef.contents = newTimeoutId;
|
|
25
32
|
};
|
|
26
|
-
var refreshEventSource = function (
|
|
33
|
+
var refreshEventSource = function () {
|
|
27
34
|
var es = eventsourceRef.contents;
|
|
28
35
|
if (es !== undefined) {
|
|
29
36
|
Caml_option.valFromOption(es).close();
|
|
30
37
|
}
|
|
31
38
|
var userAgent = "hyperindex/" + Utils.EnvioPackage.json.version;
|
|
32
39
|
var es$1 = new Eventsource.EventSource(hyperSyncUrl + "/height/sse", {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
fetch: (function (url, args) {
|
|
41
|
+
var newrecord = Caml_obj.obj_dup(args);
|
|
42
|
+
return fetch(url, (newrecord.headers = Js_dict.fromArray([
|
|
43
|
+
[
|
|
44
|
+
"Authorization",
|
|
45
|
+
"Bearer " + apiToken
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
"User-Agent",
|
|
49
|
+
userAgent
|
|
50
|
+
]
|
|
51
|
+
]), newrecord));
|
|
52
|
+
})
|
|
43
53
|
});
|
|
44
54
|
eventsourceRef.contents = Caml_option.some(es$1);
|
|
45
|
-
updateTimeoutId(
|
|
55
|
+
updateTimeoutId();
|
|
46
56
|
es$1.onopen = (function () {
|
|
47
57
|
Logging.trace({
|
|
48
58
|
msg: "SSE connection opened for height stream",
|
|
@@ -54,73 +64,34 @@ function make(hyperSyncUrl, apiToken) {
|
|
|
54
64
|
msg: "EventSource error",
|
|
55
65
|
error: error.message
|
|
56
66
|
});
|
|
57
|
-
errorRef.contents = Belt_Option.getWithDefault(error.message, "Unexpected no error.message");
|
|
58
67
|
});
|
|
59
68
|
es$1.addEventListener("ping", (function (_event) {
|
|
60
|
-
updateTimeoutId(
|
|
61
|
-
errorRef.contents = undefined;
|
|
69
|
+
updateTimeoutId();
|
|
62
70
|
}));
|
|
63
71
|
es$1.addEventListener("height", (function ($$event) {
|
|
64
72
|
var height = Belt_Int.fromString($$event.data);
|
|
65
73
|
if (height !== undefined) {
|
|
66
|
-
updateTimeoutId(
|
|
67
|
-
|
|
68
|
-
heightRef.contents = height;
|
|
74
|
+
updateTimeoutId();
|
|
75
|
+
return onHeight(height);
|
|
69
76
|
} else {
|
|
70
|
-
Logging.trace({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
errorRef.contents = "Height was not a number in event.data";
|
|
77
|
+
return Logging.trace({
|
|
78
|
+
msg: "Height was not a number in event.data",
|
|
79
|
+
data: $$event.data
|
|
80
|
+
});
|
|
75
81
|
}
|
|
76
82
|
}));
|
|
77
83
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
var timeoutIdRef = {
|
|
88
|
-
contents: setTimeout((function () {
|
|
89
|
-
|
|
90
|
-
}), 0)
|
|
91
|
-
};
|
|
92
|
-
refreshEventSource(eventsourceRef, hyperSyncUrl, apiToken, heightRef, errorRef, timeoutIdRef);
|
|
93
|
-
return {
|
|
94
|
-
heightRef: heightRef,
|
|
95
|
-
errorRef: errorRef,
|
|
96
|
-
timeoutIdRef: timeoutIdRef,
|
|
97
|
-
eventsourceRef: eventsourceRef
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async function getHeight(t) {
|
|
102
|
-
while(t.heightRef.contents === 0 && t.errorRef.contents === undefined) {
|
|
103
|
-
await Utils.delay(200);
|
|
84
|
+
refreshEventSource();
|
|
85
|
+
return function () {
|
|
86
|
+
clearTimeout(timeoutIdRef.contents);
|
|
87
|
+
var es = eventsourceRef.contents;
|
|
88
|
+
if (es !== undefined) {
|
|
89
|
+
Caml_option.valFromOption(es).close();
|
|
90
|
+
return ;
|
|
91
|
+
}
|
|
92
|
+
|
|
104
93
|
};
|
|
105
|
-
var error = t.errorRef.contents;
|
|
106
|
-
if (error !== undefined) {
|
|
107
|
-
return Js_exn.raiseError(error);
|
|
108
|
-
} else {
|
|
109
|
-
return t.heightRef.contents;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function close(t) {
|
|
114
|
-
clearTimeout(t.timeoutIdRef.contents);
|
|
115
|
-
var es = t.eventsourceRef.contents;
|
|
116
|
-
if (es !== undefined) {
|
|
117
|
-
Caml_option.valFromOption(es).close();
|
|
118
|
-
return ;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
94
|
}
|
|
122
95
|
|
|
123
|
-
exports.
|
|
124
|
-
exports.getHeight = getHeight;
|
|
125
|
-
exports.close = close;
|
|
96
|
+
exports.subscribe = subscribe;
|
|
126
97
|
/* Utils Not a pure module */
|
|
@@ -73,7 +73,10 @@ let getSelectionConfig = (selection: FetchState.selection, ~chain) => {
|
|
|
73
73
|
->(Utils.magic: array<string> => array<HyperSyncClient.QueryTypes.blockField>),
|
|
74
74
|
transaction: capitalizedTransactionFields
|
|
75
75
|
->Utils.Set.toArray
|
|
76
|
-
->(Utils.magic: array<string> => array<HyperSyncClient.QueryTypes.transactionField>)
|
|
76
|
+
->(Utils.magic: array<string> => array<HyperSyncClient.QueryTypes.transactionField>)
|
|
77
|
+
->// Currently the api for underlying "Type" field is still "Kind"
|
|
78
|
+
// transform this to use the new client
|
|
79
|
+
Array.map(field => (field :> string) !== "Kind" ? field : Type),
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
let noAddressesLogSelection = LogSelection.make(
|
|
@@ -551,32 +554,30 @@ let make = (
|
|
|
551
554
|
~logger,
|
|
552
555
|
)->Promise.thenResolve(HyperSync.mapExn)
|
|
553
556
|
|
|
554
|
-
let
|
|
557
|
+
let jsonApiClient = Rest.client(endpointUrl)
|
|
555
558
|
|
|
556
|
-
let
|
|
559
|
+
let malformedTokenMessage = `Your token is malformed. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens.`
|
|
557
560
|
|
|
558
561
|
{
|
|
559
562
|
name,
|
|
560
563
|
sourceFor: Sync,
|
|
561
564
|
chain,
|
|
562
|
-
pollingInterval:
|
|
565
|
+
pollingInterval: 100,
|
|
563
566
|
poweredByHyperSync: true,
|
|
564
567
|
getBlockHashes,
|
|
565
|
-
getHeightOrThrow: async () =>
|
|
566
|
-
|
|
567
|
-
|
|
|
568
|
-
|
|
569
|
-
->Js.Exn.message
|
|
570
|
-
->Option.getWithDefault("")
|
|
571
|
-
->Js.String2.includes(malformedTokenMessage) =>
|
|
568
|
+
getHeightOrThrow: async () =>
|
|
569
|
+
switch await HyperSyncJsonApi.heightRoute->Rest.fetch(apiToken, ~client=jsonApiClient) {
|
|
570
|
+
| Value(height) => height
|
|
571
|
+
| ErrorMessage(m) if m === malformedTokenMessage =>
|
|
572
572
|
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`)
|
|
573
573
|
// Don't want to retry if the token is malformed
|
|
574
574
|
// So just block forever
|
|
575
575
|
let _ = await Promise.make((_, _) => ())
|
|
576
576
|
0
|
|
577
|
-
|
|
|
578
|
-
}
|
|
579
|
-
},
|
|
577
|
+
| ErrorMessage(m) => Js.Exn.raiseError(m)
|
|
578
|
+
},
|
|
580
579
|
getItemsOrThrow,
|
|
580
|
+
createHeightSubscription: (~onHeight) =>
|
|
581
|
+
HyperSyncHeightStream.subscribe(~hyperSyncUrl=endpointUrl, ~apiToken, ~onHeight),
|
|
581
582
|
}
|
|
582
583
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
var Rest = require("../vendored/Rest.res.js");
|
|
4
5
|
var Viem = require("../bindings/Viem.res.js");
|
|
5
6
|
var Utils = require("../Utils.res.js");
|
|
6
7
|
var Hrtime = require("../bindings/Hrtime.res.js");
|
|
@@ -16,6 +17,7 @@ var ErrorHandling = require("../ErrorHandling.res.js");
|
|
|
16
17
|
var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
|
|
17
18
|
var HyperSyncClient = require("./HyperSyncClient.res.js");
|
|
18
19
|
var Caml_splice_call = require("rescript/lib/js/caml_splice_call.js");
|
|
20
|
+
var HyperSyncJsonApi = require("./HyperSyncJsonApi.res.js");
|
|
19
21
|
var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
|
|
20
22
|
var HyperSyncHeightStream = require("./HyperSyncHeightStream.res.js");
|
|
21
23
|
|
|
@@ -51,7 +53,13 @@ function getSelectionConfig(selection, chain) {
|
|
|
51
53
|
Caml_splice_call.spliceObjApply(noAddressesTopicSelections, "push", [tmp]);
|
|
52
54
|
}));
|
|
53
55
|
var fieldSelection_block = Array.from(capitalizedBlockFields);
|
|
54
|
-
var fieldSelection_transaction = Array.from(capitalizedTransactionFields)
|
|
56
|
+
var fieldSelection_transaction = Belt_Array.map(Array.from(capitalizedTransactionFields), (function (field) {
|
|
57
|
+
if (field !== "Kind") {
|
|
58
|
+
return field;
|
|
59
|
+
} else {
|
|
60
|
+
return "Type";
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
55
63
|
var fieldSelection_log = [
|
|
56
64
|
"Address",
|
|
57
65
|
"Data",
|
|
@@ -384,38 +392,36 @@ function make(param) {
|
|
|
384
392
|
var getBlockHashes = function (blockNumbers, logger) {
|
|
385
393
|
return HyperSync.queryBlockDataMulti(endpointUrl, apiToken, blockNumbers, logger).then(HyperSync.mapExn);
|
|
386
394
|
};
|
|
387
|
-
var
|
|
395
|
+
var jsonApiClient = Rest.client(endpointUrl, undefined);
|
|
388
396
|
return {
|
|
389
397
|
name: "HyperSync",
|
|
390
398
|
sourceFor: "Sync",
|
|
391
399
|
chain: chain,
|
|
392
400
|
poweredByHyperSync: true,
|
|
393
|
-
pollingInterval:
|
|
401
|
+
pollingInterval: 100,
|
|
394
402
|
getBlockHashes: getBlockHashes,
|
|
395
403
|
getHeightOrThrow: (async function () {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
return 0;
|
|
408
|
-
}
|
|
409
|
-
throw exn;
|
|
410
|
-
}
|
|
411
|
-
throw exn;
|
|
404
|
+
var height = await Rest.$$fetch(HyperSyncJsonApi.heightRoute, apiToken, jsonApiClient);
|
|
405
|
+
if (typeof height === "number") {
|
|
406
|
+
return height;
|
|
407
|
+
} else if (height === "Your token is malformed. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens.") {
|
|
408
|
+
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");
|
|
409
|
+
await new Promise((function (param, param$1) {
|
|
410
|
+
|
|
411
|
+
}));
|
|
412
|
+
return 0;
|
|
413
|
+
} else {
|
|
414
|
+
return Js_exn.raiseError(height);
|
|
412
415
|
}
|
|
413
416
|
}),
|
|
414
|
-
getItemsOrThrow: getItemsOrThrow
|
|
417
|
+
getItemsOrThrow: getItemsOrThrow,
|
|
418
|
+
createHeightSubscription: (function (onHeight) {
|
|
419
|
+
return HyperSyncHeightStream.subscribe(endpointUrl, apiToken, onHeight);
|
|
420
|
+
})
|
|
415
421
|
};
|
|
416
422
|
}
|
|
417
423
|
|
|
418
424
|
exports.getSelectionConfig = getSelectionConfig;
|
|
419
425
|
exports.memoGetSelectionConfig = memoGetSelectionConfig;
|
|
420
426
|
exports.make = make;
|
|
421
|
-
/*
|
|
427
|
+
/* Rest Not a pure module */
|