envio 3.3.0-alpha.7 → 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/Api.res +1 -1
- package/src/Api.res.mjs +1 -1
- package/src/ChainFetching.res +21 -10
- package/src/ChainFetching.res.mjs +11 -10
- package/src/ChainState.res +328 -165
- package/src/ChainState.res.mjs +205 -100
- package/src/ChainState.resi +16 -7
- package/src/Config.res +11 -27
- package/src/Config.res.mjs +8 -7
- package/src/Core.res +7 -0
- package/src/CrossChainState.res +53 -80
- package/src/CrossChainState.res.mjs +43 -59
- 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 +375 -171
- package/src/FetchState.res.mjs +249 -251
- 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 +20 -7
- package/src/SimulateItems.res.mjs +7 -11
- 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 +31 -40
- package/src/sources/HyperFuelSource.res.mjs +52 -44
- package/src/sources/HyperSync.res +31 -9
- package/src/sources/HyperSync.res.mjs +47 -31
- package/src/sources/HyperSync.resi +10 -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 +37 -58
- package/src/sources/HyperSyncSource.res.mjs +42 -42
- package/src/sources/RpcSource.res +91 -82
- package/src/sources/RpcSource.res.mjs +76 -45
- package/src/sources/RpcWebSocketHeightStream.res +0 -5
- package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -2
- package/src/sources/SimulateSource.res +5 -3
- package/src/sources/SimulateSource.res.mjs +12 -4
- package/src/sources/Source.res +19 -5
- package/src/sources/SourceManager.res +62 -6
- package/src/sources/SourceManager.res.mjs +55 -8
- package/src/sources/SourceManager.resi +10 -0
- package/src/sources/Svm.res +14 -10
- package/src/sources/Svm.res.mjs +23 -6
- package/src/sources/SvmHyperSyncClient.res +5 -6
- package/src/sources/SvmHyperSyncSource.res +82 -41
- package/src/sources/SvmHyperSyncSource.res.mjs +86 -41
- package/src/sources/TransactionStore.res +6 -107
- package/src/sources/TransactionStore.res.mjs +5 -86
- package/svm.schema.json +19 -0
|
@@ -378,20 +378,54 @@ let buildEvmEventConfig = (
|
|
|
378
378
|
~eventName: string,
|
|
379
379
|
~sighash: string,
|
|
380
380
|
~params: array<paramMeta>,
|
|
381
|
+
~blockFields: option<array<Internal.evmBlockField>>=?,
|
|
382
|
+
~transactionFields: option<array<Internal.evmTransactionField>>=?,
|
|
383
|
+
~globalBlockFieldsSet: Utils.Set.t<Internal.evmBlockField>=Utils.Set.make(),
|
|
384
|
+
~globalTransactionFieldsSet: Utils.Set.t<Internal.evmTransactionField>=Utils.Set.make(),
|
|
385
|
+
): Internal.evmEventConfig => {
|
|
386
|
+
let topicCount = params->Array.reduce(1, (acc, p) => p.indexed ? acc + 1 : acc)
|
|
387
|
+
|
|
388
|
+
let (selectedBlockFields, selectedTransactionFields) = resolveFieldSelection(
|
|
389
|
+
~blockFields,
|
|
390
|
+
~transactionFields,
|
|
391
|
+
~globalBlockFieldsSet,
|
|
392
|
+
~globalTransactionFieldsSet,
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
{
|
|
396
|
+
id: sighash ++ "_" ++ topicCount->Int.toString,
|
|
397
|
+
name: eventName,
|
|
398
|
+
contractName,
|
|
399
|
+
paramsRawEventSchema: buildParamsSchema(params),
|
|
400
|
+
simulateParamsSchema: buildSimulateParamsSchema(params),
|
|
401
|
+
selectedBlockFields,
|
|
402
|
+
selectedTransactionFields,
|
|
403
|
+
transactionFieldMask: Evm.eventTransactionFieldMask(selectedTransactionFields),
|
|
404
|
+
blockFieldMask: Evm.eventBlockFieldMask(
|
|
405
|
+
selectedBlockFields->(
|
|
406
|
+
Utils.magic: Utils.Set.t<Internal.evmBlockField> => Utils.Set.t<string>
|
|
407
|
+
),
|
|
408
|
+
),
|
|
409
|
+
sighash,
|
|
410
|
+
topicCount,
|
|
411
|
+
paramsMetadata: params,
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Enrich an EVM definition into a per-(event,chain) registration: resolve the
|
|
416
|
+
// registered `where` (with `probeChainId`) into the lazy `getEventFiltersOrThrow`
|
|
417
|
+
// closure + address filters, and override `startBlock` with `where.block._gte`.
|
|
418
|
+
let buildEvmOnEventRegistration = (
|
|
419
|
+
~eventConfig: Internal.evmEventConfig,
|
|
381
420
|
~isWildcard: bool,
|
|
382
421
|
~handler: option<Internal.handler>,
|
|
383
422
|
~contractRegister: option<Internal.contractRegister>,
|
|
384
423
|
~eventFilters: option<JSON.t>,
|
|
385
424
|
~probeChainId: int,
|
|
386
425
|
~onEventBlockFilterSchema: S.t<option<unknown>>,
|
|
387
|
-
~blockFields: option<array<Internal.evmBlockField>>=?,
|
|
388
|
-
~transactionFields: option<array<Internal.evmTransactionField>>=?,
|
|
389
426
|
~startBlock: option<int>=?,
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
): Internal.evmEventConfig => {
|
|
393
|
-
let topicCount = params->Array.reduce(1, (acc, p) => p.indexed ? acc + 1 : acc)
|
|
394
|
-
let indexedParams = params->Array.filter(p => p.indexed)
|
|
427
|
+
): Internal.evmOnEventRegistration => {
|
|
428
|
+
let indexedParams = eventConfig.paramsMetadata->Array.filter(p => p.indexed)
|
|
395
429
|
|
|
396
430
|
let {
|
|
397
431
|
getEventFiltersOrThrow,
|
|
@@ -400,9 +434,9 @@ let buildEvmEventConfig = (
|
|
|
400
434
|
startBlock: whereStartBlock,
|
|
401
435
|
} = LogSelection.parseEventFiltersOrThrow(
|
|
402
436
|
~eventFilters,
|
|
403
|
-
~sighash,
|
|
437
|
+
~sighash=eventConfig.sighash,
|
|
404
438
|
~params=indexedParams->Array.map(p => p.name),
|
|
405
|
-
~contractName,
|
|
439
|
+
~contractName=eventConfig.contractName,
|
|
406
440
|
~probeChainId,
|
|
407
441
|
~onEventBlockFilterSchema,
|
|
408
442
|
~topic1=?indexedParams->Array.get(0)->Option.map(buildTopicGetter),
|
|
@@ -410,46 +444,32 @@ let buildEvmEventConfig = (
|
|
|
410
444
|
~topic3=?indexedParams->Array.get(2)->Option.map(buildTopicGetter),
|
|
411
445
|
)
|
|
412
446
|
|
|
413
|
-
// `where.block.number._gte` overrides the contract-level startBlock
|
|
414
|
-
//
|
|
415
|
-
//
|
|
416
|
-
// `where.block`, the caller's contract-level value passes through.
|
|
447
|
+
// `where.block.number._gte` overrides the contract-level startBlock when
|
|
448
|
+
// present (an explicit per-event opt-in that wins over `config.yaml`);
|
|
449
|
+
// otherwise the contract/chain value passes through.
|
|
417
450
|
let resolvedStartBlock = switch whereStartBlock {
|
|
418
451
|
| Some(_) as sb => sb
|
|
419
452
|
| None => startBlock
|
|
420
453
|
}
|
|
421
454
|
|
|
422
|
-
let (selectedBlockFields, selectedTransactionFields) = resolveFieldSelection(
|
|
423
|
-
~blockFields,
|
|
424
|
-
~transactionFields,
|
|
425
|
-
~globalBlockFieldsSet,
|
|
426
|
-
~globalTransactionFieldsSet,
|
|
427
|
-
)
|
|
428
|
-
|
|
429
455
|
{
|
|
430
|
-
|
|
431
|
-
name: eventName,
|
|
432
|
-
contractName,
|
|
456
|
+
eventConfig: (eventConfig :> Internal.eventConfig),
|
|
433
457
|
isWildcard,
|
|
434
458
|
handler,
|
|
435
459
|
contractRegister,
|
|
436
|
-
paramsRawEventSchema: buildParamsSchema(params),
|
|
437
|
-
simulateParamsSchema: buildSimulateParamsSchema(params),
|
|
438
460
|
getEventFiltersOrThrow,
|
|
439
461
|
filterByAddresses,
|
|
440
462
|
clientAddressFilter: ?buildAddressFilter(addressFilterParamGroups, ~isWildcard),
|
|
441
|
-
dependsOnAddresses:
|
|
463
|
+
dependsOnAddresses: Internal.dependsOnAddresses(~isWildcard, ~filterByAddresses),
|
|
442
464
|
startBlock: resolvedStartBlock,
|
|
443
|
-
selectedBlockFields,
|
|
444
|
-
selectedTransactionFields,
|
|
445
|
-
transactionFieldMask: Evm.eventTransactionFieldMask(selectedTransactionFields),
|
|
446
|
-
sighash,
|
|
447
|
-
topicCount,
|
|
448
|
-
paramsMetadata: params,
|
|
449
465
|
}
|
|
450
466
|
}
|
|
451
467
|
|
|
452
|
-
// ============== Build
|
|
468
|
+
// ============== Build SVM instruction event config ==============
|
|
469
|
+
|
|
470
|
+
// Always-included block fields (slot, time, hash) are prepended at runtime so
|
|
471
|
+
// they're always present regardless of config.
|
|
472
|
+
let alwaysIncludedSvmBlockFields: array<Internal.svmBlockField> = [Slot, Time, Hash]
|
|
453
473
|
|
|
454
474
|
let buildSvmInstructionEventConfig = (
|
|
455
475
|
~contractName: string,
|
|
@@ -459,15 +479,12 @@ let buildSvmInstructionEventConfig = (
|
|
|
459
479
|
~discriminatorByteLen: int,
|
|
460
480
|
~includeLogs: bool,
|
|
461
481
|
~transactionFields: array<Internal.svmTransactionField>=[],
|
|
482
|
+
~blockFields: array<Internal.svmBlockField>=[],
|
|
462
483
|
~accountFilters: array<Internal.svmAccountFilterGroup>,
|
|
463
484
|
~isInner: option<bool>,
|
|
464
|
-
~isWildcard: bool,
|
|
465
|
-
~handler: option<Internal.handler>,
|
|
466
|
-
~contractRegister: option<Internal.contractRegister>,
|
|
467
485
|
~accounts: array<string>=[],
|
|
468
486
|
~args: JSON.t=JSON.Null,
|
|
469
487
|
~definedTypes: JSON.t=JSON.Null,
|
|
470
|
-
~startBlock: option<int>=?,
|
|
471
488
|
): Internal.svmInstructionEventConfig => {
|
|
472
489
|
let paramsSchema =
|
|
473
490
|
S.json(~validate=false)
|
|
@@ -480,6 +497,12 @@ let buildSvmInstructionEventConfig = (
|
|
|
480
497
|
Utils.Set.fromArray(transactionFields)->(
|
|
481
498
|
Utils.magic: Utils.Set.t<Internal.svmTransactionField> => Utils.Set.t<string>
|
|
482
499
|
)
|
|
500
|
+
let selectedBlockFields = Utils.Set.fromArray(
|
|
501
|
+
Array.concat(alwaysIncludedSvmBlockFields, blockFields),
|
|
502
|
+
)
|
|
503
|
+
let blockFieldMask = Svm.eventBlockFieldMask(
|
|
504
|
+
selectedBlockFields->(Utils.magic: Utils.Set.t<Internal.svmBlockField> => Utils.Set.t<string>),
|
|
505
|
+
)
|
|
483
506
|
{
|
|
484
507
|
id: switch discriminator {
|
|
485
508
|
| Some(d) => d
|
|
@@ -487,21 +510,16 @@ let buildSvmInstructionEventConfig = (
|
|
|
487
510
|
},
|
|
488
511
|
name: instructionName,
|
|
489
512
|
contractName,
|
|
490
|
-
isWildcard,
|
|
491
|
-
handler,
|
|
492
|
-
contractRegister,
|
|
493
513
|
paramsRawEventSchema: paramsSchema,
|
|
494
514
|
simulateParamsSchema: paramsSchema,
|
|
495
|
-
filterByAddresses: false,
|
|
496
|
-
dependsOnAddresses: !isWildcard,
|
|
497
|
-
clientAddressFilter: ?buildAddressFilter([], ~isWildcard, ~srcAddressExpr="event.programId"),
|
|
498
|
-
startBlock,
|
|
499
515
|
programId,
|
|
500
516
|
discriminator,
|
|
501
517
|
discriminatorByteLen,
|
|
502
518
|
includeLogs,
|
|
503
519
|
selectedTransactionFields,
|
|
504
520
|
transactionFieldMask: Svm.eventTransactionFieldMask(selectedTransactionFields),
|
|
521
|
+
selectedBlockFields,
|
|
522
|
+
blockFieldMask,
|
|
505
523
|
accountFilters,
|
|
506
524
|
isInner,
|
|
507
525
|
accounts,
|
|
@@ -510,16 +528,33 @@ let buildSvmInstructionEventConfig = (
|
|
|
510
528
|
}
|
|
511
529
|
}
|
|
512
530
|
|
|
531
|
+
// Enrich an SVM definition into a registration. SVM has no `where`; only the
|
|
532
|
+
// handler binding + wildcard-derived address gate are registration state.
|
|
533
|
+
let buildSvmOnEventRegistration = (
|
|
534
|
+
~eventConfig: Internal.svmInstructionEventConfig,
|
|
535
|
+
~isWildcard: bool,
|
|
536
|
+
~handler: option<Internal.handler>,
|
|
537
|
+
~contractRegister: option<Internal.contractRegister>,
|
|
538
|
+
~startBlock: option<int>=?,
|
|
539
|
+
): Internal.svmOnEventRegistration => {
|
|
540
|
+
eventConfig: (eventConfig :> Internal.eventConfig),
|
|
541
|
+
handler,
|
|
542
|
+
contractRegister,
|
|
543
|
+
isWildcard,
|
|
544
|
+
filterByAddresses: false,
|
|
545
|
+
dependsOnAddresses: Internal.dependsOnAddresses(~isWildcard, ~filterByAddresses=false),
|
|
546
|
+
clientAddressFilter: ?buildAddressFilter([], ~isWildcard, ~srcAddressExpr="event.programId"),
|
|
547
|
+
startBlock,
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// ============== Build Fuel event config ==============
|
|
551
|
+
|
|
513
552
|
let buildFuelEventConfig = (
|
|
514
553
|
~contractName: string,
|
|
515
554
|
~eventName: string,
|
|
516
555
|
~kind: string,
|
|
517
556
|
~sighash: string,
|
|
518
557
|
~rawAbi: JSON.t,
|
|
519
|
-
~isWildcard: bool,
|
|
520
|
-
~handler: option<Internal.handler>,
|
|
521
|
-
~contractRegister: option<Internal.contractRegister>,
|
|
522
|
-
~startBlock: option<int>=?,
|
|
523
558
|
): Internal.fuelEventConfig => {
|
|
524
559
|
let fuelKind = switch kind {
|
|
525
560
|
| "logData" =>
|
|
@@ -559,18 +594,32 @@ let buildFuelEventConfig = (
|
|
|
559
594
|
},
|
|
560
595
|
name: eventName,
|
|
561
596
|
contractName,
|
|
562
|
-
isWildcard,
|
|
563
|
-
handler,
|
|
564
|
-
contractRegister,
|
|
565
597
|
paramsRawEventSchema: paramsSchema,
|
|
566
598
|
simulateParamsSchema: paramsSchema,
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
clientAddressFilter: ?buildAddressFilter([], ~isWildcard),
|
|
570
|
-
startBlock,
|
|
571
|
-
// Fuel keeps the transaction inline on the payload; nothing to materialise.
|
|
599
|
+
// Fuel keeps the transaction and block inline on the payload; nothing to
|
|
600
|
+
// materialise.
|
|
572
601
|
selectedTransactionFields: Utils.Set.make(),
|
|
573
602
|
transactionFieldMask: 0.,
|
|
603
|
+
blockFieldMask: 0.,
|
|
574
604
|
kind: fuelKind,
|
|
575
605
|
}
|
|
576
606
|
}
|
|
607
|
+
|
|
608
|
+
// Enrich a Fuel definition into a registration (handler binding +
|
|
609
|
+
// wildcard-derived address gate; Fuel never filters by addresses).
|
|
610
|
+
let buildFuelOnEventRegistration = (
|
|
611
|
+
~eventConfig: Internal.fuelEventConfig,
|
|
612
|
+
~isWildcard: bool,
|
|
613
|
+
~handler: option<Internal.handler>,
|
|
614
|
+
~contractRegister: option<Internal.contractRegister>,
|
|
615
|
+
~startBlock: option<int>=?,
|
|
616
|
+
): Internal.fuelOnEventRegistration => {
|
|
617
|
+
eventConfig: (eventConfig :> Internal.eventConfig),
|
|
618
|
+
handler,
|
|
619
|
+
contractRegister,
|
|
620
|
+
isWildcard,
|
|
621
|
+
filterByAddresses: false,
|
|
622
|
+
dependsOnAddresses: Internal.dependsOnAddresses(~isWildcard, ~filterByAddresses=false),
|
|
623
|
+
clientAddressFilter: ?buildAddressFilter([], ~isWildcard),
|
|
624
|
+
startBlock,
|
|
625
|
+
}
|
|
@@ -280,7 +280,7 @@ function buildAddressFilter(groups, isWildcard, srcAddressExprOpt) {
|
|
|
280
280
|
return Stdlib_Option.map(buildAddressFilterBody(groups, isWildcard, srcAddressExpr), compileAddressFilter);
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
-
function buildEvmEventConfig(contractName, eventName, sighash, params,
|
|
283
|
+
function buildEvmEventConfig(contractName, eventName, sighash, params, blockFields, transactionFields, globalBlockFieldsSetOpt, globalTransactionFieldsSetOpt) {
|
|
284
284
|
let globalBlockFieldsSet = globalBlockFieldsSetOpt !== undefined ? Primitive_option.valFromOption(globalBlockFieldsSetOpt) : new Set();
|
|
285
285
|
let globalTransactionFieldsSet = globalTransactionFieldsSetOpt !== undefined ? Primitive_option.valFromOption(globalTransactionFieldsSetOpt) : new Set();
|
|
286
286
|
let topicCount = Stdlib_Array.reduce(params, 1, (acc, p) => {
|
|
@@ -290,58 +290,70 @@ function buildEvmEventConfig(contractName, eventName, sighash, params, isWildcar
|
|
|
290
290
|
return acc;
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
|
-
let
|
|
294
|
-
let
|
|
295
|
-
let
|
|
296
|
-
let filterByAddresses = match.filterByAddresses;
|
|
297
|
-
let resolvedStartBlock = whereStartBlock !== undefined ? whereStartBlock : startBlock;
|
|
298
|
-
let match$1 = resolveFieldSelection(blockFields, transactionFields, globalBlockFieldsSet, globalTransactionFieldsSet);
|
|
299
|
-
let selectedTransactionFields = match$1[1];
|
|
293
|
+
let match = resolveFieldSelection(blockFields, transactionFields, globalBlockFieldsSet, globalTransactionFieldsSet);
|
|
294
|
+
let selectedTransactionFields = match[1];
|
|
295
|
+
let selectedBlockFields = match[0];
|
|
300
296
|
return {
|
|
301
297
|
id: sighash + "_" + topicCount.toString(),
|
|
302
298
|
name: eventName,
|
|
303
299
|
contractName: contractName,
|
|
304
|
-
isWildcard: isWildcard,
|
|
305
|
-
filterByAddresses: filterByAddresses,
|
|
306
|
-
dependsOnAddresses: !isWildcard || filterByAddresses,
|
|
307
|
-
clientAddressFilter: buildAddressFilter(match.addressFilterParamGroups, isWildcard, undefined),
|
|
308
|
-
handler: handler,
|
|
309
|
-
contractRegister: contractRegister,
|
|
310
300
|
paramsRawEventSchema: buildParamsSchema(params),
|
|
311
301
|
simulateParamsSchema: buildSimulateParamsSchema(params),
|
|
312
|
-
startBlock: resolvedStartBlock,
|
|
313
302
|
selectedTransactionFields: selectedTransactionFields,
|
|
314
303
|
transactionFieldMask: Evm.eventTransactionFieldMask(selectedTransactionFields),
|
|
315
|
-
|
|
316
|
-
selectedBlockFields:
|
|
304
|
+
blockFieldMask: Evm.eventBlockFieldMask(selectedBlockFields),
|
|
305
|
+
selectedBlockFields: selectedBlockFields,
|
|
317
306
|
sighash: sighash,
|
|
318
307
|
topicCount: topicCount,
|
|
319
308
|
paramsMetadata: params
|
|
320
309
|
};
|
|
321
310
|
}
|
|
322
311
|
|
|
323
|
-
function
|
|
312
|
+
function buildEvmOnEventRegistration(eventConfig, isWildcard, handler, contractRegister, eventFilters, probeChainId, onEventBlockFilterSchema, startBlock) {
|
|
313
|
+
let indexedParams = eventConfig.paramsMetadata.filter(p => p.indexed);
|
|
314
|
+
let match = LogSelection.parseEventFiltersOrThrow(eventFilters, eventConfig.sighash, indexedParams.map(p => p.name), eventConfig.contractName, probeChainId, onEventBlockFilterSchema, Stdlib_Option.map(indexedParams[0], buildTopicGetter), Stdlib_Option.map(indexedParams[1], buildTopicGetter), Stdlib_Option.map(indexedParams[2], buildTopicGetter));
|
|
315
|
+
let whereStartBlock = match.startBlock;
|
|
316
|
+
let filterByAddresses = match.filterByAddresses;
|
|
317
|
+
let resolvedStartBlock = whereStartBlock !== undefined ? whereStartBlock : startBlock;
|
|
318
|
+
return {
|
|
319
|
+
eventConfig: eventConfig,
|
|
320
|
+
handler: handler,
|
|
321
|
+
contractRegister: contractRegister,
|
|
322
|
+
isWildcard: isWildcard,
|
|
323
|
+
filterByAddresses: filterByAddresses,
|
|
324
|
+
dependsOnAddresses: Internal.dependsOnAddresses(isWildcard, filterByAddresses),
|
|
325
|
+
clientAddressFilter: buildAddressFilter(match.addressFilterParamGroups, isWildcard, undefined),
|
|
326
|
+
startBlock: resolvedStartBlock,
|
|
327
|
+
getEventFiltersOrThrow: match.getEventFiltersOrThrow
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
let alwaysIncludedSvmBlockFields = [
|
|
332
|
+
"slot",
|
|
333
|
+
"time",
|
|
334
|
+
"hash"
|
|
335
|
+
];
|
|
336
|
+
|
|
337
|
+
function buildSvmInstructionEventConfig(contractName, instructionName, programId, discriminator, discriminatorByteLen, includeLogs, transactionFieldsOpt, blockFieldsOpt, accountFilters, isInner, accountsOpt, argsOpt, definedTypesOpt) {
|
|
324
338
|
let transactionFields = transactionFieldsOpt !== undefined ? transactionFieldsOpt : [];
|
|
339
|
+
let blockFields = blockFieldsOpt !== undefined ? blockFieldsOpt : [];
|
|
325
340
|
let accounts = accountsOpt !== undefined ? accountsOpt : [];
|
|
326
341
|
let args = argsOpt !== undefined ? argsOpt : null;
|
|
327
342
|
let definedTypes = definedTypesOpt !== undefined ? definedTypesOpt : null;
|
|
328
343
|
let paramsSchema = Utils.Schema.coerceToJsonPgType(S$RescriptSchema.json(false));
|
|
329
344
|
let selectedTransactionFields = new Set(transactionFields);
|
|
345
|
+
let selectedBlockFields = new Set(alwaysIncludedSvmBlockFields.concat(blockFields));
|
|
346
|
+
let blockFieldMask = Svm.eventBlockFieldMask(selectedBlockFields);
|
|
330
347
|
return {
|
|
331
348
|
id: discriminator !== undefined ? discriminator : "none",
|
|
332
349
|
name: instructionName,
|
|
333
350
|
contractName: contractName,
|
|
334
|
-
isWildcard: isWildcard,
|
|
335
|
-
filterByAddresses: false,
|
|
336
|
-
dependsOnAddresses: !isWildcard,
|
|
337
|
-
clientAddressFilter: buildAddressFilter([], isWildcard, "event.programId"),
|
|
338
|
-
handler: handler,
|
|
339
|
-
contractRegister: contractRegister,
|
|
340
351
|
paramsRawEventSchema: paramsSchema,
|
|
341
352
|
simulateParamsSchema: paramsSchema,
|
|
342
|
-
startBlock: startBlock,
|
|
343
353
|
selectedTransactionFields: selectedTransactionFields,
|
|
344
354
|
transactionFieldMask: Svm.eventTransactionFieldMask(selectedTransactionFields),
|
|
355
|
+
blockFieldMask: blockFieldMask,
|
|
356
|
+
selectedBlockFields: selectedBlockFields,
|
|
345
357
|
programId: programId,
|
|
346
358
|
discriminator: discriminator,
|
|
347
359
|
discriminatorByteLen: discriminatorByteLen,
|
|
@@ -354,7 +366,20 @@ function buildSvmInstructionEventConfig(contractName, instructionName, programId
|
|
|
354
366
|
};
|
|
355
367
|
}
|
|
356
368
|
|
|
357
|
-
function
|
|
369
|
+
function buildSvmOnEventRegistration(eventConfig, isWildcard, handler, contractRegister, startBlock) {
|
|
370
|
+
return {
|
|
371
|
+
eventConfig: eventConfig,
|
|
372
|
+
handler: handler,
|
|
373
|
+
contractRegister: contractRegister,
|
|
374
|
+
isWildcard: isWildcard,
|
|
375
|
+
filterByAddresses: false,
|
|
376
|
+
dependsOnAddresses: Internal.dependsOnAddresses(isWildcard, false),
|
|
377
|
+
clientAddressFilter: buildAddressFilter([], isWildcard, "event.programId"),
|
|
378
|
+
startBlock: startBlock
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function buildFuelEventConfig(contractName, eventName, kind, sighash, rawAbi) {
|
|
358
383
|
let fuelKind;
|
|
359
384
|
switch (kind) {
|
|
360
385
|
case "burn" :
|
|
@@ -401,21 +426,28 @@ function buildFuelEventConfig(contractName, eventName, kind, sighash, rawAbi, is
|
|
|
401
426
|
id: tmp,
|
|
402
427
|
name: eventName,
|
|
403
428
|
contractName: contractName,
|
|
404
|
-
isWildcard: isWildcard,
|
|
405
|
-
filterByAddresses: false,
|
|
406
|
-
dependsOnAddresses: !isWildcard,
|
|
407
|
-
clientAddressFilter: buildAddressFilter([], isWildcard, undefined),
|
|
408
|
-
handler: handler,
|
|
409
|
-
contractRegister: contractRegister,
|
|
410
429
|
paramsRawEventSchema: paramsSchema,
|
|
411
430
|
simulateParamsSchema: paramsSchema,
|
|
412
|
-
startBlock: startBlock,
|
|
413
431
|
selectedTransactionFields: new Set(),
|
|
414
432
|
transactionFieldMask: 0,
|
|
433
|
+
blockFieldMask: 0,
|
|
415
434
|
kind: fuelKind
|
|
416
435
|
};
|
|
417
436
|
}
|
|
418
437
|
|
|
438
|
+
function buildFuelOnEventRegistration(eventConfig, isWildcard, handler, contractRegister, startBlock) {
|
|
439
|
+
return {
|
|
440
|
+
eventConfig: eventConfig,
|
|
441
|
+
handler: handler,
|
|
442
|
+
contractRegister: contractRegister,
|
|
443
|
+
isWildcard: isWildcard,
|
|
444
|
+
filterByAddresses: false,
|
|
445
|
+
dependsOnAddresses: Internal.dependsOnAddresses(isWildcard, false),
|
|
446
|
+
clientAddressFilter: buildAddressFilter([], isWildcard, undefined),
|
|
447
|
+
startBlock: startBlock
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
419
451
|
export {
|
|
420
452
|
paramMetaSchema,
|
|
421
453
|
normalizeOrThrow,
|
|
@@ -435,7 +467,11 @@ export {
|
|
|
435
467
|
buildAddressFilterBody,
|
|
436
468
|
buildAddressFilter,
|
|
437
469
|
buildEvmEventConfig,
|
|
470
|
+
buildEvmOnEventRegistration,
|
|
471
|
+
alwaysIncludedSvmBlockFields,
|
|
438
472
|
buildSvmInstructionEventConfig,
|
|
473
|
+
buildSvmOnEventRegistration,
|
|
439
474
|
buildFuelEventConfig,
|
|
475
|
+
buildFuelOnEventRegistration,
|
|
440
476
|
}
|
|
441
477
|
/* paramMetaSchema Not a pure module */
|
package/src/EventProcessing.res
CHANGED
|
@@ -74,8 +74,8 @@ let runEventHandlerOrThrow = async (
|
|
|
74
74
|
}
|
|
75
75
|
let handlerDuration = timeBeforeHandler->Performance.secondsSince
|
|
76
76
|
Prometheus.ProcessingHandler.increment(
|
|
77
|
-
~contract=eventItem.eventConfig.contractName,
|
|
78
|
-
~event=eventItem.eventConfig.name,
|
|
77
|
+
~contract=eventItem.onEventRegistration.eventConfig.contractName,
|
|
78
|
+
~event=eventItem.onEventRegistration.eventConfig.name,
|
|
79
79
|
~duration=handlerDuration,
|
|
80
80
|
)
|
|
81
81
|
}
|
|
@@ -90,7 +90,7 @@ let runHandlerOrThrow = async (
|
|
|
90
90
|
~chains: Internal.chains,
|
|
91
91
|
) => {
|
|
92
92
|
switch item {
|
|
93
|
-
| Block({
|
|
93
|
+
| Block({onBlockRegistration: {handler}, blockNumber}) =>
|
|
94
94
|
try {
|
|
95
95
|
let contextParams: UserContext.contextParams = {
|
|
96
96
|
item,
|
|
@@ -121,8 +121,8 @@ let runHandlerOrThrow = async (
|
|
|
121
121
|
}),
|
|
122
122
|
)
|
|
123
123
|
}
|
|
124
|
-
| Event({
|
|
125
|
-
switch
|
|
124
|
+
| Event({onEventRegistration}) =>
|
|
125
|
+
switch onEventRegistration.handler {
|
|
126
126
|
| Some(handler) =>
|
|
127
127
|
await item->runEventHandlerOrThrow(
|
|
128
128
|
~handler,
|
|
@@ -161,7 +161,7 @@ let preloadBatchOrThrow = async (
|
|
|
161
161
|
for idx in 0 to checkpointEventsProcessed - 1 {
|
|
162
162
|
let item = batch.items->Array.getUnsafe(itemIdx.contents + idx)
|
|
163
163
|
switch item {
|
|
164
|
-
| Event({
|
|
164
|
+
| Event({onEventRegistration: {handler, eventConfig: {contractName, name: eventName}}}) =>
|
|
165
165
|
switch handler {
|
|
166
166
|
| None => ()
|
|
167
167
|
| Some(handler) =>
|
|
@@ -200,7 +200,7 @@ let preloadBatchOrThrow = async (
|
|
|
200
200
|
| _ => ()
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
| Block({
|
|
203
|
+
| Block({onBlockRegistration: {handler}, blockNumber}) =>
|
|
204
204
|
try {
|
|
205
205
|
promises->Array.push(
|
|
206
206
|
handler({
|
|
@@ -289,15 +289,19 @@ type logPartitionInfo = {
|
|
|
289
289
|
lastItemBlockNumber?: int,
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
// Off the hot path: bulk-materialise the selected transaction
|
|
293
|
-
// batch's store-backed (HyperSync) items and write them onto the
|
|
294
|
-
// handlers read plain objects. A batch can span chains, each with
|
|
295
|
-
// and field
|
|
296
|
-
let
|
|
292
|
+
// Off the hot path: bulk-materialise the selected transaction and block fields
|
|
293
|
+
// for the batch's store-backed (HyperSync) items and write them onto the
|
|
294
|
+
// payloads, so handlers read plain objects. A batch can span chains, each with
|
|
295
|
+
// its own stores and field masks, so group items by chain before materialising.
|
|
296
|
+
let materializeBatchEvents = async (
|
|
297
|
+
batch: Batch.t,
|
|
298
|
+
~chainStates: dict<ChainState.t>,
|
|
299
|
+
~ecosystem,
|
|
300
|
+
) => {
|
|
297
301
|
switch chainStates->Dict.valuesToArray {
|
|
298
302
|
// Single-chain indexers (the common case): every item belongs to the one
|
|
299
303
|
// chain, so skip the per-chain grouping and its allocations.
|
|
300
|
-
| [cs] => await cs->ChainState.materializeBatchItems(~items=batch.items)
|
|
304
|
+
| [cs] => await cs->ChainState.materializeBatchItems(~items=batch.items, ~ecosystem)
|
|
301
305
|
| _ =>
|
|
302
306
|
let itemsByChain: dict<array<Internal.item>> = Dict.make()
|
|
303
307
|
batch.items->Array.forEach(item => {
|
|
@@ -312,7 +316,7 @@ let materializeBatchTransactions = async (batch: Batch.t, ~chainStates: dict<Cha
|
|
|
312
316
|
->Dict.toArray
|
|
313
317
|
->Array.map(async ((chainId, items)) => {
|
|
314
318
|
let cs = chainStates->Dict.getUnsafe(chainId)
|
|
315
|
-
await cs->ChainState.materializeBatchItems(~items)
|
|
319
|
+
await cs->ChainState.materializeBatchItems(~items, ~ecosystem)
|
|
316
320
|
})
|
|
317
321
|
->Promise.all
|
|
318
322
|
}
|
|
@@ -348,7 +352,7 @@ let processEventBatch = async (
|
|
|
348
352
|
if batch.items->Utils.Array.notEmpty {
|
|
349
353
|
// Materialise store-backed transactions onto payloads before any handler
|
|
350
354
|
// (preload or execute) reads them.
|
|
351
|
-
await
|
|
355
|
+
await materializeBatchEvents(batch, ~chainStates, ~ecosystem=config.ecosystem.name)
|
|
352
356
|
await batch->preloadBatchOrThrow(~loadManager, ~persistence, ~indexerState, ~chains, ~config)
|
|
353
357
|
}
|
|
354
358
|
|
|
@@ -65,12 +65,12 @@ async function runEventHandlerOrThrow(item, checkpointId, handler, indexerState,
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
let handlerDuration = Performance.secondsSince(timeBeforeHandler);
|
|
68
|
-
return Prometheus.ProcessingHandler.increment(item.eventConfig.contractName, item.eventConfig.name, handlerDuration);
|
|
68
|
+
return Prometheus.ProcessingHandler.increment(item.onEventRegistration.eventConfig.contractName, item.onEventRegistration.eventConfig.name, handlerDuration);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
async function runHandlerOrThrow(item, checkpointId, indexerState, loadManager, persistence, config, chains) {
|
|
72
72
|
if (item.kind === 0) {
|
|
73
|
-
let handler = item.
|
|
73
|
+
let handler = item.onEventRegistration.handler;
|
|
74
74
|
if (handler !== undefined) {
|
|
75
75
|
return await runEventHandlerOrThrow(item, checkpointId, handler, indexerState, loadManager, persistence, chains, config);
|
|
76
76
|
} else {
|
|
@@ -89,7 +89,7 @@ async function runHandlerOrThrow(item, checkpointId, indexerState, loadManager,
|
|
|
89
89
|
config: config,
|
|
90
90
|
isResolved: false
|
|
91
91
|
};
|
|
92
|
-
await item.
|
|
92
|
+
await item.onBlockRegistration.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, config.ecosystem, UserContext.getHandlerContext(contextParams)));
|
|
93
93
|
contextParams.isResolved = true;
|
|
94
94
|
return;
|
|
95
95
|
} catch (raw_exn) {
|
|
@@ -113,11 +113,12 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inde
|
|
|
113
113
|
for (let idx = 0; idx < checkpointEventsProcessed; ++idx) {
|
|
114
114
|
let item = batch.items[itemIdx + idx | 0];
|
|
115
115
|
if (item.kind === 0) {
|
|
116
|
-
let match = item.
|
|
116
|
+
let match = item.onEventRegistration;
|
|
117
117
|
let handler = match.handler;
|
|
118
118
|
if (handler !== undefined) {
|
|
119
|
-
let
|
|
120
|
-
let
|
|
119
|
+
let match$1 = match.eventConfig;
|
|
120
|
+
let contractName = match$1.contractName;
|
|
121
|
+
let eventName = match$1.name;
|
|
121
122
|
try {
|
|
122
123
|
let timerRef = Prometheus.PreloadHandler.startOperation(contractName, eventName);
|
|
123
124
|
promises.push(Utils.$$Promise.silentCatch(handler({
|
|
@@ -140,7 +141,7 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inde
|
|
|
140
141
|
}
|
|
141
142
|
} else {
|
|
142
143
|
try {
|
|
143
|
-
promises.push(Utils.$$Promise.silentCatch(item.
|
|
144
|
+
promises.push(Utils.$$Promise.silentCatch(item.onBlockRegistration.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, config.ecosystem, UserContext.getHandlerContext({
|
|
144
145
|
item: item,
|
|
145
146
|
checkpointId: checkpointId,
|
|
146
147
|
indexerState: indexerState,
|
|
@@ -184,7 +185,7 @@ function registerProcessEventBatchMetrics(logger, batch, loadDuration, handlerDu
|
|
|
184
185
|
Prometheus.ProcessingBatch.registerMetrics(loadDuration, handlerDuration);
|
|
185
186
|
}
|
|
186
187
|
|
|
187
|
-
async function
|
|
188
|
+
async function materializeBatchEvents(batch, chainStates, ecosystem) {
|
|
188
189
|
let match = Object.values(chainStates);
|
|
189
190
|
if (match.length !== 1) {
|
|
190
191
|
let itemsByChain = {};
|
|
@@ -199,12 +200,12 @@ async function materializeBatchTransactions(batch, chainStates) {
|
|
|
199
200
|
});
|
|
200
201
|
await Promise.all(Object.entries(itemsByChain).map(async param => {
|
|
201
202
|
let cs = chainStates[param[0]];
|
|
202
|
-
return await ChainState.materializeBatchItems(cs, param[1]);
|
|
203
|
+
return await ChainState.materializeBatchItems(cs, param[1], ecosystem);
|
|
203
204
|
}));
|
|
204
205
|
return;
|
|
205
206
|
}
|
|
206
207
|
let cs = match[0];
|
|
207
|
-
return await ChainState.materializeBatchItems(cs, batch.items);
|
|
208
|
+
return await ChainState.materializeBatchItems(cs, batch.items, ecosystem);
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
async function processEventBatch(batch, indexerState, loadManager, persistence, config, chainStates) {
|
|
@@ -219,7 +220,7 @@ async function processEventBatch(batch, indexerState, loadManager, persistence,
|
|
|
219
220
|
await Writing.awaitCapacity(indexerState);
|
|
220
221
|
let timeRef = Performance.now();
|
|
221
222
|
if (Utils.$$Array.notEmpty(batch.items)) {
|
|
222
|
-
await
|
|
223
|
+
await materializeBatchEvents(batch, chainStates, config.ecosystem.name);
|
|
223
224
|
await preloadBatchOrThrow(batch, loadManager, persistence, config, indexerState, chains);
|
|
224
225
|
}
|
|
225
226
|
let elapsedTimeAfterLoaders = Performance.secondsSince(timeRef);
|
|
@@ -264,7 +265,7 @@ export {
|
|
|
264
265
|
preloadBatchOrThrow,
|
|
265
266
|
runBatchHandlersOrThrow,
|
|
266
267
|
registerProcessEventBatchMetrics,
|
|
267
|
-
|
|
268
|
+
materializeBatchEvents,
|
|
268
269
|
processEventBatch,
|
|
269
270
|
}
|
|
270
271
|
/* Utils Not a pure module */
|