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.
Files changed (93) hide show
  1. package/index.d.ts +23 -5
  2. package/package.json +6 -6
  3. package/src/Address.res +5 -2
  4. package/src/Address.res.mjs +3 -1
  5. package/src/Api.res +1 -1
  6. package/src/Api.res.mjs +1 -1
  7. package/src/ChainFetching.res +34 -34
  8. package/src/ChainFetching.res.mjs +29 -29
  9. package/src/ChainState.res +328 -165
  10. package/src/ChainState.res.mjs +205 -100
  11. package/src/ChainState.resi +16 -7
  12. package/src/Config.res +55 -27
  13. package/src/Config.res.mjs +46 -7
  14. package/src/ContractRegisterContext.res +2 -12
  15. package/src/ContractRegisterContext.res.mjs +3 -5
  16. package/src/Core.res +7 -0
  17. package/src/CrossChainState.res +54 -79
  18. package/src/CrossChainState.res.mjs +45 -60
  19. package/src/CrossChainState.resi +1 -1
  20. package/src/Ecosystem.res +3 -3
  21. package/src/Ecosystem.res.mjs +3 -3
  22. package/src/Envio.res +14 -9
  23. package/src/EventConfigBuilder.res +105 -56
  24. package/src/EventConfigBuilder.res.mjs +69 -33
  25. package/src/EventProcessing.res +19 -15
  26. package/src/EventProcessing.res.mjs +13 -12
  27. package/src/FetchState.res +383 -182
  28. package/src/FetchState.res.mjs +260 -264
  29. package/src/HandlerLoader.res +7 -112
  30. package/src/HandlerLoader.res.mjs +1 -87
  31. package/src/HandlerRegister.res +209 -6
  32. package/src/HandlerRegister.res.mjs +90 -5
  33. package/src/HandlerRegister.resi +13 -2
  34. package/src/IndexerState.res +6 -3
  35. package/src/IndexerState.res.mjs +3 -3
  36. package/src/IndexerState.resi +1 -1
  37. package/src/IndexingAddresses.res +10 -7
  38. package/src/IndexingAddresses.res.mjs +8 -7
  39. package/src/IndexingAddresses.resi +3 -1
  40. package/src/Internal.res +82 -36
  41. package/src/Internal.res.mjs +11 -1
  42. package/src/Main.res +22 -23
  43. package/src/Main.res.mjs +15 -17
  44. package/src/Metrics.res +43 -2
  45. package/src/Metrics.res.mjs +39 -3
  46. package/src/Prometheus.res +0 -35
  47. package/src/Prometheus.res.mjs +33 -68
  48. package/src/RawEvent.res +7 -2
  49. package/src/RawEvent.res.mjs +4 -4
  50. package/src/SimulateItems.res +26 -8
  51. package/src/SimulateItems.res.mjs +11 -14
  52. package/src/TestIndexer.res +1 -1
  53. package/src/TestIndexer.res.mjs +1 -1
  54. package/src/sources/BlockStore.res +46 -0
  55. package/src/sources/BlockStore.res.mjs +24 -0
  56. package/src/sources/EventRouter.res +19 -12
  57. package/src/sources/EventRouter.res.mjs +7 -5
  58. package/src/sources/Evm.res +54 -4
  59. package/src/sources/Evm.res.mjs +43 -4
  60. package/src/sources/EvmChain.res +14 -18
  61. package/src/sources/EvmChain.res.mjs +12 -13
  62. package/src/sources/FieldMask.res +39 -0
  63. package/src/sources/FieldMask.res.mjs +42 -0
  64. package/src/sources/Fuel.res +5 -2
  65. package/src/sources/Fuel.res.mjs +4 -3
  66. package/src/sources/HyperFuelSource.res +32 -40
  67. package/src/sources/HyperFuelSource.res.mjs +53 -45
  68. package/src/sources/HyperSync.res +35 -9
  69. package/src/sources/HyperSync.res.mjs +52 -35
  70. package/src/sources/HyperSync.resi +11 -3
  71. package/src/sources/HyperSyncClient.res +15 -4
  72. package/src/sources/HyperSyncHeightStream.res +1 -8
  73. package/src/sources/HyperSyncHeightStream.res.mjs +0 -2
  74. package/src/sources/HyperSyncSource.res +39 -58
  75. package/src/sources/HyperSyncSource.res.mjs +44 -44
  76. package/src/sources/RpcSource.res +114 -92
  77. package/src/sources/RpcSource.res.mjs +77 -46
  78. package/src/sources/RpcWebSocketHeightStream.res +0 -5
  79. package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -2
  80. package/src/sources/SimulateSource.res +6 -3
  81. package/src/sources/SimulateSource.res.mjs +13 -5
  82. package/src/sources/Source.res +25 -5
  83. package/src/sources/SourceManager.res +66 -3
  84. package/src/sources/SourceManager.res.mjs +55 -7
  85. package/src/sources/SourceManager.resi +10 -0
  86. package/src/sources/Svm.res +15 -10
  87. package/src/sources/Svm.res.mjs +24 -7
  88. package/src/sources/SvmHyperSyncClient.res +5 -6
  89. package/src/sources/SvmHyperSyncSource.res +84 -41
  90. package/src/sources/SvmHyperSyncSource.res.mjs +90 -43
  91. package/src/sources/TransactionStore.res +6 -107
  92. package/src/sources/TransactionStore.res.mjs +5 -86
  93. package/svm.schema.json +19 -0
