envio 3.3.0-alpha.6 → 3.3.0-alpha.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/index.d.ts +23 -5
- package/package.json +6 -6
- package/src/Address.res +5 -2
- package/src/Address.res.mjs +3 -1
- package/src/Api.res +1 -1
- package/src/Api.res.mjs +1 -1
- package/src/ChainFetching.res +34 -34
- package/src/ChainFetching.res.mjs +29 -29
- package/src/ChainState.res +328 -165
- package/src/ChainState.res.mjs +205 -100
- package/src/ChainState.resi +16 -7
- package/src/Config.res +55 -27
- package/src/Config.res.mjs +46 -7
- package/src/ContractRegisterContext.res +2 -12
- package/src/ContractRegisterContext.res.mjs +3 -5
- package/src/Core.res +7 -0
- package/src/CrossChainState.res +54 -79
- package/src/CrossChainState.res.mjs +45 -60
- package/src/CrossChainState.resi +1 -1
- package/src/Ecosystem.res +3 -3
- package/src/Ecosystem.res.mjs +3 -3
- package/src/Envio.res +14 -9
- package/src/EventConfigBuilder.res +105 -56
- package/src/EventConfigBuilder.res.mjs +69 -33
- package/src/EventProcessing.res +19 -15
- package/src/EventProcessing.res.mjs +13 -12
- package/src/FetchState.res +383 -182
- package/src/FetchState.res.mjs +260 -264
- package/src/HandlerLoader.res +7 -112
- package/src/HandlerLoader.res.mjs +1 -87
- package/src/HandlerRegister.res +209 -6
- package/src/HandlerRegister.res.mjs +90 -5
- package/src/HandlerRegister.resi +13 -2
- package/src/IndexerState.res +6 -3
- package/src/IndexerState.res.mjs +3 -3
- package/src/IndexerState.resi +1 -1
- package/src/IndexingAddresses.res +10 -7
- package/src/IndexingAddresses.res.mjs +8 -7
- package/src/IndexingAddresses.resi +3 -1
- package/src/Internal.res +82 -36
- package/src/Internal.res.mjs +11 -1
- package/src/Main.res +22 -23
- package/src/Main.res.mjs +15 -17
- package/src/Metrics.res +43 -2
- package/src/Metrics.res.mjs +39 -3
- package/src/Prometheus.res +0 -35
- package/src/Prometheus.res.mjs +33 -68
- package/src/RawEvent.res +7 -2
- package/src/RawEvent.res.mjs +4 -4
- package/src/SimulateItems.res +26 -8
- package/src/SimulateItems.res.mjs +11 -14
- package/src/TestIndexer.res +1 -1
- package/src/TestIndexer.res.mjs +1 -1
- package/src/sources/BlockStore.res +46 -0
- package/src/sources/BlockStore.res.mjs +24 -0
- package/src/sources/EventRouter.res +19 -12
- package/src/sources/EventRouter.res.mjs +7 -5
- package/src/sources/Evm.res +54 -4
- package/src/sources/Evm.res.mjs +43 -4
- package/src/sources/EvmChain.res +14 -18
- package/src/sources/EvmChain.res.mjs +12 -13
- package/src/sources/FieldMask.res +39 -0
- package/src/sources/FieldMask.res.mjs +42 -0
- package/src/sources/Fuel.res +5 -2
- package/src/sources/Fuel.res.mjs +4 -3
- package/src/sources/HyperFuelSource.res +32 -40
- package/src/sources/HyperFuelSource.res.mjs +53 -45
- package/src/sources/HyperSync.res +35 -9
- package/src/sources/HyperSync.res.mjs +52 -35
- package/src/sources/HyperSync.resi +11 -3
- package/src/sources/HyperSyncClient.res +15 -4
- package/src/sources/HyperSyncHeightStream.res +1 -8
- package/src/sources/HyperSyncHeightStream.res.mjs +0 -2
- package/src/sources/HyperSyncSource.res +39 -58
- package/src/sources/HyperSyncSource.res.mjs +44 -44
- package/src/sources/RpcSource.res +114 -92
- package/src/sources/RpcSource.res.mjs +77 -46
- package/src/sources/RpcWebSocketHeightStream.res +0 -5
- package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -2
- package/src/sources/SimulateSource.res +6 -3
- package/src/sources/SimulateSource.res.mjs +13 -5
- package/src/sources/Source.res +25 -5
- package/src/sources/SourceManager.res +66 -3
- package/src/sources/SourceManager.res.mjs +55 -7
- package/src/sources/SourceManager.resi +10 -0
- package/src/sources/Svm.res +15 -10
- package/src/sources/Svm.res.mjs +24 -7
- package/src/sources/SvmHyperSyncClient.res +5 -6
- package/src/sources/SvmHyperSyncSource.res +84 -41
- package/src/sources/SvmHyperSyncSource.res.mjs +90 -43
- package/src/sources/TransactionStore.res +6 -107
- package/src/sources/TransactionStore.res.mjs +5 -86
- package/svm.schema.json +19 -0
|
@@ -17,16 +17,14 @@ let getSelectionConfig = (selection: FetchState.selection, ~chain) => {
|
|
|
17
17
|
let noAddressesTopicSelections = []
|
|
18
18
|
let contractNames = Utils.Set.make()
|
|
19
19
|
|
|
20
|
-
selection.
|
|
21
|
-
->(Utils.magic: array<Internal.
|
|
22
|
-
->Array.forEach(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
selectedBlockFields,
|
|
27
|
-
|
|
28
|
-
isWildcard,
|
|
29
|
-
}) => {
|
|
20
|
+
selection.onEventRegistrations
|
|
21
|
+
->(Utils.magic: array<Internal.onEventRegistration> => array<Internal.evmOnEventRegistration>)
|
|
22
|
+
->Array.forEach(reg => {
|
|
23
|
+
let eventConfig =
|
|
24
|
+
reg.eventConfig->(Utils.magic: Internal.eventConfig => Internal.evmEventConfig)
|
|
25
|
+
let contractName = eventConfig.contractName
|
|
26
|
+
let {selectedBlockFields, selectedTransactionFields} = eventConfig
|
|
27
|
+
let {dependsOnAddresses, getEventFiltersOrThrow, isWildcard} = reg
|
|
30
28
|
selectedBlockFields
|
|
31
29
|
->Utils.Set.toArray
|
|
32
30
|
->Array.forEach(name =>
|
|
@@ -141,7 +139,7 @@ type options = {
|
|
|
141
139
|
chain: ChainMap.Chain.t,
|
|
142
140
|
endpointUrl: string,
|
|
143
141
|
allEventParams: array<HyperSyncClient.Decoder.eventParamsInput>,
|
|
144
|
-
eventRouter: EventRouter.t<Internal.
|
|
142
|
+
eventRouter: EventRouter.t<Internal.evmOnEventRegistration>,
|
|
145
143
|
apiToken: option<string>,
|
|
146
144
|
clientTimeoutMillis: int,
|
|
147
145
|
lowercaseAddresses: bool,
|
|
@@ -197,27 +195,25 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
197
195
|
|
|
198
196
|
let makeEventBatchQueueItem = (
|
|
199
197
|
item: HyperSyncClient.EventItems.item,
|
|
200
|
-
~block: HyperSyncClient.ResponseTypes.block,
|
|
201
198
|
~params: Internal.eventParams,
|
|
202
|
-
~
|
|
199
|
+
~onEventRegistration: Internal.evmOnEventRegistration,
|
|
203
200
|
): Internal.item => {
|
|
204
201
|
let {transactionIndex, logIndex, srcAddress} = item
|
|
205
202
|
let chainId = chain->ChainMap.Chain.toChainId
|
|
206
203
|
|
|
207
204
|
Internal.Event({
|
|
208
|
-
|
|
209
|
-
timestamp: block.timestamp->Option.getUnsafe,
|
|
205
|
+
onEventRegistration: (onEventRegistration :> Internal.onEventRegistration),
|
|
210
206
|
chain,
|
|
211
207
|
blockNumber: item.blockNumber,
|
|
212
|
-
blockHash: block.hash->Option.getUnsafe,
|
|
213
208
|
logIndex,
|
|
214
209
|
transactionIndex,
|
|
210
|
+
// `block` and `transaction` are omitted; they're materialised from the
|
|
211
|
+
// per-chain stores onto the payload at batch prep.
|
|
215
212
|
payload: {
|
|
216
|
-
contractName: eventConfig.contractName,
|
|
217
|
-
eventName: eventConfig.name,
|
|
213
|
+
contractName: onEventRegistration.eventConfig.contractName,
|
|
214
|
+
eventName: onEventRegistration.eventConfig.name,
|
|
218
215
|
chainId,
|
|
219
216
|
params,
|
|
220
|
-
block: block->(Utils.magic: HyperSyncClient.ResponseTypes.block => Internal.eventBlock),
|
|
221
217
|
srcAddress,
|
|
222
218
|
logIndex,
|
|
223
219
|
}->Evm.fromPayload,
|
|
@@ -232,6 +228,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
232
228
|
~knownHeight,
|
|
233
229
|
~partitionId as _,
|
|
234
230
|
~selection,
|
|
231
|
+
~itemsTarget,
|
|
235
232
|
~retry,
|
|
236
233
|
~logger,
|
|
237
234
|
) => {
|
|
@@ -247,17 +244,13 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
247
244
|
let startFetchingBatchTimeRef = Performance.now()
|
|
248
245
|
|
|
249
246
|
//fetch batch
|
|
250
|
-
Prometheus.SourceRequestCount.increment(
|
|
251
|
-
~sourceName=name,
|
|
252
|
-
~chainId=chain->ChainMap.Chain.toChainId,
|
|
253
|
-
~method="getLogs",
|
|
254
|
-
)
|
|
255
247
|
let pageUnsafe = try await HyperSync.GetLogs.query(
|
|
256
248
|
~client,
|
|
257
249
|
~fromBlock,
|
|
258
250
|
~toBlock,
|
|
259
251
|
~logSelections,
|
|
260
252
|
~fieldSelection=selectionConfig.fieldSelection,
|
|
253
|
+
~maxNumLogs=itemsTarget,
|
|
261
254
|
) catch {
|
|
262
255
|
| HyperSync.GetLogs.Error(error) =>
|
|
263
256
|
throw(
|
|
@@ -305,6 +298,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
305
298
|
}
|
|
306
299
|
|
|
307
300
|
let pageFetchTime = startFetchingBatchTimeRef->Performance.secondsSince
|
|
301
|
+
let requestStats = [{Source.method: "getLogs", seconds: pageFetchTime}]
|
|
308
302
|
|
|
309
303
|
//set height and next from block
|
|
310
304
|
let knownHeight = pageUnsafe.archiveHeight
|
|
@@ -319,28 +313,25 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
319
313
|
//Parse page items into queue items
|
|
320
314
|
let parsedQueueItems = []
|
|
321
315
|
|
|
322
|
-
//
|
|
316
|
+
// Block headers are returned once per number; items reference them by blockNumber.
|
|
323
317
|
let blocksByNumber = Utils.Map.make()
|
|
324
318
|
pageUnsafe.blocks->Array.forEach(block => {
|
|
325
|
-
|
|
326
|
-
| Some(number) => blocksByNumber->Utils.Map.set(number, block)->ignore
|
|
327
|
-
| None => ()
|
|
328
|
-
}
|
|
319
|
+
blocksByNumber->Utils.Map.set(block.number, block)->ignore
|
|
329
320
|
})
|
|
330
321
|
let getBlock = blockNumber => blocksByNumber->Utils.Map.unsafeGet(blockNumber)
|
|
331
322
|
|
|
332
323
|
let handleDecodeFailure = (
|
|
333
|
-
~
|
|
324
|
+
~onEventRegistration: Internal.evmOnEventRegistration,
|
|
334
325
|
~logIndex,
|
|
335
326
|
~blockNumber,
|
|
336
327
|
~chainId,
|
|
337
328
|
~exn,
|
|
338
329
|
) => {
|
|
339
|
-
if !
|
|
330
|
+
if !onEventRegistration.isWildcard {
|
|
340
331
|
//Wildcard events can be parsed as undefined if the number of topics
|
|
341
332
|
//don't match the event with the given topic0
|
|
342
333
|
//Non wildcard events should be expected to be parsed
|
|
343
|
-
let msg = `Event ${eventConfig.name} was unexpectedly parsed as undefined`
|
|
334
|
+
let msg = `Event ${onEventRegistration.eventConfig.name} was unexpectedly parsed as undefined`
|
|
344
335
|
let logger = Logging.createChildFrom(
|
|
345
336
|
~logger,
|
|
346
337
|
~params={
|
|
@@ -368,19 +359,17 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
368
359
|
|
|
369
360
|
switch maybeEventConfig {
|
|
370
361
|
| None => () //ignore events that aren't registered
|
|
371
|
-
| Some(
|
|
362
|
+
| Some(onEventRegistration) =>
|
|
372
363
|
switch item.params
|
|
373
364
|
->Nullable.toOption
|
|
374
|
-
->Option.flatMap(Dict.get(_, eventConfig.contractName)) {
|
|
365
|
+
->Option.flatMap(Dict.get(_, onEventRegistration.eventConfig.contractName)) {
|
|
375
366
|
| Some(params) =>
|
|
376
367
|
parsedQueueItems
|
|
377
|
-
->Array.push(
|
|
378
|
-
makeEventBatchQueueItem(item, ~block=getBlock(item.blockNumber), ~params, ~eventConfig),
|
|
379
|
-
)
|
|
368
|
+
->Array.push(makeEventBatchQueueItem(item, ~params, ~onEventRegistration))
|
|
380
369
|
->ignore
|
|
381
370
|
| None =>
|
|
382
371
|
handleDecodeFailure(
|
|
383
|
-
~
|
|
372
|
+
~onEventRegistration,
|
|
384
373
|
~logIndex=item.logIndex,
|
|
385
374
|
~blockNumber=item.blockNumber,
|
|
386
375
|
~chainId,
|
|
@@ -398,11 +387,9 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
398
387
|
// detection notices same-block-number-different-hash collisions itself.
|
|
399
388
|
let blockHashes = []
|
|
400
389
|
pageUnsafe.blocks->Array.forEach(block => {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
| _ => ()
|
|
405
|
-
}
|
|
390
|
+
blockHashes
|
|
391
|
+
->Array.push({ReorgDetection.blockNumber: block.number, blockHash: block.hash})
|
|
392
|
+
->ignore
|
|
406
393
|
})
|
|
407
394
|
switch pageUnsafe.rollbackGuard {
|
|
408
395
|
| None => ()
|
|
@@ -426,7 +413,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
426
413
|
| None =>
|
|
427
414
|
switch pageUnsafe.items->Array.get(pageUnsafe.items->Array.length - 1) {
|
|
428
415
|
| Some(item) if item.blockNumber == heighestBlockQueried =>
|
|
429
|
-
getBlock(item.blockNumber).timestamp
|
|
416
|
+
getBlock(item.blockNumber).timestamp
|
|
430
417
|
| _ => 0
|
|
431
418
|
}
|
|
432
419
|
}
|
|
@@ -443,11 +430,13 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
443
430
|
latestFetchedBlockTimestamp,
|
|
444
431
|
parsedQueueItems,
|
|
445
432
|
transactionStore: Some(pageUnsafe.transactionStore),
|
|
433
|
+
blockStore: Some(pageUnsafe.blockStore),
|
|
446
434
|
latestFetchedBlockNumber: heighestBlockQueried,
|
|
447
435
|
stats,
|
|
448
436
|
knownHeight,
|
|
449
437
|
blockHashes,
|
|
450
438
|
fromBlockQueried: fromBlock,
|
|
439
|
+
requestStats,
|
|
451
440
|
}
|
|
452
441
|
}
|
|
453
442
|
|
|
@@ -458,7 +447,10 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
458
447
|
~sourceName=name,
|
|
459
448
|
~chainId=chain->ChainMap.Chain.toChainId,
|
|
460
449
|
~logger,
|
|
461
|
-
)->Promise.thenResolve(
|
|
450
|
+
)->Promise.thenResolve(((queryRes, requestStats)) => {
|
|
451
|
+
Source.result: queryRes->HyperSync.mapExn,
|
|
452
|
+
requestStats,
|
|
453
|
+
})
|
|
462
454
|
|
|
463
455
|
{
|
|
464
456
|
name,
|
|
@@ -469,7 +461,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
469
461
|
getBlockHashes,
|
|
470
462
|
getHeightOrThrow: async () => {
|
|
471
463
|
let timerRef = Performance.now()
|
|
472
|
-
let
|
|
464
|
+
let height = try {
|
|
473
465
|
await client.getHeight()
|
|
474
466
|
} catch {
|
|
475
467
|
| JsExn(e) =>
|
|
@@ -483,18 +475,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
483
475
|
}
|
|
484
476
|
}
|
|
485
477
|
let seconds = timerRef->Performance.secondsSince
|
|
486
|
-
|
|
487
|
-
~sourceName=name,
|
|
488
|
-
~chainId=chain->ChainMap.Chain.toChainId,
|
|
489
|
-
~method="getHeight",
|
|
490
|
-
)
|
|
491
|
-
Prometheus.SourceRequestCount.addSeconds(
|
|
492
|
-
~sourceName=name,
|
|
493
|
-
~chainId=chain->ChainMap.Chain.toChainId,
|
|
494
|
-
~method="getHeight",
|
|
495
|
-
~seconds,
|
|
496
|
-
)
|
|
497
|
-
result
|
|
478
|
+
{height, requestStats: [{method: "getHeight", seconds}]}
|
|
498
479
|
},
|
|
499
480
|
getItemsOrThrow,
|
|
500
481
|
createHeightSubscription: (~onHeight) =>
|
|
@@ -4,7 +4,6 @@ import * as Utils from "../Utils.res.mjs";
|
|
|
4
4
|
import * as Source from "./Source.res.mjs";
|
|
5
5
|
import * as Logging from "../Logging.res.mjs";
|
|
6
6
|
import * as HyperSync from "./HyperSync.res.mjs";
|
|
7
|
-
import * as Prometheus from "../Prometheus.res.mjs";
|
|
8
7
|
import * as EventRouter from "./EventRouter.res.mjs";
|
|
9
8
|
import * as Performance from "../bindings/Performance.res.mjs";
|
|
10
9
|
import * as LogSelection from "../LogSelection.res.mjs";
|
|
@@ -25,24 +24,25 @@ function getSelectionConfig(selection, chain) {
|
|
|
25
24
|
let dynamicWildcardEventFiltersByContract = {};
|
|
26
25
|
let noAddressesTopicSelections = [];
|
|
27
26
|
let contractNames = new Set();
|
|
28
|
-
selection.
|
|
29
|
-
let
|
|
30
|
-
|
|
27
|
+
selection.onEventRegistrations.forEach(reg => {
|
|
28
|
+
let eventConfig = reg.eventConfig;
|
|
29
|
+
let contractName = eventConfig.contractName;
|
|
30
|
+
Array.from(eventConfig.selectedBlockFields).forEach(name => {
|
|
31
31
|
capitalizedBlockFields.add(Utils.$$String.capitalize(name));
|
|
32
32
|
});
|
|
33
|
-
Array.from(
|
|
33
|
+
Array.from(eventConfig.selectedTransactionFields).forEach(name => {
|
|
34
34
|
if (name !== "transactionIndex") {
|
|
35
35
|
capitalizedTransactionFields.add(Utils.$$String.capitalize(name));
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
-
let eventFilters =
|
|
40
|
-
if (
|
|
39
|
+
let eventFilters = reg.getEventFiltersOrThrow(chain);
|
|
40
|
+
if (reg.dependsOnAddresses) {
|
|
41
41
|
contractNames.add(contractName);
|
|
42
42
|
if (eventFilters.TAG === "Static") {
|
|
43
43
|
return Utils.Dict.pushMany(staticTopicSelectionsByContract, contractName, eventFilters._0);
|
|
44
44
|
} else {
|
|
45
|
-
return Utils.Dict.push(
|
|
45
|
+
return Utils.Dict.push(reg.isWildcard ? dynamicWildcardEventFiltersByContract : dynamicEventFiltersByContract, contractName, eventFilters._0);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
let tmp;
|
|
@@ -127,29 +127,26 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
127
127
|
client = ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate the hypersync client, please double check your ABI", exn);
|
|
128
128
|
}
|
|
129
129
|
let UndefinedValue = /* @__PURE__ */Primitive_exceptions.create("UndefinedValue");
|
|
130
|
-
let makeEventBatchQueueItem = (item,
|
|
130
|
+
let makeEventBatchQueueItem = (item, params, onEventRegistration) => {
|
|
131
131
|
let logIndex = item.logIndex;
|
|
132
132
|
return {
|
|
133
133
|
kind: 0,
|
|
134
|
-
|
|
135
|
-
timestamp: block.timestamp,
|
|
134
|
+
onEventRegistration: onEventRegistration,
|
|
136
135
|
chain: chain,
|
|
137
136
|
blockNumber: item.blockNumber,
|
|
138
|
-
blockHash: block.hash,
|
|
139
137
|
logIndex: logIndex,
|
|
140
138
|
transactionIndex: item.transactionIndex,
|
|
141
139
|
payload: {
|
|
142
|
-
contractName: eventConfig.contractName,
|
|
143
|
-
eventName: eventConfig.name,
|
|
140
|
+
contractName: onEventRegistration.eventConfig.contractName,
|
|
141
|
+
eventName: onEventRegistration.eventConfig.name,
|
|
144
142
|
params: params,
|
|
145
143
|
chainId: chain,
|
|
146
144
|
srcAddress: item.srcAddress,
|
|
147
|
-
logIndex: logIndex
|
|
148
|
-
block: block
|
|
145
|
+
logIndex: logIndex
|
|
149
146
|
}
|
|
150
147
|
};
|
|
151
148
|
};
|
|
152
|
-
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, contractNameByAddress, knownHeight, param, selection, retry, logger) => {
|
|
149
|
+
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, contractNameByAddress, knownHeight, param, selection, itemsTarget, retry, logger) => {
|
|
153
150
|
let totalTimeRef = Performance.now();
|
|
154
151
|
let selectionConfig = getSelectionConfig(selection);
|
|
155
152
|
let logSelections;
|
|
@@ -160,10 +157,9 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
160
157
|
logSelections = ErrorHandling.mkLogAndRaise(logger, "Failed getting log selection for the query", exn);
|
|
161
158
|
}
|
|
162
159
|
let startFetchingBatchTimeRef = Performance.now();
|
|
163
|
-
Prometheus.SourceRequestCount.increment(name, chain, "getLogs");
|
|
164
160
|
let pageUnsafe;
|
|
165
161
|
try {
|
|
166
|
-
pageUnsafe = await HyperSync.GetLogs.query(client, fromBlock, toBlock, logSelections, selectionConfig.fieldSelection);
|
|
162
|
+
pageUnsafe = await HyperSync.GetLogs.query(client, fromBlock, toBlock, logSelections, selectionConfig.fieldSelection, itemsTarget);
|
|
167
163
|
} catch (raw_error) {
|
|
168
164
|
let error = Primitive_exceptions.internalToException(raw_error);
|
|
169
165
|
if (error.RE_EXN_ID === HyperSync.GetLogs.$$Error) {
|
|
@@ -212,26 +208,26 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
212
208
|
};
|
|
213
209
|
}
|
|
214
210
|
let pageFetchTime = Performance.secondsSince(startFetchingBatchTimeRef);
|
|
211
|
+
let requestStats = [{
|
|
212
|
+
method: "getLogs",
|
|
213
|
+
seconds: pageFetchTime
|
|
214
|
+
}];
|
|
215
215
|
let knownHeight$1 = pageUnsafe.archiveHeight;
|
|
216
216
|
let heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
|
|
217
217
|
let parsingTimeRef = Performance.now();
|
|
218
218
|
let parsedQueueItems = [];
|
|
219
219
|
let blocksByNumber = new Map();
|
|
220
220
|
pageUnsafe.blocks.forEach(block => {
|
|
221
|
-
|
|
222
|
-
if (number !== undefined) {
|
|
223
|
-
blocksByNumber.set(number, block);
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
221
|
+
blocksByNumber.set(block.number, block);
|
|
226
222
|
});
|
|
227
223
|
pageUnsafe.items.forEach(item => {
|
|
228
224
|
let maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(item.topic0, item.topicCount), item.srcAddress, contractNameByAddress);
|
|
229
225
|
if (maybeEventConfig === undefined) {
|
|
230
226
|
return;
|
|
231
227
|
}
|
|
232
|
-
let params = Stdlib_Option.flatMap(Primitive_option.fromNullable(item.params), __x => __x[maybeEventConfig.contractName]);
|
|
228
|
+
let params = Stdlib_Option.flatMap(Primitive_option.fromNullable(item.params), __x => __x[maybeEventConfig.eventConfig.contractName]);
|
|
233
229
|
if (params !== undefined) {
|
|
234
|
-
parsedQueueItems.push(makeEventBatchQueueItem(item,
|
|
230
|
+
parsedQueueItems.push(makeEventBatchQueueItem(item, Primitive_option.valFromOption(params), maybeEventConfig));
|
|
235
231
|
return;
|
|
236
232
|
} else {
|
|
237
233
|
let logIndex = item.logIndex;
|
|
@@ -242,7 +238,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
242
238
|
if (maybeEventConfig.isWildcard) {
|
|
243
239
|
return;
|
|
244
240
|
}
|
|
245
|
-
let msg = `Event ` + maybeEventConfig.name + ` was unexpectedly parsed as undefined`;
|
|
241
|
+
let msg = `Event ` + maybeEventConfig.eventConfig.name + ` was unexpectedly parsed as undefined`;
|
|
246
242
|
let logger$1 = Logging.createChildFrom(logger, {
|
|
247
243
|
chainId: chain,
|
|
248
244
|
blockNumber: blockNumber,
|
|
@@ -255,15 +251,10 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
255
251
|
let parsingTimeElapsed = Performance.secondsSince(parsingTimeRef);
|
|
256
252
|
let blockHashes = [];
|
|
257
253
|
pageUnsafe.blocks.forEach(block => {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
blockHash: match$1,
|
|
263
|
-
blockNumber: match
|
|
264
|
-
});
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
254
|
+
blockHashes.push({
|
|
255
|
+
blockHash: block.hash,
|
|
256
|
+
blockNumber: block.number
|
|
257
|
+
});
|
|
267
258
|
});
|
|
268
259
|
let match = pageUnsafe.rollbackGuard;
|
|
269
260
|
if (match !== undefined) {
|
|
@@ -297,13 +288,18 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
297
288
|
blockHashes: blockHashes,
|
|
298
289
|
parsedQueueItems: parsedQueueItems,
|
|
299
290
|
transactionStore: Primitive_option.some(pageUnsafe.transactionStore),
|
|
291
|
+
blockStore: Primitive_option.some(pageUnsafe.blockStore),
|
|
300
292
|
fromBlockQueried: fromBlock,
|
|
301
293
|
latestFetchedBlockNumber: heighestBlockQueried,
|
|
302
294
|
latestFetchedBlockTimestamp: latestFetchedBlockTimestamp,
|
|
303
|
-
stats: stats
|
|
295
|
+
stats: stats,
|
|
296
|
+
requestStats: requestStats
|
|
304
297
|
};
|
|
305
298
|
};
|
|
306
|
-
let getBlockHashes = (blockNumbers, logger) => HyperSync.queryBlockDataMulti(client, blockNumbers, name, chain, logger).then(
|
|
299
|
+
let getBlockHashes = (blockNumbers, logger) => HyperSync.queryBlockDataMulti(client, blockNumbers, name, chain, logger).then(param => ({
|
|
300
|
+
result: HyperSync.mapExn(param[0]),
|
|
301
|
+
requestStats: param[1]
|
|
302
|
+
}));
|
|
307
303
|
return {
|
|
308
304
|
name: name,
|
|
309
305
|
sourceFor: "Sync",
|
|
@@ -313,9 +309,9 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
313
309
|
getBlockHashes: getBlockHashes,
|
|
314
310
|
getHeightOrThrow: async () => {
|
|
315
311
|
let timerRef = Performance.now();
|
|
316
|
-
let
|
|
312
|
+
let height;
|
|
317
313
|
try {
|
|
318
|
-
|
|
314
|
+
height = await client.getHeight();
|
|
319
315
|
} catch (raw_e) {
|
|
320
316
|
let e = Primitive_exceptions.internalToException(raw_e);
|
|
321
317
|
if (e.RE_EXN_ID === "JsExn") {
|
|
@@ -325,7 +321,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
325
321
|
if (message.includes("401 Unauthorized")) {
|
|
326
322
|
Logging.error(`Your ENVIO_API_TOKEN was rejected by HyperSync (401 Unauthorized). The indexer will not be able to fetch events. Update the token and try again using 'envio start' or 'envio dev'. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens`);
|
|
327
323
|
await new Promise((param, param$1) => {});
|
|
328
|
-
|
|
324
|
+
height = 0;
|
|
329
325
|
} else {
|
|
330
326
|
throw {
|
|
331
327
|
RE_EXN_ID: "JsExn",
|
|
@@ -345,9 +341,13 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
345
341
|
}
|
|
346
342
|
}
|
|
347
343
|
let seconds = Performance.secondsSince(timerRef);
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
344
|
+
return {
|
|
345
|
+
height: height,
|
|
346
|
+
requestStats: [{
|
|
347
|
+
method: "getHeight",
|
|
348
|
+
seconds: seconds
|
|
349
|
+
}]
|
|
350
|
+
};
|
|
351
351
|
},
|
|
352
352
|
getItemsOrThrow: getItemsOrThrow,
|
|
353
353
|
createHeightSubscription: onHeight => HyperSyncHeightStream.subscribe(endpointUrl, apiToken$1, chain, onHeight)
|