envio 3.0.2 → 3.1.0-rc.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/README.md +0 -1
- package/evm.schema.json +15 -8
- package/fuel.schema.json +19 -12
- package/index.d.ts +0 -2
- package/package.json +6 -7
- package/rescript.json +1 -1
- package/src/Batch.res +4 -214
- package/src/Batch.res.mjs +6 -165
- package/src/ChainFetcher.res +4 -5
- package/src/ChainFetcher.res.mjs +6 -7
- package/src/ChainManager.res +10 -9
- package/src/ChainManager.res.mjs +6 -10
- package/src/Config.res +9 -25
- package/src/Config.res.mjs +17 -27
- package/src/Core.res +7 -0
- package/src/Ctx.res +1 -0
- package/src/Env.res +0 -1
- package/src/Env.res.mjs +0 -3
- package/src/EventConfigBuilder.res +13 -123
- package/src/EventConfigBuilder.res.mjs +6 -73
- package/src/EventProcessing.res +5 -29
- package/src/EventProcessing.res.mjs +11 -20
- package/src/EventUtils.res +0 -27
- package/src/EventUtils.res.mjs +0 -24
- package/src/FetchState.res +1 -11
- package/src/FetchState.res.mjs +2 -16
- package/src/GlobalState.res +23 -37
- package/src/GlobalState.res.mjs +10 -38
- package/src/HandlerLoader.res +6 -5
- package/src/HandlerLoader.res.mjs +27 -9
- package/src/HandlerRegister.res +1 -12
- package/src/HandlerRegister.res.mjs +1 -6
- package/src/HandlerRegister.resi +1 -1
- package/src/Hasura.res +96 -32
- package/src/Hasura.res.mjs +93 -38
- package/src/InMemoryStore.res +181 -45
- package/src/InMemoryStore.res.mjs +143 -40
- package/src/InMemoryTable.res +147 -247
- package/src/InMemoryTable.res.mjs +131 -230
- package/src/Internal.res +10 -34
- package/src/Internal.res.mjs +9 -3
- package/src/LoadLayer.res +5 -5
- package/src/LoadLayer.res.mjs +5 -5
- package/src/Main.res +4 -6
- package/src/Main.res.mjs +26 -15
- package/src/Persistence.res +7 -132
- package/src/Persistence.res.mjs +1 -102
- package/src/PgStorage.res +57 -40
- package/src/PgStorage.res.mjs +60 -34
- package/src/ReorgDetection.res +35 -58
- package/src/ReorgDetection.res.mjs +21 -29
- package/src/SimulateItems.res.mjs +21 -3
- package/src/Sink.res +2 -2
- package/src/Sink.res.mjs +1 -1
- package/src/TableIndices.res +9 -2
- package/src/TableIndices.res.mjs +7 -1
- package/src/TestIndexer.res +53 -60
- package/src/TestIndexer.res.mjs +77 -63
- package/src/TestIndexerProxyStorage.res +4 -14
- package/src/TestIndexerProxyStorage.res.mjs +1 -5
- package/src/UserContext.res +2 -4
- package/src/UserContext.res.mjs +4 -5
- package/src/Utils.res +0 -2
- package/src/Utils.res.mjs +0 -3
- package/src/bindings/ClickHouse.res +45 -38
- package/src/bindings/ClickHouse.res.mjs +16 -17
- package/src/bindings/Vitest.res +3 -0
- package/src/db/InternalTable.res +59 -18
- package/src/db/InternalTable.res.mjs +82 -51
- package/src/db/Table.res +9 -2
- package/src/db/Table.res.mjs +10 -7
- package/src/sources/EvmChain.res +32 -9
- package/src/sources/EvmChain.res.mjs +31 -4
- package/src/sources/HyperFuelSource.res +14 -57
- package/src/sources/HyperFuelSource.res.mjs +18 -38
- package/src/sources/HyperSync.res +36 -101
- package/src/sources/HyperSync.res.mjs +42 -96
- package/src/sources/HyperSync.resi +4 -22
- package/src/sources/HyperSyncClient.res +67 -245
- package/src/sources/HyperSyncClient.res.mjs +47 -46
- package/src/sources/HyperSyncSource.res +76 -147
- package/src/sources/HyperSyncSource.res.mjs +61 -114
- package/src/sources/RpcSource.res +43 -22
- package/src/sources/RpcSource.res.mjs +50 -35
- package/src/sources/SimulateSource.res +1 -7
- package/src/sources/SimulateSource.res.mjs +1 -7
- package/src/sources/Source.res +8 -1
- package/src/sources/SourceManager.res +9 -0
- package/src/sources/SourceManager.res.mjs +10 -0
- package/src/sources/SourceManager.resi +2 -0
- package/svm.schema.json +11 -4
|
@@ -12,7 +12,6 @@ import * as EventRouter from "./EventRouter.res.mjs";
|
|
|
12
12
|
import * as ErrorHandling from "../ErrorHandling.res.mjs";
|
|
13
13
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
14
14
|
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
15
|
-
import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.js";
|
|
16
15
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
17
16
|
|
|
18
17
|
let EventRoutingFailed = /* @__PURE__ */Primitive_exceptions.create("HyperFuelSource.EventRoutingFailed");
|
|
@@ -182,7 +181,6 @@ function make(param) {
|
|
|
182
181
|
let name = "HyperFuel";
|
|
183
182
|
let getSelectionConfig = memoGetSelectionConfig(chain);
|
|
184
183
|
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, indexingAddresses, knownHeight, param, selection, retry, logger) => {
|
|
185
|
-
let mkLogAndRaise = (extra, extra$1) => ErrorHandling.mkLogAndRaise(logger, extra, extra$1);
|
|
186
184
|
let totalTimeRef = Hrtime.makeTimer();
|
|
187
185
|
let selectionConfig = getSelectionConfig(selection);
|
|
188
186
|
let recieptsSelection = selectionConfig.getRecieptsSelection(addressesByContractName);
|
|
@@ -238,34 +236,6 @@ function make(param) {
|
|
|
238
236
|
let pageFetchTime = Hrtime.toSecondsFloat(Hrtime.timeSince(startFetchingBatchTimeRef));
|
|
239
237
|
let knownHeight$1 = pageUnsafe.archiveHeight;
|
|
240
238
|
let heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
|
|
241
|
-
let match = Belt_Array.get(pageUnsafe.items, pageUnsafe.items.length - 1 | 0);
|
|
242
|
-
let lastBlockQueriedPromise;
|
|
243
|
-
let exit = 0;
|
|
244
|
-
if (match !== undefined) {
|
|
245
|
-
let block = match.block;
|
|
246
|
-
if (block.height === heighestBlockQueried) {
|
|
247
|
-
lastBlockQueriedPromise = Promise.resolve({
|
|
248
|
-
blockHash: block.id,
|
|
249
|
-
blockNumber: block.height,
|
|
250
|
-
blockTimestamp: block.time
|
|
251
|
-
});
|
|
252
|
-
} else {
|
|
253
|
-
exit = 1;
|
|
254
|
-
}
|
|
255
|
-
} else {
|
|
256
|
-
exit = 1;
|
|
257
|
-
}
|
|
258
|
-
if (exit === 1) {
|
|
259
|
-
lastBlockQueriedPromise = Stdlib_Promise.$$catch(HyperFuel.queryBlockData(endpointUrl, heighestBlockQueried, logger).then(res => {
|
|
260
|
-
if (res !== undefined) {
|
|
261
|
-
return res;
|
|
262
|
-
} else {
|
|
263
|
-
return mkLogAndRaise(`Failure, blockData for block ` + heighestBlockQueried.toString() + ` unexpectedly returned None`, {
|
|
264
|
-
RE_EXN_ID: "Not_found"
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
}), exn => mkLogAndRaise(`Failed to query blockData for block ` + heighestBlockQueried.toString(), exn));
|
|
268
|
-
}
|
|
269
239
|
let parsingTimeRef = Hrtime.makeTimer();
|
|
270
240
|
let parsedQueueItems = pageUnsafe.items.map(item => {
|
|
271
241
|
let block = item.block;
|
|
@@ -383,11 +353,21 @@ function make(param) {
|
|
|
383
353
|
};
|
|
384
354
|
});
|
|
385
355
|
let parsingTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(parsingTimeRef));
|
|
386
|
-
let
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
356
|
+
let blockHashes = pageUnsafe.items.map(param => {
|
|
357
|
+
let block = param.block;
|
|
358
|
+
return {
|
|
359
|
+
blockHash: block.id,
|
|
360
|
+
blockNumber: block.height
|
|
361
|
+
};
|
|
362
|
+
});
|
|
363
|
+
let match = Belt_Array.get(pageUnsafe.items, pageUnsafe.items.length - 1 | 0);
|
|
364
|
+
let latestFetchedBlockTimestamp;
|
|
365
|
+
if (match !== undefined) {
|
|
366
|
+
let block = match.block;
|
|
367
|
+
latestFetchedBlockTimestamp = block.height === heighestBlockQueried ? block.time : 0;
|
|
368
|
+
} else {
|
|
369
|
+
latestFetchedBlockTimestamp = 0;
|
|
370
|
+
}
|
|
391
371
|
let totalTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(totalTimeRef));
|
|
392
372
|
let stats_parsing$unknowntime$unknown$lpars$rpar = parsingTimeElapsed;
|
|
393
373
|
let stats_page$unknownfetch$unknowntime$unknown$lpars$rpar = pageFetchTime;
|
|
@@ -398,11 +378,11 @@ function make(param) {
|
|
|
398
378
|
};
|
|
399
379
|
return {
|
|
400
380
|
knownHeight: knownHeight$1,
|
|
401
|
-
|
|
381
|
+
blockHashes: blockHashes,
|
|
402
382
|
parsedQueueItems: parsedQueueItems,
|
|
403
383
|
fromBlockQueried: fromBlock,
|
|
404
|
-
latestFetchedBlockNumber:
|
|
405
|
-
latestFetchedBlockTimestamp:
|
|
384
|
+
latestFetchedBlockNumber: heighestBlockQueried,
|
|
385
|
+
latestFetchedBlockTimestamp: latestFetchedBlockTimestamp,
|
|
406
386
|
stats: stats
|
|
407
387
|
};
|
|
408
388
|
};
|
|
@@ -1,30 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
address: Address.t,
|
|
4
|
-
data: string,
|
|
5
|
-
topics: array<EvmTypes.Hex.t>,
|
|
6
|
-
logIndex: int,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
let fieldNames = ["address", "data", "topics", "logIndex"]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
type hyperSyncPage<'item> = {
|
|
13
|
-
items: array<'item>,
|
|
1
|
+
type logsQueryPage = {
|
|
2
|
+
items: array<HyperSyncClient.EventItems.item>,
|
|
14
3
|
nextBlock: int,
|
|
15
4
|
archiveHeight: int,
|
|
16
5
|
rollbackGuard: option<HyperSyncClient.ResponseTypes.rollbackGuard>,
|
|
17
|
-
events: array<HyperSyncClient.ResponseTypes.event>,
|
|
18
6
|
}
|
|
19
7
|
|
|
20
|
-
type logsQueryPageItem = {
|
|
21
|
-
log: Log.t,
|
|
22
|
-
block: HyperSyncClient.ResponseTypes.block,
|
|
23
|
-
transaction: Internal.eventTransaction,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type logsQueryPage = hyperSyncPage<logsQueryPageItem>
|
|
27
|
-
|
|
28
8
|
type missingParams = {
|
|
29
9
|
queryName: string,
|
|
30
10
|
missingParams: array<string>,
|
|
@@ -74,94 +54,37 @@ module GetLogs = {
|
|
|
74
54
|
fieldSelection,
|
|
75
55
|
}
|
|
76
56
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
57
|
+
// Rust encodes structured failures as a JSON payload in the napi error's
|
|
58
|
+
// message: `{"kind":"MissingFields","fields":["block.timestamp", ...]}`.
|
|
59
|
+
// JSON.parse + shape check is the recovery protocol — no string-grepping
|
|
60
|
+
// on anyhow's Debug format.
|
|
61
|
+
let extractMissingParams = (exn: exn): option<array<string>> => {
|
|
62
|
+
let message = switch exn {
|
|
63
|
+
| JsExn(jsExn) => jsExn->JsExn.message
|
|
64
|
+
| _ => None
|
|
65
|
+
}
|
|
66
|
+
switch message {
|
|
67
|
+
| None => None
|
|
68
|
+
| Some(msg) =>
|
|
69
|
+
switch msg->JSON.parseOrThrow->JSON.Decode.object {
|
|
70
|
+
| exception _ => None
|
|
71
|
+
| None => None
|
|
72
|
+
| Some(obj) =>
|
|
73
|
+
switch (obj->Dict.get("kind"), obj->Dict.get("fields")) {
|
|
74
|
+
| (Some(String("MissingFields")), Some(Array(fields))) =>
|
|
75
|
+
Some(fields->Array.filterMap(JSON.Decode.string))
|
|
76
|
+
| _ => None
|
|
91
77
|
}
|
|
92
78
|
}
|
|
93
79
|
}
|
|
94
80
|
}
|
|
95
81
|
|
|
96
|
-
//Note this function can throw an error
|
|
97
|
-
let convertEvent = (
|
|
98
|
-
event: HyperSyncClient.ResponseTypes.event,
|
|
99
|
-
~nonOptionalBlockFieldNames,
|
|
100
|
-
~nonOptionalTransactionFieldNames,
|
|
101
|
-
): logsQueryPageItem => {
|
|
102
|
-
let missingParams = []
|
|
103
|
-
missingParams->addMissingParams(Log.fieldNames, event.log, ~prefix="log")
|
|
104
|
-
missingParams->addMissingParams(nonOptionalBlockFieldNames, event.block, ~prefix="block")
|
|
105
|
-
missingParams->addMissingParams(
|
|
106
|
-
nonOptionalTransactionFieldNames,
|
|
107
|
-
event.transaction,
|
|
108
|
-
~prefix="transaction",
|
|
109
|
-
)
|
|
110
|
-
if missingParams->Array.length > 0 {
|
|
111
|
-
throw(Error(UnexpectedMissingParams({missingParams: missingParams})))
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
//Topics can be nullable and still need to be filtered
|
|
115
|
-
let logUnsanitized: Log.t = event.log->(Utils.magic: HyperSyncClient.ResponseTypes.log => Log.t)
|
|
116
|
-
let topics = event.log.topics->Option.getUnsafe->Array.filterMap(Nullable.toOption)
|
|
117
|
-
let address = event.log.address->Option.getUnsafe
|
|
118
|
-
let log = {
|
|
119
|
-
...logUnsanitized,
|
|
120
|
-
topics,
|
|
121
|
-
address,
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
{
|
|
125
|
-
log,
|
|
126
|
-
block: event.block->(
|
|
127
|
-
Utils.magic: option<
|
|
128
|
-
HyperSyncClient.ResponseTypes.block,
|
|
129
|
-
> => HyperSyncClient.ResponseTypes.block
|
|
130
|
-
),
|
|
131
|
-
transaction: event.transaction->(
|
|
132
|
-
Utils.magic: option<HyperSyncClient.ResponseTypes.transaction> => Internal.eventTransaction
|
|
133
|
-
),
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
let convertResponse = (
|
|
138
|
-
res: HyperSyncClient.ResponseTypes.eventResponse,
|
|
139
|
-
~nonOptionalBlockFieldNames,
|
|
140
|
-
~nonOptionalTransactionFieldNames,
|
|
141
|
-
): logsQueryPage => {
|
|
142
|
-
let {nextBlock, archiveHeight, rollbackGuard} = res
|
|
143
|
-
let items =
|
|
144
|
-
res.data->Array.map(item =>
|
|
145
|
-
item->convertEvent(~nonOptionalBlockFieldNames, ~nonOptionalTransactionFieldNames)
|
|
146
|
-
)
|
|
147
|
-
let page: logsQueryPage = {
|
|
148
|
-
items,
|
|
149
|
-
nextBlock,
|
|
150
|
-
archiveHeight: archiveHeight->Option.getOr(0), //Archive Height is only None if height is 0
|
|
151
|
-
events: res.data,
|
|
152
|
-
rollbackGuard,
|
|
153
|
-
}
|
|
154
|
-
page
|
|
155
|
-
}
|
|
156
|
-
|
|
157
82
|
let query = async (
|
|
158
83
|
~client: HyperSyncClient.t,
|
|
159
84
|
~fromBlock,
|
|
160
85
|
~toBlock,
|
|
161
86
|
~logSelections: array<LogSelection.t>,
|
|
162
87
|
~fieldSelection,
|
|
163
|
-
~nonOptionalBlockFieldNames,
|
|
164
|
-
~nonOptionalTransactionFieldNames,
|
|
165
88
|
): logsQueryPage => {
|
|
166
89
|
let addressesWithTopics = logSelections->Array.flatMap(({addresses, topicSelections}) =>
|
|
167
90
|
topicSelections->Array.map(({topic0, topic1, topic2, topic3}) => {
|
|
@@ -182,13 +105,25 @@ module GetLogs = {
|
|
|
182
105
|
~fieldSelection,
|
|
183
106
|
)
|
|
184
107
|
|
|
185
|
-
let res = await client.
|
|
108
|
+
let res = switch await client.getEventItems(~query) {
|
|
109
|
+
| res => res
|
|
110
|
+
| exception exn =>
|
|
111
|
+
switch extractMissingParams(exn) {
|
|
112
|
+
| Some(missingParams) => throw(Error(UnexpectedMissingParams({missingParams: missingParams})))
|
|
113
|
+
| None => throw(exn)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
186
116
|
if res.nextBlock <= fromBlock {
|
|
187
117
|
// Might happen when /height response was from another instance of HyperSync
|
|
188
118
|
throw(Error(WrongInstance))
|
|
189
119
|
}
|
|
190
120
|
|
|
191
|
-
|
|
121
|
+
{
|
|
122
|
+
items: res.items,
|
|
123
|
+
nextBlock: res.nextBlock,
|
|
124
|
+
archiveHeight: res.archiveHeight->Option.getOr(0), //Archive Height is only None if height is 0
|
|
125
|
+
rollbackGuard: res.rollbackGuard,
|
|
126
|
+
}
|
|
192
127
|
}
|
|
193
128
|
}
|
|
194
129
|
|
|
@@ -4,21 +4,15 @@ import * as Time from "../Time.res.mjs";
|
|
|
4
4
|
import * as Utils from "../Utils.res.mjs";
|
|
5
5
|
import * as Logging from "../Logging.res.mjs";
|
|
6
6
|
import * as Prometheus from "../Prometheus.res.mjs";
|
|
7
|
+
import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
7
8
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
9
|
+
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
8
10
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
9
11
|
import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
|
|
10
12
|
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
11
13
|
import * as HyperSyncClient from "./HyperSyncClient.res.mjs";
|
|
12
|
-
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
13
14
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
14
15
|
|
|
15
|
-
let fieldNames = [
|
|
16
|
-
"address",
|
|
17
|
-
"data",
|
|
18
|
-
"topics",
|
|
19
|
-
"logIndex"
|
|
20
|
-
];
|
|
21
|
-
|
|
22
16
|
let HyperSyncQueryError = /* @__PURE__ */Primitive_exceptions.create("HyperSync.HyperSyncQueryError");
|
|
23
17
|
|
|
24
18
|
function queryErrorToMsq(e) {
|
|
@@ -55,7 +49,28 @@ function makeRequestBody(fromBlock, toBlockInclusive, addressesWithTopics, field
|
|
|
55
49
|
};
|
|
56
50
|
}
|
|
57
51
|
|
|
58
|
-
|
|
52
|
+
function extractMissingParams(exn) {
|
|
53
|
+
let message = exn.RE_EXN_ID === "JsExn" ? Stdlib_JsExn.message(exn._1) : undefined;
|
|
54
|
+
if (message === undefined) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
let obj;
|
|
58
|
+
try {
|
|
59
|
+
obj = Stdlib_JSON.Decode.object(JSON.parse(message));
|
|
60
|
+
} catch (exn$1) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (obj === undefined) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let match = obj["kind"];
|
|
67
|
+
let match$1 = obj["fields"];
|
|
68
|
+
if (match === "MissingFields" && Array.isArray(match$1)) {
|
|
69
|
+
return Stdlib_Array.filterMap(match$1, Stdlib_JSON.Decode.string);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function query(client, fromBlock, toBlock, logSelections, fieldSelection) {
|
|
59
74
|
let addressesWithTopics = logSelections.flatMap(param => {
|
|
60
75
|
let addresses = param.addresses;
|
|
61
76
|
return param.topicSelections.map(param => {
|
|
@@ -64,65 +79,13 @@ async function query(client, fromBlock, toBlock, logSelections, fieldSelection,
|
|
|
64
79
|
});
|
|
65
80
|
});
|
|
66
81
|
let query$1 = makeRequestBody(fromBlock, toBlock, addressesWithTopics, fieldSelection);
|
|
67
|
-
let res
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
let items = res.data.map(item => {
|
|
76
|
-
let missingParams = [];
|
|
77
|
-
let returnedObj = item.log;
|
|
78
|
-
if (Utils.$$Array.notEmpty(fieldNames)) {
|
|
79
|
-
if (returnedObj) {
|
|
80
|
-
for (let idx = 0, idx_finish = fieldNames.length; idx < idx_finish; ++idx) {
|
|
81
|
-
let fieldName = fieldNames[idx];
|
|
82
|
-
let match = returnedObj[fieldName];
|
|
83
|
-
if (match !== undefined) {
|
|
84
|
-
|
|
85
|
-
} else {
|
|
86
|
-
missingParams.push("log." + fieldName);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
missingParams.push("log");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
let returnedObj$1 = item.block;
|
|
94
|
-
if (Utils.$$Array.notEmpty(nonOptionalBlockFieldNames)) {
|
|
95
|
-
if (returnedObj$1) {
|
|
96
|
-
for (let idx$1 = 0, idx_finish$1 = nonOptionalBlockFieldNames.length; idx$1 < idx_finish$1; ++idx$1) {
|
|
97
|
-
let fieldName$1 = nonOptionalBlockFieldNames[idx$1];
|
|
98
|
-
let match$1 = returnedObj$1[fieldName$1];
|
|
99
|
-
if (match$1 !== undefined) {
|
|
100
|
-
|
|
101
|
-
} else {
|
|
102
|
-
missingParams.push("block." + fieldName$1);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
missingParams.push("block");
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
let returnedObj$2 = item.transaction;
|
|
110
|
-
if (Utils.$$Array.notEmpty(nonOptionalTransactionFieldNames)) {
|
|
111
|
-
if (returnedObj$2) {
|
|
112
|
-
for (let idx$2 = 0, idx_finish$2 = nonOptionalTransactionFieldNames.length; idx$2 < idx_finish$2; ++idx$2) {
|
|
113
|
-
let fieldName$2 = nonOptionalTransactionFieldNames[idx$2];
|
|
114
|
-
let match$2 = returnedObj$2[fieldName$2];
|
|
115
|
-
if (match$2 !== undefined) {
|
|
116
|
-
|
|
117
|
-
} else {
|
|
118
|
-
missingParams.push("transaction." + fieldName$2);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
missingParams.push("transaction");
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (missingParams.length !== 0) {
|
|
82
|
+
let res;
|
|
83
|
+
try {
|
|
84
|
+
res = await client.getEventItems(query$1);
|
|
85
|
+
} catch (raw_exn) {
|
|
86
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
87
|
+
let missingParams = extractMissingParams(exn);
|
|
88
|
+
if (missingParams !== undefined) {
|
|
126
89
|
throw {
|
|
127
90
|
RE_EXN_ID: $$Error,
|
|
128
91
|
_1: {
|
|
@@ -132,35 +95,20 @@ async function query(client, fromBlock, toBlock, logSelections, fieldSelection,
|
|
|
132
95
|
Error: new Error()
|
|
133
96
|
};
|
|
134
97
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|
|
143
|
-
let address = item.log.address;
|
|
144
|
-
let log_data = logUnsanitized.data;
|
|
145
|
-
let log_logIndex = logUnsanitized.logIndex;
|
|
146
|
-
let log = {
|
|
147
|
-
address: address,
|
|
148
|
-
data: log_data,
|
|
149
|
-
topics: topics,
|
|
150
|
-
logIndex: log_logIndex
|
|
151
|
-
};
|
|
152
|
-
return {
|
|
153
|
-
log: log,
|
|
154
|
-
block: item.block,
|
|
155
|
-
transaction: item.transaction
|
|
98
|
+
throw exn;
|
|
99
|
+
}
|
|
100
|
+
if (res.nextBlock <= fromBlock) {
|
|
101
|
+
throw {
|
|
102
|
+
RE_EXN_ID: $$Error,
|
|
103
|
+
_1: "WrongInstance",
|
|
104
|
+
Error: new Error()
|
|
156
105
|
};
|
|
157
|
-
}
|
|
106
|
+
}
|
|
158
107
|
return {
|
|
159
|
-
items: items,
|
|
108
|
+
items: res.items,
|
|
160
109
|
nextBlock: res.nextBlock,
|
|
161
110
|
archiveHeight: Stdlib_Option.getOr(res.archiveHeight, 0),
|
|
162
|
-
rollbackGuard: res.rollbackGuard
|
|
163
|
-
events: res.data
|
|
111
|
+
rollbackGuard: res.rollbackGuard
|
|
164
112
|
};
|
|
165
113
|
}
|
|
166
114
|
|
|
@@ -289,15 +237,13 @@ function queryBlockData$1(client, blockNumber, sourceName, chainId, logger) {
|
|
|
289
237
|
return queryBlockData(client, blockNumber, blockNumber, sourceName, chainId, logger).then(res => Stdlib_Result.map(res, res => res[0]));
|
|
290
238
|
}
|
|
291
239
|
|
|
292
|
-
let Log = {};
|
|
293
|
-
|
|
294
240
|
let GetLogs = {
|
|
295
241
|
$$Error: $$Error,
|
|
242
|
+
extractMissingParams: extractMissingParams,
|
|
296
243
|
query: query
|
|
297
244
|
};
|
|
298
245
|
|
|
299
246
|
export {
|
|
300
|
-
Log,
|
|
301
247
|
queryErrorToMsq,
|
|
302
248
|
GetLogs,
|
|
303
249
|
queryBlockData$1 as queryBlockData,
|
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
type
|
|
2
|
-
items: array<
|
|
1
|
+
type logsQueryPage = {
|
|
2
|
+
items: array<HyperSyncClient.EventItems.item>,
|
|
3
3
|
nextBlock: int,
|
|
4
4
|
archiveHeight: int,
|
|
5
5
|
rollbackGuard: option<HyperSyncClient.ResponseTypes.rollbackGuard>,
|
|
6
|
-
events: array<HyperSyncClient.ResponseTypes.event>,
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
module Log: {
|
|
10
|
-
type t = {
|
|
11
|
-
address: Address.t,
|
|
12
|
-
data: string,
|
|
13
|
-
topics: array<EvmTypes.Hex.t>,
|
|
14
|
-
logIndex: int,
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type logsQueryPageItem = {
|
|
19
|
-
log: Log.t,
|
|
20
|
-
block: HyperSyncClient.ResponseTypes.block,
|
|
21
|
-
transaction: Internal.eventTransaction,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type logsQueryPage = hyperSyncPage<logsQueryPageItem>
|
|
25
|
-
|
|
26
8
|
type missingParams = {
|
|
27
9
|
queryName: string,
|
|
28
10
|
missingParams: array<string>,
|
|
@@ -41,14 +23,14 @@ module GetLogs: {
|
|
|
41
23
|
|
|
42
24
|
exception Error(error)
|
|
43
25
|
|
|
26
|
+
let extractMissingParams: exn => option<array<string>>
|
|
27
|
+
|
|
44
28
|
let query: (
|
|
45
29
|
~client: HyperSyncClient.t,
|
|
46
30
|
~fromBlock: int,
|
|
47
31
|
~toBlock: option<int>,
|
|
48
32
|
~logSelections: array<LogSelection.t>,
|
|
49
33
|
~fieldSelection: HyperSyncClient.QueryTypes.fieldSelection,
|
|
50
|
-
~nonOptionalBlockFieldNames: array<string>,
|
|
51
|
-
~nonOptionalTransactionFieldNames: array<string>,
|
|
52
34
|
) => promise<logsQueryPage>
|
|
53
35
|
}
|
|
54
36
|
|