@@ -4,6 +4,7 @@ import * as Utils from "./Utils.res.mjs";
4
4
  import * as ChainState from "./ChainState.res.mjs";
5
5
  import * as PromClient from "prom-client";
6
6
  import * as IndexerState from "./IndexerState.res.mjs";
7
+ import * as SourceManager from "./sources/SourceManager.res.mjs";
7
8
  import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
8
9
 
9
10
  let indexingAddressesName = "envio_indexing_addresses";
@@ -21,19 +22,54 @@ function renderGauge(name, help, chains, value) {
21
22
  return out.contents;
22
23
  }
23
24
 
25
+ let sourceRequestTotalName = "envio_source_request_total";
26
+
27
+ let sourceRequestTotalHelp = "The number of requests made to data sources.";
28
+
29
+ let sourceRequestSecondsTotalName = "envio_source_request_seconds_total";
30
+
31
+ let sourceRequestSecondsTotalHelp = "Cumulative time spent on data source requests.";
32
+
33
+ function renderSourceRequests(samples) {
34
+ if (Utils.$$Array.isEmpty(samples)) {
35
+ return "";
36
+ }
37
+ let countOut = {
38
+ contents: `\n# HELP ` + sourceRequestTotalName + ` ` + sourceRequestTotalHelp + `\n# TYPE ` + sourceRequestTotalName + ` counter`
39
+ };
40
+ let secondsOut = {
41
+ contents: `\n# HELP ` + sourceRequestSecondsTotalName + ` ` + sourceRequestSecondsTotalHelp + `\n# TYPE ` + sourceRequestSecondsTotalName + ` counter`
42
+ };
43
+ samples.forEach(sample => {
44
+ let labels = `{source="` + sample.sourceName + `",chainId="` + sample.chainId.toString() + `",method="` + sample.method + `"}`;
45
+ countOut.contents = countOut.contents + (`\n` + sourceRequestTotalName + labels + ` ` + sample.count.toString());
46
+ if (sample.seconds !== 0) {
47
+ secondsOut.contents = secondsOut.contents + (`\n` + sourceRequestSecondsTotalName + labels + ` ` + sample.seconds.toString());
48
+ return;
49
+ }
50
+ });
51
+ return countOut.contents + secondsOut.contents;
52
+ }
53
+
24
54
  async function collect(state) {
25
55
  let base = await PromClient.register.metrics();
26
- if (state !== undefined) {
27
- return base + renderGauge(indexingAddressesName, indexingAddressesHelp, IndexerState.chainStates(Primitive_option.valFromOption(state)), cs => ChainState.toChainData(cs).numAddresses) + `\n`;
28
- } else {
56
+ if (state === undefined) {
29
57
  return base;
30
58
  }
59
+ let chainStates = IndexerState.chainStates(Primitive_option.valFromOption(state));
60
+ let sourceRequestSamples = Object.values(chainStates).flatMap(cs => SourceManager.getRequestStatSamples(ChainState.sourceManager(cs)));
61
+ return base + renderGauge(indexingAddressesName, indexingAddressesHelp, chainStates, cs => ChainState.toChainData(cs).numAddresses) + renderSourceRequests(sourceRequestSamples) + `\n`;
31
62
  }
32
63
 
33
64
  export {
34
65
  indexingAddressesName,
35
66
  indexingAddressesHelp,
36
67
  renderGauge,
68
+ sourceRequestTotalName,
69
+ sourceRequestTotalHelp,
70
+ sourceRequestSecondsTotalName,
71
+ sourceRequestSecondsTotalHelp,
72
+ renderSourceRequests,
37
73
  collect,
38
74
  }
39
75
  /* Utils Not a pure module */
@@ -438,41 +438,6 @@ let sourceLabelsSchema = S.schema(s =>
438
438
  }
439
439
  )
440
440
 
