envio 2.29.0-alpha.0 → 2.29.0-alpha.1
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/index.d.ts +3 -0
- package/package.json +5 -5
- package/src/Batch.res +4 -14
- package/src/Batch.res.js +3 -14
- package/src/Envio.gen.ts +10 -0
- package/src/Envio.res +21 -0
- package/src/EventRegister.res +150 -31
- package/src/EventRegister.res.js +120 -33
- package/src/EventRegister.resi +11 -0
- package/src/EventUtils.res +52 -58
- package/src/EventUtils.res.js +15 -51
- package/src/FetchState.res +68 -56
- package/src/FetchState.res.js +66 -53
- package/src/Internal.gen.ts +2 -0
- package/src/Internal.res +44 -3
- package/src/InternalConfig.res +18 -0
- package/src/Logging.res +36 -24
- package/src/Logging.res.js +35 -21
- package/src/sources/HyperFuelSource.res +506 -0
- package/src/sources/HyperFuelSource.res.js +451 -0
- package/src/sources/HyperSync.res +1 -1
- package/src/sources/HyperSync.resi +1 -1
- package/src/sources/HyperSyncSource.res +569 -0
- package/src/sources/HyperSyncSource.res.js +413 -0
- package/src/sources/RpcSource.res +18 -20
- package/src/sources/RpcSource.res.js +1 -0
- package/src/sources/Source.res +1 -1
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var Rest = require("../vendored/Rest.res.js");
|
|
5
|
+
var Viem = require("../bindings/Viem.res.js");
|
|
6
|
+
var Utils = require("../Utils.res.js");
|
|
7
|
+
var Hrtime = require("../bindings/Hrtime.res.js");
|
|
8
|
+
var Js_exn = require("rescript/lib/js/js_exn.js");
|
|
9
|
+
var Source = require("./Source.res.js");
|
|
10
|
+
var Logging = require("../Logging.res.js");
|
|
11
|
+
var HyperSync = require("./HyperSync.res.js");
|
|
12
|
+
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
13
|
+
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
|
14
|
+
var EventRouter = require("./EventRouter.res.js");
|
|
15
|
+
var LogSelection = require("../LogSelection.res.js");
|
|
16
|
+
var ErrorHandling = require("../ErrorHandling.res.js");
|
|
17
|
+
var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
|
|
18
|
+
var HyperSyncClient = require("./HyperSyncClient.res.js");
|
|
19
|
+
var Caml_splice_call = require("rescript/lib/js/caml_splice_call.js");
|
|
20
|
+
var HyperSyncJsonApi = require("./HyperSyncJsonApi.res.js");
|
|
21
|
+
var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
|
|
22
|
+
|
|
23
|
+
function getSelectionConfig(selection, chain) {
|
|
24
|
+
var nonOptionalBlockFieldNames = new Set();
|
|
25
|
+
var nonOptionalTransactionFieldNames = new Set();
|
|
26
|
+
var capitalizedBlockFields = new Set();
|
|
27
|
+
var capitalizedTransactionFields = new Set();
|
|
28
|
+
var staticTopicSelectionsByContract = {};
|
|
29
|
+
var dynamicEventFiltersByContract = {};
|
|
30
|
+
var dynamicWildcardEventFiltersByContract = {};
|
|
31
|
+
var noAddressesTopicSelections = [];
|
|
32
|
+
var contractNames = new Set();
|
|
33
|
+
Belt_Array.forEach(selection.eventConfigs, (function (param) {
|
|
34
|
+
var transactionSchema = param.transactionSchema;
|
|
35
|
+
var blockSchema = param.blockSchema;
|
|
36
|
+
var contractName = param.contractName;
|
|
37
|
+
Utils.$$Set.addMany(nonOptionalBlockFieldNames, Utils.Schema.getNonOptionalFieldNames(blockSchema));
|
|
38
|
+
Utils.$$Set.addMany(nonOptionalTransactionFieldNames, Utils.Schema.getNonOptionalFieldNames(transactionSchema));
|
|
39
|
+
Utils.$$Set.addMany(capitalizedBlockFields, Utils.Schema.getCapitalizedFieldNames(blockSchema));
|
|
40
|
+
Utils.$$Set.addMany(capitalizedTransactionFields, Utils.Schema.getCapitalizedFieldNames(transactionSchema));
|
|
41
|
+
var eventFilters = param.getEventFiltersOrThrow(chain);
|
|
42
|
+
if (param.dependsOnAddresses) {
|
|
43
|
+
contractNames.add(contractName);
|
|
44
|
+
if (eventFilters.TAG === "Static") {
|
|
45
|
+
return Utils.Dict.pushMany(staticTopicSelectionsByContract, contractName, eventFilters._0);
|
|
46
|
+
} else {
|
|
47
|
+
return Utils.Dict.push(param.isWildcard ? dynamicWildcardEventFiltersByContract : dynamicEventFiltersByContract, contractName, eventFilters._0);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
var tmp;
|
|
51
|
+
tmp = eventFilters.TAG === "Static" ? eventFilters._0 : eventFilters._0([]);
|
|
52
|
+
Caml_splice_call.spliceObjApply(noAddressesTopicSelections, "push", [tmp]);
|
|
53
|
+
}));
|
|
54
|
+
var fieldSelection_block = Array.from(capitalizedBlockFields);
|
|
55
|
+
var fieldSelection_transaction = Array.from(capitalizedTransactionFields);
|
|
56
|
+
var fieldSelection_log = [
|
|
57
|
+
"Address",
|
|
58
|
+
"Data",
|
|
59
|
+
"LogIndex",
|
|
60
|
+
"Topic0",
|
|
61
|
+
"Topic1",
|
|
62
|
+
"Topic2",
|
|
63
|
+
"Topic3"
|
|
64
|
+
];
|
|
65
|
+
var fieldSelection = {
|
|
66
|
+
block: fieldSelection_block,
|
|
67
|
+
transaction: fieldSelection_transaction,
|
|
68
|
+
log: fieldSelection_log
|
|
69
|
+
};
|
|
70
|
+
var noAddressesLogSelection = LogSelection.make([], noAddressesTopicSelections);
|
|
71
|
+
var getLogSelectionOrThrow = function (addressesByContractName) {
|
|
72
|
+
var logSelections = [];
|
|
73
|
+
if (!Utils.$$Array.isEmpty(noAddressesLogSelection.topicSelections)) {
|
|
74
|
+
logSelections.push(noAddressesLogSelection);
|
|
75
|
+
}
|
|
76
|
+
contractNames.forEach(function (contractName) {
|
|
77
|
+
var addresses = addressesByContractName[contractName];
|
|
78
|
+
if (addresses === undefined) {
|
|
79
|
+
return ;
|
|
80
|
+
}
|
|
81
|
+
if (addresses.length === 0) {
|
|
82
|
+
return ;
|
|
83
|
+
}
|
|
84
|
+
var topicSelections = staticTopicSelectionsByContract[contractName];
|
|
85
|
+
if (topicSelections !== undefined) {
|
|
86
|
+
logSelections.push(LogSelection.make(addresses, topicSelections));
|
|
87
|
+
}
|
|
88
|
+
var fns = dynamicEventFiltersByContract[contractName];
|
|
89
|
+
if (fns !== undefined) {
|
|
90
|
+
logSelections.push(LogSelection.make(addresses, Belt_Array.flatMapU(fns, (function (fn) {
|
|
91
|
+
return fn(addresses);
|
|
92
|
+
}))));
|
|
93
|
+
}
|
|
94
|
+
var fns$1 = dynamicWildcardEventFiltersByContract[contractName];
|
|
95
|
+
if (fns$1 !== undefined) {
|
|
96
|
+
logSelections.push(LogSelection.make([], Belt_Array.flatMapU(fns$1, (function (fn) {
|
|
97
|
+
return fn(addresses);
|
|
98
|
+
}))));
|
|
99
|
+
return ;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
});
|
|
103
|
+
return logSelections;
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
getLogSelectionOrThrow: getLogSelectionOrThrow,
|
|
107
|
+
fieldSelection: fieldSelection,
|
|
108
|
+
nonOptionalBlockFieldNames: Array.from(nonOptionalBlockFieldNames),
|
|
109
|
+
nonOptionalTransactionFieldNames: Array.from(nonOptionalTransactionFieldNames)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function memoGetSelectionConfig(chain) {
|
|
114
|
+
var cache = new WeakMap();
|
|
115
|
+
return function (selection) {
|
|
116
|
+
var c = cache.get(selection);
|
|
117
|
+
if (c !== undefined) {
|
|
118
|
+
return c;
|
|
119
|
+
}
|
|
120
|
+
var c$1 = getSelectionConfig(selection, chain);
|
|
121
|
+
cache.set(selection, c$1);
|
|
122
|
+
return c$1;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function make(param) {
|
|
127
|
+
var eventRouter = param.eventRouter;
|
|
128
|
+
var shouldUseHypersyncClientDecoder = param.shouldUseHypersyncClientDecoder;
|
|
129
|
+
var allEventSignatures = param.allEventSignatures;
|
|
130
|
+
var endpointUrl = param.endpointUrl;
|
|
131
|
+
var chain = param.chain;
|
|
132
|
+
var getSelectionConfig = memoGetSelectionConfig(chain);
|
|
133
|
+
var apiToken = Belt_Option.getWithDefault(param.apiToken, "3dc856dd-b0ea-494f-b27e-017b8b6b7e07");
|
|
134
|
+
var client = HyperSyncClient.make(endpointUrl, apiToken, param.clientTimeoutMillis, param.clientMaxRetries);
|
|
135
|
+
var hscDecoder = {
|
|
136
|
+
contents: undefined
|
|
137
|
+
};
|
|
138
|
+
var getHscDecoder = function () {
|
|
139
|
+
var decoder = hscDecoder.contents;
|
|
140
|
+
if (decoder !== undefined) {
|
|
141
|
+
return decoder;
|
|
142
|
+
}
|
|
143
|
+
var decoder$1;
|
|
144
|
+
try {
|
|
145
|
+
decoder$1 = HyperSyncClient.Decoder.fromSignatures(allEventSignatures);
|
|
146
|
+
}
|
|
147
|
+
catch (raw_exn){
|
|
148
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
149
|
+
return ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate a decoder from hypersync client, please double check your ABI or try using 'event_decoder: viem' config option", exn);
|
|
150
|
+
}
|
|
151
|
+
decoder$1.enableChecksummedAddresses();
|
|
152
|
+
return decoder$1;
|
|
153
|
+
};
|
|
154
|
+
var UndefinedValue = /* @__PURE__ */Caml_exceptions.create("UndefinedValue");
|
|
155
|
+
var makeEventBatchQueueItem = function (item, params, eventConfig) {
|
|
156
|
+
var block = item.block;
|
|
157
|
+
var log = item.log;
|
|
158
|
+
return {
|
|
159
|
+
kind: 0,
|
|
160
|
+
eventConfig: eventConfig,
|
|
161
|
+
timestamp: block.timestamp,
|
|
162
|
+
chain: chain,
|
|
163
|
+
blockNumber: block.number,
|
|
164
|
+
logIndex: log.logIndex,
|
|
165
|
+
event: {
|
|
166
|
+
params: params,
|
|
167
|
+
chainId: chain,
|
|
168
|
+
srcAddress: log.address,
|
|
169
|
+
logIndex: log.logIndex,
|
|
170
|
+
transaction: item.transaction,
|
|
171
|
+
block: block
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
var contractNameAbiMapping = {};
|
|
176
|
+
Belt_Array.forEach(param.contracts, (function (contract) {
|
|
177
|
+
contractNameAbiMapping[contract.name] = contract.abi;
|
|
178
|
+
}));
|
|
179
|
+
var getItemsOrThrow = async function (fromBlock, toBlock, addressesByContractName, indexingContracts, currentBlockHeight, param, selection, retry, logger) {
|
|
180
|
+
var mkLogAndRaise = function (extra, extra$1) {
|
|
181
|
+
return ErrorHandling.mkLogAndRaise(logger, extra, extra$1);
|
|
182
|
+
};
|
|
183
|
+
var totalTimeRef = Hrtime.makeTimer();
|
|
184
|
+
var selectionConfig = getSelectionConfig(selection);
|
|
185
|
+
var logSelections;
|
|
186
|
+
try {
|
|
187
|
+
logSelections = selectionConfig.getLogSelectionOrThrow(addressesByContractName);
|
|
188
|
+
}
|
|
189
|
+
catch (raw_exn){
|
|
190
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
191
|
+
logSelections = ErrorHandling.mkLogAndRaise(logger, "Failed getting log selection for the query", exn);
|
|
192
|
+
}
|
|
193
|
+
var startFetchingBatchTimeRef = Hrtime.makeTimer();
|
|
194
|
+
var pageUnsafe;
|
|
195
|
+
try {
|
|
196
|
+
pageUnsafe = await HyperSync.GetLogs.query(client, fromBlock, toBlock, logSelections, selectionConfig.fieldSelection, selectionConfig.nonOptionalBlockFieldNames, selectionConfig.nonOptionalTransactionFieldNames);
|
|
197
|
+
}
|
|
198
|
+
catch (raw_error){
|
|
199
|
+
var error = Caml_js_exceptions.internalToOCamlException(raw_error);
|
|
200
|
+
if (error.RE_EXN_ID === HyperSync.GetLogs.$$Error) {
|
|
201
|
+
var error$1 = error._1;
|
|
202
|
+
var tmp;
|
|
203
|
+
if (typeof error$1 !== "object") {
|
|
204
|
+
var backoffMillis = retry !== 0 ? Math.imul(500, retry) : 100;
|
|
205
|
+
tmp = {
|
|
206
|
+
TAG: "WithBackoff",
|
|
207
|
+
message: "Block #" + String(fromBlock) + " not found in HyperSync. HyperSync has multiple instances and it's possible that they drift independently slightly from the head. Indexing should continue correctly after retrying the query in " + String(backoffMillis) + "ms.",
|
|
208
|
+
backoffMillis: backoffMillis
|
|
209
|
+
};
|
|
210
|
+
} else {
|
|
211
|
+
tmp = {
|
|
212
|
+
TAG: "WithBackoff",
|
|
213
|
+
message: "Received page response with invalid data. Attempt a retry. Missing params: " + error$1.missingParams.join(","),
|
|
214
|
+
backoffMillis: retry !== 0 ? Math.imul(4000, retry) : 1000
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
throw {
|
|
218
|
+
RE_EXN_ID: Source.GetItemsError,
|
|
219
|
+
_1: {
|
|
220
|
+
TAG: "FailedGettingItems",
|
|
221
|
+
exn: null,
|
|
222
|
+
attemptedToBlock: Belt_Option.getWithDefault(toBlock, currentBlockHeight),
|
|
223
|
+
retry: tmp
|
|
224
|
+
},
|
|
225
|
+
Error: new Error()
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
throw {
|
|
229
|
+
RE_EXN_ID: Source.GetItemsError,
|
|
230
|
+
_1: {
|
|
231
|
+
TAG: "FailedGettingItems",
|
|
232
|
+
exn: error,
|
|
233
|
+
attemptedToBlock: Belt_Option.getWithDefault(toBlock, currentBlockHeight),
|
|
234
|
+
retry: {
|
|
235
|
+
TAG: "WithBackoff",
|
|
236
|
+
message: "Unexpected issue while fetching events from HyperSync client. Attempt a retry.",
|
|
237
|
+
backoffMillis: retry !== 0 ? Math.imul(1000, retry) : 500
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
Error: new Error()
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
var pageFetchTime = Hrtime.intFromMillis(Hrtime.toMillis(Hrtime.timeSince(startFetchingBatchTimeRef)));
|
|
244
|
+
var currentBlockHeight$1 = pageUnsafe.archiveHeight;
|
|
245
|
+
var heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
|
|
246
|
+
var match = pageUnsafe.rollbackGuard;
|
|
247
|
+
var lastBlockQueriedPromise;
|
|
248
|
+
if (match !== undefined) {
|
|
249
|
+
lastBlockQueriedPromise = Promise.resolve({
|
|
250
|
+
blockHash: match.hash,
|
|
251
|
+
blockNumber: match.blockNumber,
|
|
252
|
+
blockTimestamp: match.timestamp
|
|
253
|
+
});
|
|
254
|
+
} else {
|
|
255
|
+
var match$1 = Belt_Array.get(pageUnsafe.items, pageUnsafe.items.length - 1 | 0);
|
|
256
|
+
var exit = 0;
|
|
257
|
+
if (match$1 !== undefined) {
|
|
258
|
+
var block = match$1.block;
|
|
259
|
+
if (block.number === heighestBlockQueried) {
|
|
260
|
+
lastBlockQueriedPromise = Promise.resolve({
|
|
261
|
+
blockHash: block.hash,
|
|
262
|
+
blockNumber: block.number,
|
|
263
|
+
blockTimestamp: block.timestamp
|
|
264
|
+
});
|
|
265
|
+
} else {
|
|
266
|
+
exit = 1;
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
exit = 1;
|
|
270
|
+
}
|
|
271
|
+
if (exit === 1) {
|
|
272
|
+
lastBlockQueriedPromise = HyperSync.queryBlockData(endpointUrl, apiToken, heighestBlockQueried, logger).then(function (res) {
|
|
273
|
+
if (res.TAG !== "Ok") {
|
|
274
|
+
return mkLogAndRaise("Failed to query blockData for block " + String(heighestBlockQueried), HyperSync.queryErrorToMsq(res._0));
|
|
275
|
+
}
|
|
276
|
+
var blockData = res._0;
|
|
277
|
+
if (blockData !== undefined) {
|
|
278
|
+
return blockData;
|
|
279
|
+
} else {
|
|
280
|
+
return mkLogAndRaise("Failure, blockData for block " + String(heighestBlockQueried) + " unexpectedly returned None", {
|
|
281
|
+
RE_EXN_ID: "Not_found"
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
}
|
|
288
|
+
var parsingTimeRef = Hrtime.makeTimer();
|
|
289
|
+
var parsedQueueItems = [];
|
|
290
|
+
var handleDecodeFailure = function (eventConfig, decoder, logIndex, blockNumber, chainId, exn) {
|
|
291
|
+
if (eventConfig.isWildcard) {
|
|
292
|
+
return ;
|
|
293
|
+
}
|
|
294
|
+
var msg = "Event " + eventConfig.name + " was unexpectedly parsed as undefined";
|
|
295
|
+
var logger$1 = Logging.createChildFrom(logger, {
|
|
296
|
+
chainId: chainId,
|
|
297
|
+
blockNumber: blockNumber,
|
|
298
|
+
logIndex: logIndex,
|
|
299
|
+
decoder: decoder
|
|
300
|
+
});
|
|
301
|
+
ErrorHandling.mkLogAndRaise(logger$1, msg, exn);
|
|
302
|
+
};
|
|
303
|
+
if (shouldUseHypersyncClientDecoder) {
|
|
304
|
+
var parsedEvents;
|
|
305
|
+
try {
|
|
306
|
+
parsedEvents = await getHscDecoder().decodeEvents(pageUnsafe.events);
|
|
307
|
+
}
|
|
308
|
+
catch (raw_exn$1){
|
|
309
|
+
var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1);
|
|
310
|
+
parsedEvents = mkLogAndRaise("Failed to parse events using hypersync client, please double check your ABI.", exn$1);
|
|
311
|
+
}
|
|
312
|
+
Belt_Array.forEachWithIndex(pageUnsafe.items, (function (index, item) {
|
|
313
|
+
var block = item.block;
|
|
314
|
+
var log = item.log;
|
|
315
|
+
var topic0 = log.topics[0];
|
|
316
|
+
var maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), log.address, block.number, indexingContracts);
|
|
317
|
+
var maybeDecodedEvent = parsedEvents[index];
|
|
318
|
+
if (maybeEventConfig === undefined) {
|
|
319
|
+
return ;
|
|
320
|
+
}
|
|
321
|
+
if (maybeDecodedEvent === null || maybeDecodedEvent === undefined) {
|
|
322
|
+
maybeDecodedEvent === null;
|
|
323
|
+
} else {
|
|
324
|
+
parsedQueueItems.push(makeEventBatchQueueItem(item, maybeEventConfig.convertHyperSyncEventArgs(maybeDecodedEvent), maybeEventConfig));
|
|
325
|
+
return ;
|
|
326
|
+
}
|
|
327
|
+
handleDecodeFailure(maybeEventConfig, "hypersync-client", log.logIndex, block.number, chain, {
|
|
328
|
+
RE_EXN_ID: UndefinedValue
|
|
329
|
+
});
|
|
330
|
+
}));
|
|
331
|
+
} else {
|
|
332
|
+
Belt_Array.forEach(pageUnsafe.items, (function (item) {
|
|
333
|
+
var block = item.block;
|
|
334
|
+
var log = item.log;
|
|
335
|
+
var topic0 = log.topics[0];
|
|
336
|
+
var eventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), log.address, block.number, indexingContracts);
|
|
337
|
+
if (eventConfig === undefined) {
|
|
338
|
+
return ;
|
|
339
|
+
}
|
|
340
|
+
var decodedEvent;
|
|
341
|
+
try {
|
|
342
|
+
decodedEvent = Viem.parseLogOrThrow(contractNameAbiMapping, eventConfig.contractName, log.topics, log.data);
|
|
343
|
+
}
|
|
344
|
+
catch (raw_exn){
|
|
345
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
346
|
+
return handleDecodeFailure(eventConfig, "viem", log.logIndex, block.number, chain, exn);
|
|
347
|
+
}
|
|
348
|
+
parsedQueueItems.push(makeEventBatchQueueItem(item, decodedEvent.args, eventConfig));
|
|
349
|
+
}));
|
|
350
|
+
}
|
|
351
|
+
var parsingTimeElapsed = Hrtime.intFromMillis(Hrtime.toMillis(Hrtime.timeSince(parsingTimeRef)));
|
|
352
|
+
var rangeLastBlock = await lastBlockQueriedPromise;
|
|
353
|
+
var reorgGuard_prevRangeLastBlock = Belt_Option.map(pageUnsafe.rollbackGuard, (function (v) {
|
|
354
|
+
return {
|
|
355
|
+
blockHash: v.firstParentHash,
|
|
356
|
+
blockNumber: v.firstBlockNumber - 1 | 0
|
|
357
|
+
};
|
|
358
|
+
}));
|
|
359
|
+
var reorgGuard = {
|
|
360
|
+
rangeLastBlock: rangeLastBlock,
|
|
361
|
+
prevRangeLastBlock: reorgGuard_prevRangeLastBlock
|
|
362
|
+
};
|
|
363
|
+
var totalTimeElapsed = Hrtime.intFromMillis(Hrtime.toMillis(Hrtime.timeSince(totalTimeRef)));
|
|
364
|
+
var stats_parsing$unknowntime$unknown$lparms$rpar = parsingTimeElapsed;
|
|
365
|
+
var stats_page$unknownfetch$unknowntime$unknown$lparms$rpar = pageFetchTime;
|
|
366
|
+
var stats = {
|
|
367
|
+
"total time elapsed (ms)": totalTimeElapsed,
|
|
368
|
+
"parsing time (ms)": stats_parsing$unknowntime$unknown$lparms$rpar,
|
|
369
|
+
"page fetch time (ms)": stats_page$unknownfetch$unknowntime$unknown$lparms$rpar
|
|
370
|
+
};
|
|
371
|
+
return {
|
|
372
|
+
currentBlockHeight: currentBlockHeight$1,
|
|
373
|
+
reorgGuard: reorgGuard,
|
|
374
|
+
parsedQueueItems: parsedQueueItems,
|
|
375
|
+
fromBlockQueried: fromBlock,
|
|
376
|
+
latestFetchedBlockNumber: rangeLastBlock.blockNumber,
|
|
377
|
+
latestFetchedBlockTimestamp: rangeLastBlock.blockTimestamp,
|
|
378
|
+
stats: stats
|
|
379
|
+
};
|
|
380
|
+
};
|
|
381
|
+
var getBlockHashes = function (blockNumbers, logger) {
|
|
382
|
+
return HyperSync.queryBlockDataMulti(endpointUrl, apiToken, blockNumbers, logger).then(HyperSync.mapExn);
|
|
383
|
+
};
|
|
384
|
+
var jsonApiClient = Rest.client(endpointUrl, undefined);
|
|
385
|
+
return {
|
|
386
|
+
name: "HyperSync",
|
|
387
|
+
sourceFor: "Sync",
|
|
388
|
+
chain: chain,
|
|
389
|
+
poweredByHyperSync: true,
|
|
390
|
+
pollingInterval: 100,
|
|
391
|
+
getBlockHashes: getBlockHashes,
|
|
392
|
+
getHeightOrThrow: (async function () {
|
|
393
|
+
var height = await Rest.$$fetch(HyperSyncJsonApi.heightRoute, apiToken, jsonApiClient);
|
|
394
|
+
if (typeof height === "number") {
|
|
395
|
+
return height;
|
|
396
|
+
} else if (height === "Your token is malformed. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens.") {
|
|
397
|
+
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");
|
|
398
|
+
await new Promise((function (param, param$1) {
|
|
399
|
+
|
|
400
|
+
}));
|
|
401
|
+
return 0;
|
|
402
|
+
} else {
|
|
403
|
+
return Js_exn.raiseError(height);
|
|
404
|
+
}
|
|
405
|
+
}),
|
|
406
|
+
getItemsOrThrow: getItemsOrThrow
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
exports.getSelectionConfig = getSelectionConfig;
|
|
411
|
+
exports.memoGetSelectionConfig = memoGetSelectionConfig;
|
|
412
|
+
exports.make = make;
|
|
413
|
+
/* Rest Not a pure module */
|
|
@@ -660,27 +660,25 @@ let make = ({sourceFor, syncConfig, url, chain, contracts, eventRouter}: options
|
|
|
660
660
|
)
|
|
661
661
|
}
|
|
662
662
|
|
|
663
|
-
(
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
663
|
+
Internal.Event({
|
|
664
|
+
eventConfig: (eventConfig :> Internal.eventConfig),
|
|
665
|
+
timestamp: block.timestamp,
|
|
666
|
+
blockNumber: block.number,
|
|
667
|
+
chain,
|
|
668
|
+
logIndex: log.logIndex,
|
|
669
|
+
event: {
|
|
670
|
+
chainId: chain->ChainMap.Chain.toChainId,
|
|
671
|
+
params: decodedEvent.args,
|
|
672
|
+
transaction,
|
|
673
|
+
// Unreliably expect that the Ethers block fields match the types in HyperIndex
|
|
674
|
+
// I assume this is wrong in some cases, so we need to fix it in the future
|
|
675
|
+
block: block->(
|
|
676
|
+
Utils.magic: Ethers.JsonRpcProvider.block => Internal.eventBlock
|
|
677
|
+
),
|
|
678
|
+
srcAddress: log.address,
|
|
669
679
|
logIndex: log.logIndex,
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
params: decodedEvent.args,
|
|
673
|
-
transaction,
|
|
674
|
-
// Unreliably expect that the Ethers block fields match the types in HyperIndex
|
|
675
|
-
// I assume this is wrong in some cases, so we need to fix it in the future
|
|
676
|
-
block: block->(
|
|
677
|
-
Utils.magic: Ethers.JsonRpcProvider.block => Internal.eventBlock
|
|
678
|
-
),
|
|
679
|
-
srcAddress: log.address,
|
|
680
|
-
logIndex: log.logIndex,
|
|
681
|
-
}->Internal.fromGenericEvent,
|
|
682
|
-
}: Internal.eventItem
|
|
683
|
-
)
|
|
680
|
+
}->Internal.fromGenericEvent,
|
|
681
|
+
})
|
|
684
682
|
}
|
|
685
683
|
)(),
|
|
686
684
|
)
|
package/src/sources/Source.res
CHANGED
|
@@ -13,7 +13,7 @@ Thes response returned from a block range fetch
|
|
|
13
13
|
type blockRangeFetchResponse = {
|
|
14
14
|
currentBlockHeight: int,
|
|
15
15
|
reorgGuard: ReorgDetection.reorgGuard,
|
|
16
|
-
parsedQueueItems: array<Internal.
|
|
16
|
+
parsedQueueItems: array<Internal.item>,
|
|
17
17
|
fromBlockQueried: int,
|
|
18
18
|
latestFetchedBlockNumber: int,
|
|
19
19
|
latestFetchedBlockTimestamp: int,
|