441
- let sourceRequestLabelsSchema = S.schema(s =>
442
- {
443
- "source": s.matches(S.string),
444
- "chainId": s.matches(S.string->S.coerce(S.int)),
445
- "method": s.matches(S.string),
446
- }
447
- )
448
-
449
- module SourceRequestCount = {
450
- let counter = SafeCounter.makeOrThrow(
451
- ~name="envio_source_request_total",
452
- ~help="The number of requests made to data sources.",
453
- ~labelSchema=sourceRequestLabelsSchema,
454
- )
455
-
456
- let sumTimeCounter = SafeCounter.makeOrThrow(
457
- ~name="envio_source_request_seconds_total",
458
- ~help="Cumulative time spent on data source requests.",
459
- ~labelSchema=sourceRequestLabelsSchema,
460
- )
461
-
462
- let increment = (~sourceName, ~chainId, ~method) => {
463
- counter->SafeCounter.increment(
464
- ~labels={"source": sourceName, "chainId": chainId, "method": method},
465
- )
466
- }
467
-
468
- let addSeconds = (~sourceName, ~chainId, ~method, ~seconds) => {
469
- sumTimeCounter->SafeCounter.handleFloat(
470
- ~labels={"source": sourceName, "chainId": chainId, "method": method},
471
- ~value=seconds,
472
- )
473
- }
474
- }
475
-
476
441
  module SourceHeight = {
477
442
  let gauge = SafeGauge.makeOrThrow(
478
443
  ~name="envio_source_known_height",
@@ -481,39 +481,6 @@ let sourceLabelsSchema = S$RescriptSchema.schema(s => ({
481
481
  chainId: s.m(S$RescriptSchema.coerce(S$RescriptSchema.string, S$RescriptSchema.int))
482
482
  }));
483
483
 
484
- let sourceRequestLabelsSchema = S$RescriptSchema.schema(s => ({
485
- source: s.m(S$RescriptSchema.string),
486
- chainId: s.m(S$RescriptSchema.coerce(S$RescriptSchema.string, S$RescriptSchema.int)),
487
- method: s.m(S$RescriptSchema.string)
488
- }));
489
-
490
- let counter$3 = makeOrThrow("envio_source_request_total", "The number of requests made to data sources.", sourceRequestLabelsSchema);
491
-
492
- let sumTimeCounter$1 = makeOrThrow("envio_source_request_seconds_total", "Cumulative time spent on data source requests.", sourceRequestLabelsSchema);
493
-
494
- function increment$4(sourceName, chainId, method) {
495
- increment(counter$3, {
496
- source: sourceName,
497
- chainId: chainId,
498
- method: method
499
- });
500
- }
501
-
502
- function addSeconds(sourceName, chainId, method, seconds) {
503
- handleFloat(sumTimeCounter$1, {
504
- source: sourceName,
505
- chainId: chainId,
506
- method: method
507
- }, seconds);
508
- }
509
-
510
- let SourceRequestCount = {
511
- counter: counter$3,
512
- sumTimeCounter: sumTimeCounter$1,
513
- increment: increment$4,
514
- addSeconds: addSeconds
515
- };
516
-
517
484
  let gauge$10 = makeOrThrow$1("envio_source_known_height", "The latest known block number reported by the source. This value may lag behind the actual chain height, as it is updated only when queried.", sourceLabelsSchema);
518
485
 
519
486
  function set$10(sourceName, chainId, blockNumber) {
@@ -528,15 +495,15 @@ let SourceHeight = {
528
495
  set: set$10
529
496
  };
530
497
 
531
- let counter$4 = makeOrThrow("envio_reorg_detected_total", "Total number of reorgs detected", chainIdLabelsSchema);
498
+ let counter$3 = makeOrThrow("envio_reorg_detected_total", "Total number of reorgs detected", chainIdLabelsSchema);
532
499
 
533
- function increment$5(chain) {
534
- increment(counter$4, chain);
500
+ function increment$4(chain) {
501
+ increment(counter$3, chain);
535
502
  }
536
503
 
537
504
  let ReorgCount = {
538
- counter: counter$4,
539
- increment: increment$5
505
+ counter: counter$3,
506
+ increment: increment$4
540
507
  };
541
508
 
542
509
  let gauge$11 = makeOrThrow$1("envio_reorg_detected_block", "The block number where reorg was detected the last time. This doesn't mean that the block was reorged, this is simply where we found block hash to be different.", chainIdLabelsSchema);
@@ -583,7 +550,7 @@ let timeCounter$3 = PromClient.Counter.makeCounter({
583
550
  help: "Rollback on reorg total time."
584
551
  });
585
552
 
586
- let counter$5 = PromClient.Counter.makeCounter({
553
+ let counter$4 = PromClient.Counter.makeCounter({
587
554
  name: "envio_rollback_total",
588
555
  help: "Number of successful rollbacks on reorg"
589
556
  });
@@ -593,35 +560,35 @@ let eventsCounter = PromClient.Counter.makeCounter({
593
560
  help: "Number of events rollbacked on reorg"
594
561
  });
595
562
 
596
- function increment$6(timeSeconds, rollbackedProcessedEvents) {
563
+ function increment$5(timeSeconds, rollbackedProcessedEvents) {
597
564
  timeCounter$3.inc(timeSeconds);
598
- counter$5.inc();
565
+ counter$4.inc();
599
566
  eventsCounter.inc(Math.trunc(rollbackedProcessedEvents));
600
567
  }
601
568
 
602
569
  let RollbackSuccess = {
603
570
  timeCounter: timeCounter$3,
604
- counter: counter$5,
571
+ counter: counter$4,
605
572
  eventsCounter: eventsCounter,
606
- increment: increment$6
573
+ increment: increment$5
607
574
  };
608
575
 
609
576
  let entityNameLabelsSchema = S$RescriptSchema.object(s => s.f("entity", S$RescriptSchema.string));
610
577
 
611
578
  let timeCounter$4 = makeOrThrow("envio_rollback_history_prune_seconds", "The total time spent pruning entity history which is not in the reorg threshold.", entityNameLabelsSchema);
612
579
 
613
- let counter$6 = makeOrThrow("envio_rollback_history_prune_total", "Number of successful entity history prunes", entityNameLabelsSchema);
580
+ let counter$5 = makeOrThrow("envio_rollback_history_prune_total", "Number of successful entity history prunes", entityNameLabelsSchema);
614
581
 
615
- function increment$7(timeSeconds, entityName) {
582
+ function increment$6(timeSeconds, entityName) {
616
583
  handleFloat(timeCounter$4, entityName, timeSeconds);
617
- increment(counter$6, entityName);
584
+ increment(counter$5, entityName);
618
585
  }
619
586
 
620
587
  let RollbackHistoryPrune = {
621
588
  entityNameLabelsSchema: entityNameLabelsSchema,
622
589
  timeCounter: timeCounter$4,
623
- counter: counter$6,
624
- increment: increment$7
590
+ counter: counter$5,
591
+ increment: increment$6
625
592
  };
626
593
 
627
594
  let gauge$14 = makeOrThrow$1("envio_rollback_target_block", "The block number reorg was rollbacked to the last time.", chainIdLabelsSchema);
@@ -686,7 +653,7 @@ let effectLabelsSchema = S$RescriptSchema.object(s => s.f("effect", S$RescriptSc
686
653
 
687
654
  let timeCounter$5 = makeOrThrow("envio_effect_call_seconds", "Processing time taken to call the Effect function.", effectLabelsSchema);
688
655
 
689
- let sumTimeCounter$2 = makeOrThrow("envio_effect_call_seconds_total", "Cumulative time spent calling the Effect function during the indexing process.", effectLabelsSchema);
656
+ let sumTimeCounter$1 = makeOrThrow("envio_effect_call_seconds_total", "Cumulative time spent calling the Effect function during the indexing process.", effectLabelsSchema);
690
657
 
691
658
  let totalCallsCount = makeOrThrow("envio_effect_call_total", "Cumulative number of resolved Effect function calls during the indexing process.", effectLabelsSchema);
692
659
 
@@ -694,7 +661,7 @@ let activeCallsCount = makeOrThrow$1("envio_effect_active_calls", "The number of
694
661
 
695
662
  let EffectCalls = {
696
663
  timeCounter: timeCounter$5,
697
- sumTimeCounter: sumTimeCounter$2,
664
+ sumTimeCounter: sumTimeCounter$1,
698
665
  totalCallsCount: totalCallsCount,
699
666
  activeCallsCount: activeCallsCount
700
667
  };
@@ -710,15 +677,15 @@ let EffectCacheCount = {
710
677
  set: set$19
711
678
  };
712
679
 
713
- let counter$7 = makeOrThrow("envio_effect_cache_invalidations", "The number of effect cache invalidations.", effectLabelsSchema);
680
+ let counter$6 = makeOrThrow("envio_effect_cache_invalidations", "The number of effect cache invalidations.", effectLabelsSchema);
714
681
 
715
- function increment$8(effectName) {
716
- increment(counter$7, effectName);
682
+ function increment$7(effectName) {
683
+ increment(counter$6, effectName);
717
684
  }
718
685
 
719
686
  let EffectCacheInvalidationsCount = {
720
- counter: counter$7,
721
- increment: increment$8
687
+ counter: counter$6,
688
+ increment: increment$7
722
689
  };
723
690
 
724
691
  let gauge$20 = makeOrThrow$1("envio_effect_queue", "The number of effect calls waiting in the rate limit queue.", effectLabelsSchema);
@@ -742,9 +709,9 @@ let loadLabelsSchema = S$RescriptSchema.schema(s => ({
742
709
 
743
710
  let timeCounter$7 = makeOrThrow("envio_storage_load_seconds", "Processing time taken to load data from storage.", loadLabelsSchema);
744
711
 
745
- let sumTimeCounter$3 = makeOrThrow("envio_storage_load_seconds_total", "Cumulative time spent loading data from storage during the indexing process.", loadLabelsSchema);
712
+ let sumTimeCounter$2 = makeOrThrow("envio_storage_load_seconds_total", "Cumulative time spent loading data from storage during the indexing process.", loadLabelsSchema);
746
713
 
747
- let counter$8 = makeOrThrow("envio_storage_load_total", "Cumulative number of successful storage load operations during the indexing process.", loadLabelsSchema);
714
+ let counter$7 = makeOrThrow("envio_storage_load_total", "Cumulative number of successful storage load operations during the indexing process.", loadLabelsSchema);
748
715
 
749
716
  let whereSizeCounter = makeOrThrow("envio_storage_load_where_size", "Cumulative number of filter conditions ('where' items) used in storage load operations during the indexing process.", loadLabelsSchema);
750
717
 
@@ -782,8 +749,8 @@ function endOperation$1(timerRef, storage, operation, whereSize, size) {
782
749
  handleFloat(timeCounter$7, labels, Performance.secondsSince(operationRef.timerRef));
783
750
  Utils.Dict.deleteInPlace(operations$1, key);
784
751
  }
785
- handleFloat(sumTimeCounter$3, labels, Performance.secondsSince(timerRef));
786
- increment(counter$8, labels);
752
+ handleFloat(sumTimeCounter$2, labels, Performance.secondsSince(timerRef));
753
+ increment(counter$7, labels);
787
754
  handleInt(whereSizeCounter, labels, whereSize);
788
755
  handleInt(sizeCounter$1, labels, size);
789
756
  }
@@ -791,8 +758,8 @@ function endOperation$1(timerRef, storage, operation, whereSize, size) {
791
758
  let StorageLoad = {
792
759
  loadLabelsSchema: loadLabelsSchema,
793
760
  timeCounter: timeCounter$7,
794
- sumTimeCounter: sumTimeCounter$3,
795
- counter: counter$8,
761
+ sumTimeCounter: sumTimeCounter$2,
762
+ counter: counter$7,
796
763
  whereSizeCounter: whereSizeCounter,
797
764
  sizeCounter: sizeCounter$1,
798
765
  operations: operations$1,
@@ -805,18 +772,18 @@ let storageLabelsSchema = S$RescriptSchema.object(s => s.f("storage", S$Rescript
805
772
 
806
773
  let timeCounter$8 = makeOrThrow("envio_storage_write_seconds", "Cumulative time spent writing batch data to storage.", storageLabelsSchema);
807
774
 
808
- let counter$9 = makeOrThrow("envio_storage_write_total", "Cumulative number of successful storage write operations during the indexing process.", storageLabelsSchema);
775
+ let counter$8 = makeOrThrow("envio_storage_write_total", "Cumulative number of successful storage write operations during the indexing process.", storageLabelsSchema);
809
776
 
810
- function increment$9(storage, timeSeconds) {
777
+ function increment$8(storage, timeSeconds) {
811
778
  handleFloat(timeCounter$8, storage, timeSeconds);
812
- increment(counter$9, storage);
779
+ increment(counter$8, storage);
813
780
  }
814
781
 
815
782
  let StorageWrite = {
816
783
  storageLabelsSchema: storageLabelsSchema,
817
784
  timeCounter: timeCounter$8,
818
- counter: counter$9,
819
- increment: increment$9
785
+ counter: counter$8,
786
+ increment: increment$8
820
787
  };
821
788
 
822
789
  export {
@@ -845,8 +812,6 @@ export {
845
812
  IndexingBufferBlockNumber,
846
813
  IndexingEndBlock,
847
814
  sourceLabelsSchema,
848
- sourceRequestLabelsSchema,
849
- SourceRequestCount,
850
815
  SourceHeight,
851
816
  ReorgCount,
852
817
  ReorgDetectionBlockNumber,
package/src/RawEvent.res CHANGED
@@ -19,16 +19,21 @@ let convertFieldsToJson = (fields: option<dict<unknown>>) => {
19
19
 
20
20
  // Block and transaction are passed already extracted from the ecosystem's
21
21
  // concrete payload (EVM or Fuel) — `RawEvent` stays payload-shape-agnostic and
22
- // only needs them as opaque field bags to serialise.
22
+ // only needs them as opaque field bags to serialise. The dedicated
23
+ // `block_hash`/`block_timestamp` column values are extracted from the payload
24
+ // block by the ecosystem caller (the field names differ per ecosystem).
23
25
  let make = (
24
26
  eventItem: Internal.eventItem,
25
27
  ~block,
26
28
  ~transaction,
27
29
  ~params: Internal.eventParams,
28
30
  ~srcAddress: Address.t,
31
+ ~blockHash: string,
32
+ ~blockTimestamp: int,
29
33
  ~cleanUpRawEventFieldsInPlace: JSON.t => unit,
30
34
  ): Internal.rawEvent => {
31
- let {eventConfig, chain, blockNumber, blockHash, timestamp: blockTimestamp, logIndex} = eventItem
35
+ let {onEventRegistration, chain, blockNumber, logIndex} = eventItem
36
+ let eventConfig = onEventRegistration.eventConfig
32
37
  let chainId = chain->ChainMap.Chain.toChainId
33
38
  let eventId = EventUtils.packEventIndex(~logIndex, ~blockNumber)
34
39
  let blockFields =
@@ -18,10 +18,10 @@ function convertFieldsToJson(fields) {
18
18
  }
19
19
  }
20
20
 
21
- function make(eventItem, block, transaction, params, srcAddress, cleanUpRawEventFieldsInPlace) {
21
+ function make(eventItem, block, transaction, params, srcAddress, blockHash, blockTimestamp, cleanUpRawEventFieldsInPlace) {
22
22
  let logIndex = eventItem.logIndex;
23
23
  let blockNumber = eventItem.blockNumber;
24
- let eventConfig = eventItem.eventConfig;
24
+ let eventConfig = eventItem.onEventRegistration.eventConfig;
25
25
  let eventId = EventUtils.packEventIndex(blockNumber, logIndex);
26
26
  let blockFields = convertFieldsToJson(block);
27
27
  let transactionFields = convertFieldsToJson(transaction);
@@ -36,8 +36,8 @@ function make(eventItem, block, transaction, params, srcAddress, cleanUpRawEvent
36
36
  block_number: blockNumber,
37
37
  log_index: logIndex,
38
38
  src_address: srcAddress,
39
- block_hash: eventItem.blockHash,
40
- block_timestamp: eventItem.timestamp,
39
+ block_hash: blockHash,
40
+ block_timestamp: blockTimestamp,
41
41
  block_fields: blockFields,
42
42
  transaction_fields: transactionFields,
43
43
  params: params$2
@@ -216,11 +216,20 @@ let deriveSrcAddress = (
216
216
  ~providedSrcAddress: option<Address.t>,
217
217
  ~eventConfig: Internal.eventConfig,
218
218
  ~chainConfig: Config.chain,
219
+ ~config: Config.t,
219
220
  ): Address.t => {
220
221
  switch providedSrcAddress {
221
- | Some(addr) => addr
222
+ // Canonicalize to the configured casing; the fallback addresses below already
223
+ // come from the parsed config and need no normalization. Relaxed (not
224
+ // Config.normalizeUserAddress) so test placeholders like "0xfoo" are allowed.
225
+ | Some(addr) => config->Config.normalizeSimulateAddress(addr)
222
226
  | None =>
223
- if eventConfig.isWildcard {
227
+ if (
228
+ HandlerRegister.isWildcard(
229
+ ~contractName=eventConfig.contractName,
230
+ ~eventName=eventConfig.name,
231
+ )
232
+ ) {
224
233
  dummySrcAddress
225
234
  } else {
226
235
  switch firstContractAddress(~chainConfig, ~contractName=eventConfig.contractName) {
@@ -287,6 +296,7 @@ let parse = (~simulateItems: array<JSON.t>, ~config: Config.t, ~chainConfig: Con
287
296
  ~providedSrcAddress=item.srcAddress,
288
297
  ~eventConfig,
289
298
  ~chainConfig,
299
+ ~config,
290
300
  )
291
301
 
292
302
  let rawItem = rawJson->(Utils.magic: JSON.t => {..})
@@ -294,15 +304,15 @@ let parse = (~simulateItems: array<JSON.t>, ~config: Config.t, ~chainConfig: Con
294
304
  rawItem["block"]->(Utils.magic: 'a => Nullable.t<JSON.t>)->Nullable.toOption
295
305
  let transactionJson: option<JSON.t> =
296
306
  rawItem["transaction"]->(Utils.magic: 'a => Nullable.t<JSON.t>)->Nullable.toOption
297
- let (block, blockNumber, timestamp, blockHash) = switch config.ecosystem.name {
307
+ let (block, blockNumber) = switch config.ecosystem.name {
298
308
  | Fuel =>
299
309
  let block = parseFuelSimulateBlock(~defaultBlockNumber=currentBlock.contents, ~blockJson)
300
310
  let blockFields = block->(Utils.magic: Internal.eventBlock => fuelSimulateBlock)
301
- (block, blockFields.height, blockFields.time, blockFields.id)
311
+ (block, blockFields.height)
302
312
  | Evm =>
303
313
  let block = parseEvmSimulateBlock(~defaultBlockNumber=currentBlock.contents, ~blockJson)
304
314
  let blockFields = block->(Utils.magic: Internal.eventBlock => evmSimulateBlock)
305
- (block, blockFields.number, blockFields.timestamp, blockFields.hash)
315
+ (block, blockFields.number)
306
316
  | Svm => JsError.throwWithMessage("simulate is not supported for SVM ecosystem")
307
317
  }
308
318
  let transaction = switch config.ecosystem.name {
@@ -326,14 +336,22 @@ let parse = (~simulateItems: array<JSON.t>, ~config: Config.t, ~chainConfig: Con
326
336
  | None => seenCoordinates->Dict.set(coordinate, itemIndex)
327
337
  }
328
338
 
339
+ // Build a real registration the same way `HandlerRegister.buildOnEventRegistrations`
340
+ // does at startup (not a stub), so the address filter and `where`
341
+ // behave identically to real indexing — the dead-input tracker relies
342
+ // on `clientAddressFilter` actually gating unrouted items.
343
+ let onEventRegistration = HandlerRegister.buildOnEventRegistration(
344
+ ~config,
345
+ ~chainId,
346
+ ~eventConfig,
347
+ )
348
+
329
349
  items
330
350
  ->Array.push(
331
351
  Internal.Event({
332
- eventConfig,
333
- timestamp,
352
+ onEventRegistration,
334
353
  chain,
335
354
  blockNumber,
336
- blockHash,
337
355
  logIndex,
338
356
  // Simulate keeps the transaction inline on the payload, so the store
339
357
  // key is unused.
@@ -1,10 +1,12 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
+ import * as Config from "./Config.res.mjs";
3
4
  import * as Address from "./Address.res.mjs";
4
5
  import * as ChainMap from "./ChainMap.res.mjs";
5
6
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
6
7
  import * as SimulateSource from "./sources/SimulateSource.res.mjs";
7
8
  import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
9
+ import * as HandlerRegister from "./HandlerRegister.res.mjs";
8
10
  import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
9
11
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
10
12
 
@@ -150,11 +152,11 @@ function firstContractAddress(chainConfig, contractName) {
150
152
  return found.contents;
151
153
  }
152
154
 
153
- function deriveSrcAddress(providedSrcAddress, eventConfig, chainConfig) {
155
+ function deriveSrcAddress(providedSrcAddress, eventConfig, chainConfig, config) {
154
156
  if (providedSrcAddress !== undefined) {
155
- return Primitive_option.valFromOption(providedSrcAddress);
157
+ return Config.normalizeSimulateAddress(config, Primitive_option.valFromOption(providedSrcAddress));
156
158
  }
157
- if (eventConfig.isWildcard) {
159
+ if (HandlerRegister.isWildcard(eventConfig.contractName, eventConfig.name)) {
158
160
  return dummySrcAddress;
159
161
  }
160
162
  let addr = firstContractAddress(chainConfig, eventConfig.contractName);
@@ -203,7 +205,7 @@ function parse(simulateItems, config, chainConfig) {
203
205
  currentLogIndex.contents = li$1 + 1 | 0;
204
206
  logIndex = li$1;
205
207
  }
206
- let srcAddress = deriveSrcAddress(rawJson.srcAddress, eventConfig, chainConfig);
208
+ let srcAddress = deriveSrcAddress(rawJson.srcAddress, eventConfig, chainConfig, config);
207
209
  let blockJson = rawJson.block;
208
210
  let blockJson$1 = (blockJson == null) ? undefined : Primitive_option.some(blockJson);
209
211
  let transactionJson = rawJson.transaction;
@@ -215,18 +217,14 @@ function parse(simulateItems, config, chainConfig) {
215
217
  let block = parseEvmSimulateBlock(currentBlock.contents, blockJson$1);
216
218
  match$3 = [
217
219
  block,
218
- block.number,
219
- block.timestamp,
220
- block.hash
220
+ block.number
221
221
  ];
222
222
  break;
223
223
  case "fuel" :
224
224
  let block$1 = parseFuelSimulateBlock(currentBlock.contents, blockJson$1);
225
225
  match$3 = [
226
226
  block$1,
227
- block$1.height,
228
- block$1.time,
229
- block$1.id
227
+ block$1.height
230
228
  ];
231
229
  break;
232
230
  case "svm" :
@@ -255,13 +253,12 @@ function parse(simulateItems, config, chainConfig) {
255
253
  } else {
256
254
  seenCoordinates[coordinate] = itemIndex;
257
255
  }
256
+ let onEventRegistration = HandlerRegister.buildOnEventRegistration(config, chainId, eventConfig, undefined);
258
257
  items.push({
259
258
  kind: 0,
260
- eventConfig: eventConfig,
261
- timestamp: match$3[2],
259
+ onEventRegistration: onEventRegistration,
262
260
  chain: chain,
263
261
  blockNumber: blockNumber,
264
- blockHash: match$3[3],
265
262
  logIndex: logIndex,
266
263
  transactionIndex: 0,
267
264
  payload: {
@@ -272,7 +269,7 @@ function parse(simulateItems, config, chainConfig) {
272
269
  srcAddress: srcAddress,
273
270
  logIndex: logIndex,
274
271
  transaction: Primitive_option.some(transaction),
275
- block: match$3[0]
272
+ block: Primitive_option.some(match$3[0])
276
273
  }
277
274
  });
278
275
  });
@@ -850,7 +850,7 @@ let initTestWorker = () => {
850
850
  // Create proxy storage that communicates with main thread
851
851
  let proxy = TestIndexerProxyStorage.make(~parentPort, ~initialState)
852
852
  let storage = TestIndexerProxyStorage.makeStorage(proxy)
853
- let config = Config.loadWithoutRegistrations()
853
+ let config = Config.load()
854
854
  let persistence = Persistence.make(
855
855
  ~userEntities=config.userEntities,
856
856
  ~allEnums=config.allEnums,
@@ -605,7 +605,7 @@ function initTestWorker() {
605
605
  };
606
606
  let proxy = TestIndexerProxyStorage.make(parentPort, workerData.initialState);
607
607
  let storage = TestIndexerProxyStorage.makeStorage(proxy);
608
- let config = Config.loadWithoutRegistrations();
608
+ let config = Config.load();
609
609
  let persistence = Persistence.make(config.userEntities, config.allEnums, storage);
610
610
  if (Env.userLogLevel !== undefined) {
611
611
 
@@ -0,0 +1,46 @@
1
+ // Binding to the Rust `BlockStore` napi class. Blocks are kept in Rust as raw
2
+ // structs (their large fields never enter JS until read) keyed by block number.
3
+ // One store lives per chain on `ChainState`; each fetch response contributes a
4
+ // page that is merged in. At batch preparation the selected fields are
5
+ // materialised in bulk, off the JS thread, in columnar form and zipped into
6
+ // plain JS objects on the main thread.
7
+ type t
8
+
9
+ @send external newEvm: (Core.blockStoreCtor, ~shouldChecksum: bool) => t = "newEvm"
10
+ @send external newSvm: Core.blockStoreCtor => t = "newSvm"
11
+ @send external newFuel: Core.blockStoreCtor => t = "newFuel"
12
+
13
+ // The store's ecosystem is fixed here, from the chain's config. EVM carries the
14
+ // chain's address-checksumming setting; SVM/Fuel need no extra data.
15
+ let make = (~ecosystem: Ecosystem.name, ~shouldChecksum: bool): t => {
16
+ let ctor = Core.getAddon().blockStore
17
+ switch ecosystem {
18
+ | Evm => ctor->newEvm(~shouldChecksum)
19
+ | Svm => ctor->newSvm
20
+ | Fuel => ctor->newFuel
21
+ }
22
+ }
23
+
24
+ // One event's selected block fields → store selection bitmask, built from the
25
+ // ecosystem's ordered field-name array (the bit index is the field code shared
26
+ // with the Rust store, `EvmBlockField`).
27
+ let makeMaskFn = FieldMask.makeMaskFn
28
+
29
+ // Drain another store (a fetch-response page) into this one.
30
+ @send external merge: (t, t) => unit = "merge"
31
+
32
+ // Bulk-materialise blocks off the JS thread, one row per `blockNumbers[i]` key,
33
+ // decoding only the fields set in that row's own `masks[i]`. Result is aligned
34
+ // with the input.
35
+ @send
36
+ external materialize: (
37
+ t,
38
+ ~blockNumbers: array<int>,
39
+ ~masks: array<float>,
40
+ ) => promise<array<Internal.eventBlock>> = "materialize"
41
+
42
+ // Drop blocks at or below the given block (already processed).
43
+ @send external prune: (t, int) => unit = "prune"
44
+
45
+ // Drop blocks above the given block (rolled back).
46
+ @send external rollback: (t, int) => unit = "rollback"
@@ -0,0 +1,24 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Core from "../Core.res.mjs";
4
+ import * as FieldMask from "./FieldMask.res.mjs";
5
+
6
+ function make(ecosystem, shouldChecksum) {
7
+ let ctor = Core.getAddon().BlockStore;
8
+ switch (ecosystem) {
9
+ case "evm" :
10
+ return ctor.newEvm(shouldChecksum);
11
+ case "fuel" :
12
+ return ctor.newFuel();
13
+ case "svm" :
14
+ return ctor.newSvm();
15
+ }
16
+ }
17
+
18
+ let makeMaskFn = FieldMask.makeMaskFn;
19
+
20
+ export {
21
+ make,
22
+ makeMaskFn,
23
+ }
24
+ /* Core Not a pure module */