envio 3.3.0-alpha.3 → 3.3.0-alpha.5

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 (53) hide show
  1. package/evm.schema.json +10 -0
  2. package/package.json +7 -7
  3. package/src/Batch.res.mjs +1 -1
  4. package/src/Bin.res +3 -0
  5. package/src/Bin.res.mjs +4 -0
  6. package/src/ChainFetching.res +1 -3
  7. package/src/ChainFetching.res.mjs +3 -3
  8. package/src/ChainState.res +44 -19
  9. package/src/ChainState.res.mjs +25 -23
  10. package/src/ChainState.resi +3 -3
  11. package/src/Config.res +3 -0
  12. package/src/Config.res.mjs +3 -1
  13. package/src/Core.res +0 -3
  14. package/src/Ecosystem.res +0 -4
  15. package/src/EventConfigBuilder.res +3 -0
  16. package/src/EventConfigBuilder.res.mjs +7 -1
  17. package/src/FetchState.res +73 -160
  18. package/src/FetchState.res.mjs +120 -222
  19. package/src/IndexingAddresses.res +105 -0
  20. package/src/IndexingAddresses.res.mjs +100 -0
  21. package/src/IndexingAddresses.resi +32 -0
  22. package/src/Internal.res +5 -0
  23. package/src/Main.res +21 -24
  24. package/src/Main.res.mjs +21 -20
  25. package/src/Metrics.res +33 -0
  26. package/src/Metrics.res.mjs +39 -0
  27. package/src/Prometheus.res +2 -20
  28. package/src/Prometheus.res.mjs +83 -95
  29. package/src/SimulateItems.res +4 -0
  30. package/src/TestIndexer.res +43 -17
  31. package/src/TestIndexer.res.mjs +16 -9
  32. package/src/bindings/Viem.res +0 -41
  33. package/src/bindings/Viem.res.mjs +1 -43
  34. package/src/sources/Evm.res +17 -39
  35. package/src/sources/Evm.res.mjs +8 -40
  36. package/src/sources/EvmChain.res +3 -1
  37. package/src/sources/EvmChain.res.mjs +2 -1
  38. package/src/sources/EvmRpcClient.res +36 -5
  39. package/src/sources/EvmRpcClient.res.mjs +7 -4
  40. package/src/sources/Fuel.res +0 -2
  41. package/src/sources/Fuel.res.mjs +0 -1
  42. package/src/sources/HyperSyncClient.res +0 -35
  43. package/src/sources/HyperSyncClient.res.mjs +1 -8
  44. package/src/sources/Rpc.res +15 -47
  45. package/src/sources/Rpc.res.mjs +25 -56
  46. package/src/sources/RpcSource.res +30 -73
  47. package/src/sources/RpcSource.res.mjs +24 -73
  48. package/src/sources/SourceManager.res +1 -1
  49. package/src/sources/SourceManager.res.mjs +1 -1
  50. package/src/sources/Svm.res +10 -17
  51. package/src/sources/Svm.res.mjs +6 -18
  52. package/src/sources/TransactionStore.res +98 -76
  53. package/src/sources/TransactionStore.res.mjs +49 -35
@@ -389,39 +389,28 @@ let ProcessStartTimeSeconds = {
389
389
  set: set$3
390
390
  };
391
391
 
392
- let gauge$4 = makeOrThrow$1("envio_indexing_addresses", "The number of addresses indexed on chain. Includes both static and dynamic addresses.", chainIdLabelsSchema);
392
+ let gauge$4 = makeOrThrow$1("envio_indexing_concurrency", "The number of executing concurrent queries to the chain data-source.", chainIdLabelsSchema);
393
393
 
394
- function set$4(addressesCount, chainId) {
395
- handleInt$1(gauge$4, chainId, addressesCount);
394
+ function set$4(concurrency, chainId) {
395
+ handleInt$1(gauge$4, chainId, concurrency);
396
396
  }
397
397
 
398
- let IndexingAddresses = {
398
+ let IndexingConcurrency = {
399
399
  gauge: gauge$4,
400
400
  set: set$4
401
401
  };
402
402
 
403
- let gauge$5 = makeOrThrow$1("envio_indexing_concurrency", "The number of executing concurrent queries to the chain data-source.", chainIdLabelsSchema);
403
+ let gauge$5 = makeOrThrow$1("envio_indexing_partitions", "The number of partitions used to split fetching logic by addresses and block ranges.", chainIdLabelsSchema);
404
404
 
405
- function set$5(concurrency, chainId) {
406
- handleInt$1(gauge$5, chainId, concurrency);
405
+ function set$5(partitionsCount, chainId) {
406
+ handleInt$1(gauge$5, chainId, partitionsCount);
407
407
  }
408
408
 
409
- let IndexingConcurrency = {
409
+ let IndexingPartitions = {
410
410
  gauge: gauge$5,
411
411
  set: set$5
412
412
  };
413
413
 
414
- let gauge$6 = makeOrThrow$1("envio_indexing_partitions", "The number of partitions used to split fetching logic by addresses and block ranges.", chainIdLabelsSchema);
415
-
416
- function set$6(partitionsCount, chainId) {
417
- handleInt$1(gauge$6, chainId, partitionsCount);
418
- }
419
-
420
- let IndexingPartitions = {
421
- gauge: gauge$6,
422
- set: set$6
423
- };
424
-
425
414
  let counter = makeOrThrow("envio_indexing_idle_seconds", "The time the indexer source syncing has been idle. A high value may indicate the source sync is a bottleneck.", chainIdLabelsSchema);
426
415
 
427
416
  let IndexingIdleTime = {
@@ -440,51 +429,51 @@ let IndexingQueryTime = {
440
429
  counter: counter$2
441
430
  };
442
431
 
443
- let gauge$7 = makeOrThrow$1("envio_indexing_buffer_size", "The current number of items in the indexing buffer.", chainIdLabelsSchema);
432
+ let gauge$6 = makeOrThrow$1("envio_indexing_buffer_size", "The current number of items in the indexing buffer.", chainIdLabelsSchema);
444
433
 
445
- function set$7(bufferSize, chainId) {
446
- handleInt$1(gauge$7, chainId, bufferSize);
434
+ function set$6(bufferSize, chainId) {
435
+ handleInt$1(gauge$6, chainId, bufferSize);
447
436
  }
448
437
 
449
438
  let IndexingBufferSize = {
450
- gauge: gauge$7,
451
- set: set$7
439
+ gauge: gauge$6,
440
+ set: set$6
452
441
  };
453
442
 
454
- let gauge$8 = PromClient.Gauge.makeGauge({
443
+ let gauge$7 = PromClient.Gauge.makeGauge({
455
444
  name: "envio_indexing_target_buffer_size",
456
445
  help: "The indexer-wide target buffer size shared across all chains. The actual number of items in the queue may exceed this value, but the indexer always tries to keep the buffer filled up to this target."
457
446
  });
458
447
 
459
- function set$8(targetBufferSize) {
460
- gauge$8.set(targetBufferSize);
448
+ function set$7(targetBufferSize) {
449
+ gauge$7.set(targetBufferSize);
461
450
  }
462
451
 
463
452
  let IndexingTargetBufferSize = {
464
- gauge: gauge$8,
465
- set: set$8
453
+ gauge: gauge$7,
454
+ set: set$7
466
455
  };
467
456
 
468
- let gauge$9 = makeOrThrow$1("envio_indexing_buffer_block", "The highest block number that has been fully fetched by the indexer.", chainIdLabelsSchema);
457
+ let gauge$8 = makeOrThrow$1("envio_indexing_buffer_block", "The highest block number that has been fully fetched by the indexer.", chainIdLabelsSchema);
469
458
 
470
- function set$9(blockNumber, chainId) {
471
- handleInt$1(gauge$9, chainId, blockNumber);
459
+ function set$8(blockNumber, chainId) {
460
+ handleInt$1(gauge$8, chainId, blockNumber);
472
461
  }
473
462
 
474
463
  let IndexingBufferBlockNumber = {
475
- gauge: gauge$9,
476
- set: set$9
464
+ gauge: gauge$8,
465
+ set: set$8
477
466
  };
478
467
 
479
- let gauge$10 = makeOrThrow$1("envio_indexing_end_block", "The block number to stop indexing at. (inclusive)", chainIdLabelsSchema);
468
+ let gauge$9 = makeOrThrow$1("envio_indexing_end_block", "The block number to stop indexing at. (inclusive)", chainIdLabelsSchema);
480
469
 
481
- function set$10(endBlock, chainId) {
482
- handleInt$1(gauge$10, chainId, endBlock);
470
+ function set$9(endBlock, chainId) {
471
+ handleInt$1(gauge$9, chainId, endBlock);
483
472
  }
484
473
 
485
474
  let IndexingEndBlock = {
486
- gauge: gauge$10,
487
- set: set$10
475
+ gauge: gauge$9,
476
+ set: set$9
488
477
  };
489
478
 
490
479
  let sourceLabelsSchema = S$RescriptSchema.schema(s => ({
@@ -525,18 +514,18 @@ let SourceRequestCount = {
525
514
  addSeconds: addSeconds
526
515
  };
527
516
 
528
- let gauge$11 = 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);
517
+ 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);
529
518
 
530
- function set$11(sourceName, chainId, blockNumber) {
531
- handleInt$1(gauge$11, {
519
+ function set$10(sourceName, chainId, blockNumber) {
520
+ handleInt$1(gauge$10, {
532
521
  source: sourceName,
533
522
  chainId: chainId
534
523
  }, blockNumber);
535
524
  }
536
525
 
537
526
  let SourceHeight = {
538
- gauge: gauge$11,
539
- set: set$11
527
+ gauge: gauge$10,
528
+ set: set$10
540
529
  };
541
530
 
542
531
  let counter$4 = makeOrThrow("envio_reorg_detected_total", "Total number of reorgs detected", chainIdLabelsSchema);
@@ -550,43 +539,43 @@ let ReorgCount = {
550
539
  increment: increment$5
551
540
  };
552
541
 
553
- let gauge$12 = 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);
542
+ 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);
554
543
 
555
- function set$12(blockNumber, chain) {
556
- handleInt$1(gauge$12, chain, blockNumber);
544
+ function set$11(blockNumber, chain) {
545
+ handleInt$1(gauge$11, chain, blockNumber);
557
546
  }
558
547
 
559
548
  let ReorgDetectionBlockNumber = {
560
- gauge: gauge$12,
561
- set: set$12
549
+ gauge: gauge$11,
550
+ set: set$11
562
551
  };
563
552
 
564
- let gauge$13 = PromClient.Gauge.makeGauge({
553
+ let gauge$12 = PromClient.Gauge.makeGauge({
565
554
  name: "envio_reorg_threshold",
566
555
  help: "Whether indexing is currently within the reorg threshold"
567
556
  });
568
557
 
569
- function set$13(isInReorgThreshold) {
570
- gauge$13.set(isInReorgThreshold ? 1 : 0);
558
+ function set$12(isInReorgThreshold) {
559
+ gauge$12.set(isInReorgThreshold ? 1 : 0);
571
560
  }
572
561
 
573
562
  let ReorgThreshold = {
574
- gauge: gauge$13,
575
- set: set$13
563
+ gauge: gauge$12,
564
+ set: set$12
576
565
  };
577
566
 
578
- let gauge$14 = PromClient.Gauge.makeGauge({
567
+ let gauge$13 = PromClient.Gauge.makeGauge({
579
568
  name: "envio_rollback_enabled",
580
569
  help: "Whether rollback on reorg is enabled"
581
570
  });
582
571
 
583
- function set$14(enabled) {
584
- gauge$14.set(enabled ? 1 : 0);
572
+ function set$13(enabled) {
573
+ gauge$13.set(enabled ? 1 : 0);
585
574
  }
586
575
 
587
576
  let RollbackEnabled = {
588
- gauge: gauge$14,
589
- set: set$14
577
+ gauge: gauge$13,
578
+ set: set$13
590
579
  };
591
580
 
592
581
  let timeCounter$3 = PromClient.Counter.makeCounter({
@@ -635,62 +624,62 @@ let RollbackHistoryPrune = {
635
624
  increment: increment$7
636
625
  };
637
626
 
638
- let gauge$15 = makeOrThrow$1("envio_rollback_target_block", "The block number reorg was rollbacked to the last time.", chainIdLabelsSchema);
627
+ let gauge$14 = makeOrThrow$1("envio_rollback_target_block", "The block number reorg was rollbacked to the last time.", chainIdLabelsSchema);
639
628
 
640
- function set$15(blockNumber, chain) {
641
- handleInt$1(gauge$15, chain, blockNumber);
629
+ function set$14(blockNumber, chain) {
630
+ handleInt$1(gauge$14, chain, blockNumber);
642
631
  }
643
632
 
644
633
  let RollbackTargetBlockNumber = {
645
- gauge: gauge$15,
646
- set: set$15
634
+ gauge: gauge$14,
635
+ set: set$14
647
636
  };
648
637
 
649
- let gauge$16 = PromClient.Gauge.makeGauge({
638
+ let gauge$15 = PromClient.Gauge.makeGauge({
650
639
  name: "envio_processing_max_batch_size",
651
640
  help: "The maximum number of items to process in a single batch."
652
641
  });
653
642
 
654
- function set$16(maxBatchSize) {
655
- gauge$16.set(maxBatchSize);
643
+ function set$15(maxBatchSize) {
644
+ gauge$15.set(maxBatchSize);
656
645
  }
657
646
 
658
647
  let ProcessingMaxBatchSize = {
659
- gauge: gauge$16,
660
- set: set$16
648
+ gauge: gauge$15,
649
+ set: set$15
661
650
  };
662
651
 
663
- let gauge$17 = makeOrThrow$1("envio_progress_block", "The block number of the latest block processed and stored in the database.", chainIdLabelsSchema);
652
+ let gauge$16 = makeOrThrow$1("envio_progress_block", "The block number of the latest block processed and stored in the database.", chainIdLabelsSchema);
664
653
 
665
- function set$17(blockNumber, chainId) {
666
- handleInt$1(gauge$17, chainId, blockNumber);
654
+ function set$16(blockNumber, chainId) {
655
+ handleInt$1(gauge$16, chainId, blockNumber);
667
656
  }
668
657
 
669
658
  let ProgressBlockNumber = {
670
- gauge: gauge$17,
671
- set: set$17
659
+ gauge: gauge$16,
660
+ set: set$16
672
661
  };
673
662
 
674
- let gauge$18 = makeOrThrow$1("envio_progress_events", "The number of events processed and reflected in the database.", chainIdLabelsSchema);
663
+ let gauge$17 = makeOrThrow$1("envio_progress_events", "The number of events processed and reflected in the database.", chainIdLabelsSchema);
675
664
 
676
- function set$18(processedCount, chainId) {
677
- handleFloat$1(gauge$18, chainId, processedCount);
665
+ function set$17(processedCount, chainId) {
666
+ handleFloat$1(gauge$17, chainId, processedCount);
678
667
  }
679
668
 
680
669
  let ProgressEventsCount = {
681
- gauge: gauge$18,
682
- set: set$18
670
+ gauge: gauge$17,
671
+ set: set$17
683
672
  };
684
673
 
685
- let gauge$19 = makeOrThrow$1("envio_progress_latency", "The latency in milliseconds between the latest processed event creation and the time it was written to storage.", chainIdLabelsSchema);
674
+ let gauge$18 = makeOrThrow$1("envio_progress_latency", "The latency in milliseconds between the latest processed event creation and the time it was written to storage.", chainIdLabelsSchema);
686
675
 
687
- function set$19(latencyMs, chainId) {
688
- handleInt$1(gauge$19, chainId, latencyMs);
676
+ function set$18(latencyMs, chainId) {
677
+ handleInt$1(gauge$18, chainId, latencyMs);
689
678
  }
690
679
 
691
680
  let ProgressLatency = {
692
- gauge: gauge$19,
693
- set: set$19
681
+ gauge: gauge$18,
682
+ set: set$18
694
683
  };
695
684
 
696
685
  let effectLabelsSchema = S$RescriptSchema.object(s => s.f("effect", S$RescriptSchema.string));
@@ -710,15 +699,15 @@ let EffectCalls = {
710
699
  activeCallsCount: activeCallsCount
711
700
  };
712
701
 
713
- let gauge$20 = makeOrThrow$1("envio_effect_cache", "The number of items in the effect cache.", effectLabelsSchema);
702
+ let gauge$19 = makeOrThrow$1("envio_effect_cache", "The number of items in the effect cache.", effectLabelsSchema);
714
703
 
715
- function set$20(count, effectName) {
716
- handleInt$1(gauge$20, effectName, count);
704
+ function set$19(count, effectName) {
705
+ handleInt$1(gauge$19, effectName, count);
717
706
  }
718
707
 
719
708
  let EffectCacheCount = {
720
- gauge: gauge$20,
721
- set: set$20
709
+ gauge: gauge$19,
710
+ set: set$19
722
711
  };
723
712
 
724
713
  let counter$7 = makeOrThrow("envio_effect_cache_invalidations", "The number of effect cache invalidations.", effectLabelsSchema);
@@ -732,18 +721,18 @@ let EffectCacheInvalidationsCount = {
732
721
  increment: increment$8
733
722
  };
734
723
 
735
- let gauge$21 = makeOrThrow$1("envio_effect_queue", "The number of effect calls waiting in the rate limit queue.", effectLabelsSchema);
724
+ let gauge$20 = makeOrThrow$1("envio_effect_queue", "The number of effect calls waiting in the rate limit queue.", effectLabelsSchema);
736
725
 
737
726
  let timeCounter$6 = makeOrThrow("envio_effect_queue_wait_seconds", "The time spent waiting in the rate limit queue.", effectLabelsSchema);
738
727
 
739
- function set$21(count, effectName) {
740
- handleInt$1(gauge$21, effectName, count);
728
+ function set$20(count, effectName) {
729
+ handleInt$1(gauge$20, effectName, count);
741
730
  }
742
731
 
743
732
  let EffectQueueCount = {
744
- gauge: gauge$21,
733
+ gauge: gauge$20,
745
734
  timeCounter: timeCounter$6,
746
- set: set$21
735
+ set: set$20
747
736
  };
748
737
 
749
738
  let loadLabelsSchema = S$RescriptSchema.schema(s => ({
@@ -846,7 +835,6 @@ export {
846
835
  IndexingKnownHeight,
847
836
  Info,
848
837
  ProcessStartTimeSeconds,
849
- IndexingAddresses,
850
838
  IndexingConcurrency,
851
839
  IndexingPartitions,
852
840
  IndexingIdleTime,
@@ -234,6 +234,10 @@ let deriveSrcAddress = (
234
234
  // A non-wildcard event is gated by `clientAddressFilter` on srcAddress ownership,
235
235
  // so a simulate item whose srcAddress isn't indexed on this chain would be
236
236
  // silently dropped (handler never runs). Fail loudly instead.
237
+ //
238
+ // `config` must already have handler registrations applied, otherwise an event
239
+ // made wildcard purely through `indexer.onEvent({ wildcard: true })` reads back
240
+ // as non-wildcard and gets wrongly rejected.
237
241
  let validateSrcAddresses = (
238
242
  ~simulateItems: array<JSON.t>,
239
243
  ~config: Config.t,
@@ -667,8 +667,11 @@ let makeCreateTestIndexer = (~config: Config.t, ~workerPath: string): (
667
667
  Int.compare(aId, bId)
668
668
  })
669
669
 
670
- // Parse and validate all chain configs upfront before starting any workers
671
- let preflightAddressesByChain = getIndexingAddressesByChain(state)
670
+ // Parse and validate the block ranges upfront before starting any
671
+ // workers. srcAddress validation can't run here: it depends on which
672
+ // events are wildcard, and `config` reflects config.yaml only —
673
+ // handler-level `wildcard: true` takes effect only once registrations
674
+ // are applied.
672
675
  let chainEntries = sortedChainKeys->Array.map(chainIdStr => {
673
676
  let rawChainConfig = rawChains->Dict.getUnsafe(chainIdStr)
674
677
  let chainId = switch chainIdStr->Int.fromString {
@@ -684,19 +687,6 @@ let makeCreateTestIndexer = (~config: Config.t, ~workerPath: string): (
684
687
  ~rawChainConfig,
685
688
  ~progressBlock=state.progressBlockByChain->Dict.get(chainIdStr),
686
689
  )
687
- switch rawChainConfig.simulate {
688
- | Some(simulateItems) =>
689
- let chainConfig = config.chainMap->ChainMap.get(ChainMap.Chain.makeUnsafe(~chainId))
690
- SimulateItems.validateSrcAddresses(
691
- ~simulateItems,
692
- ~config,
693
- ~chainConfig,
694
- ~indexingAddresses=preflightAddressesByChain
695
- ->Dict.get(chainIdStr)
696
- ->Option.getOr([]),
697
- )
698
- | None => ()
699
- }
700
690
  (chainIdStr, chainId, rawChainConfig, processChainConfig)
701
691
  })
702
692
 
@@ -877,7 +867,27 @@ let initTestWorker = () => {
877
867
  | Some(_) => ()
878
868
  }
879
869
 
880
- let patchConfig = (config, _registrations) => {
870
+ let patchConfig = (config: Config.t, _registrations) => {
871
+ // `config` here has handler registrations applied, so `isWildcard`
872
+ // reflects `indexer.onEvent({ wildcard: true })` — which the main thread
873
+ // can't see. Validate srcAddresses against it before patching in the
874
+ // simulate source.
875
+ switch simulate {
876
+ | Some(simulateItems) =>
877
+ let chainConfig = config.chainMap->ChainMap.get(ChainMap.Chain.makeUnsafe(~chainId))
878
+ let indexingAddresses =
879
+ initialState.chains
880
+ ->Array.find(c => c.id == chainId)
881
+ ->Option.mapOr([], c => c.indexingAddresses)
882
+ SimulateItems.validateSrcAddresses(
883
+ ~simulateItems,
884
+ ~config,
885
+ ~chainConfig,
886
+ ~indexingAddresses,
887
+ )
888
+ | None => ()
889
+ }
890
+
881
891
  let config = SimulateItems.patchConfig(~config, ~processConfig)
882
892
 
883
893
  // In auto-exit mode, set batchSize=1 to process one block checkpoint at a time
@@ -887,7 +897,23 @@ let initTestWorker = () => {
887
897
  config
888
898
  }
889
899
  }
890
- Main.start(~persistence, ~isTest=true, ~patchConfig, ~exitAfterFirstEventBlock)->ignore
900
+ Main.start(~persistence, ~isTest=true, ~patchConfig, ~exitAfterFirstEventBlock)
901
+ ->Promise.catch(exn => {
902
+ // `Main.start` rejects on any fatal error: a runtime failure arrives wrapped
903
+ // in `Main.FatalError` (already logged), a setup throw (e.g. patchConfig's
904
+ // srcAddress validation) arrives raw. The parent only learns of failures
905
+ // through the worker `error` event, which fires on an *uncaught* exception.
906
+ // Throwing synchronously in this catch would just reject the catch's own
907
+ // promise (swallowed by `ignore`); `setImmediate` re-throws outside the
908
+ // promise chain so it becomes uncaught and reaches the parent.
909
+ let toThrow = switch exn {
910
+ | Main.FatalError(inner) => inner
911
+ | _ => exn->Utils.prettifyExn
912
+ }
913
+ NodeJs.setImmediate(() => throw(toThrow))
914
+ Promise.resolve()
915
+ })
916
+ ->ignore
891
917
  | None =>
892
918
  Logging.error("TestIndexerWorker: No worker data provided")
893
919
  NodeJs.process->NodeJs.exitWithCode(Failure)
@@ -481,17 +481,11 @@ function makeCreateTestIndexer(config, workerPath) {
481
481
  let bId = Stdlib_Option.getOr(Stdlib_Int.fromString(b, undefined), 0);
482
482
  return Primitive_int.compare(aId, bId);
483
483
  });
484
- let preflightAddressesByChain = getIndexingAddressesByChain(state);
485
484
  let chainEntries = sortedChainKeys.map(chainIdStr => {
486
485
  let rawChainConfig = rawChains[chainIdStr];
487
486
  let id = Stdlib_Int.fromString(chainIdStr, undefined);
488
487
  let chainId = id !== undefined ? id : Stdlib_JsError.throwWithMessage(`Invalid chain ID "` + chainIdStr + `": expected a numeric chain ID`);
489
488
  let processChainConfig = parseBlockRange(chainIdStr, config, rawChainConfig, state.progressBlockByChain[chainIdStr]);
490
- let simulateItems = rawChainConfig.simulate;
491
- if (simulateItems !== undefined) {
492
- let chainConfig = ChainMap.get(config.chainMap, ChainMap.Chain.makeUnsafe(chainId));
493
- SimulateItems.validateSrcAddresses(simulateItems, config, chainConfig, Stdlib_Option.getOr(preflightAddressesByChain[chainIdStr], []));
494
- }
495
489
  return [
496
490
  chainIdStr,
497
491
  chainId,
@@ -592,9 +586,11 @@ function initTestWorker() {
592
586
  Process.exit(1);
593
587
  return;
594
588
  }
589
+ let initialState = workerData.initialState;
595
590
  let simulate = workerData.simulate;
596
591
  let endBlock = workerData.endBlock;
597
- let chainIdStr = workerData.chainId.toString();
592
+ let chainId = workerData.chainId;
593
+ let chainIdStr = chainId.toString();
598
594
  let exitAfterFirstEventBlock = Stdlib_Option.isNone(endBlock);
599
595
  let resolvedChainDict = {};
600
596
  resolvedChainDict["startBlock"] = workerData.startBlock;
@@ -609,7 +605,7 @@ function initTestWorker() {
609
605
  let processConfig = {
610
606
  chains: resolvedChainsDict
611
607
  };
612
- let proxy = TestIndexerProxyStorage.make(parentPort, workerData.initialState);
608
+ let proxy = TestIndexerProxyStorage.make(parentPort, initialState);
613
609
  let storage = TestIndexerProxyStorage.makeStorage(proxy);
614
610
  let config = Config.loadWithoutRegistrations();
615
611
  let persistence = Persistence.make(config.userEntities, config.allEnums, storage);
@@ -619,6 +615,11 @@ function initTestWorker() {
619
615
  Logging.setLogLevel("silent");
620
616
  }
621
617
  let patchConfig = (config, _registrations) => {
618
+ if (simulate !== undefined) {
619
+ let chainConfig = ChainMap.get(config.chainMap, ChainMap.Chain.makeUnsafe(chainId));
620
+ let indexingAddresses = Stdlib_Option.mapOr(initialState.chains.find(c => c.id === chainId), [], c => c.indexingAddresses);
621
+ SimulateItems.validateSrcAddresses(simulate, config, chainConfig, indexingAddresses);
622
+ }
622
623
  let config$1 = SimulateItems.patchConfig(config, processConfig);
623
624
  if (exitAfterFirstEventBlock) {
624
625
  return {
@@ -646,7 +647,13 @@ function initTestWorker() {
646
647
  return config$1;
647
648
  }
648
649
  };
649
- Main.start(persistence, undefined, true, exitAfterFirstEventBlock, patchConfig);
650
+ Stdlib_Promise.$$catch(Main.start(persistence, undefined, true, exitAfterFirstEventBlock, patchConfig), exn => {
651
+ let toThrow = exn.RE_EXN_ID === Main.FatalError ? exn._1 : Utils.prettifyExn(exn);
652
+ setImmediate(() => {
653
+ throw toThrow;
654
+ });
655
+ return Promise.resolve();
656
+ });
650
657
  }
651
658
 
652
659
  export {
@@ -1,52 +1,11 @@
1
- type eventLog = {
2
- abi: EvmTypes.Abi.t,
3
- data: string,
4
- topics: array<EvmTypes.Hex.t>,
5
- }
6
-
7
- type decodedEvent<'a> = {
8
- eventName: string,
9
- args: 'a,
10
- }
11
-
12
- @module("viem") external decodeEventLogOrThrow: eventLog => decodedEvent<'a> = "decodeEventLog"
13
-
14
1
  type hex = EvmTypes.Hex.t
15
2
  @module("viem") external toHex: 'a => hex = "toHex"
16
3
  @module("viem") external keccak256: hex => hex = "keccak256"
17
- @module("viem") external keccak256Bytes: Uint8Array.t => hex = "keccak256"
18
4
  @module("viem") external pad: hex => hex = "pad"
19
- @module("viem")
20
- external encodePacked: (~types: array<string>, ~values: array<'a>) => hex = "encodePacked"
21
5
 
22
6
  type sizeOptions = {size: int}
23
- @module("viem") external intToHex: (int, ~options: sizeOptions=?) => hex = "numberToHex"
24
7
  @module("viem") external bigintToHex: (bigint, ~options: sizeOptions=?) => hex = "numberToHex"
25
8
  @module("viem") external stringToHex: (string, ~options: sizeOptions=?) => hex = "stringToHex"
26
9
  @module("viem") external boolToHex: (bool, ~options: sizeOptions=?) => hex = "boolToHex"
27
10
  @module("viem") external bytesToHex: (Uint8Array.t, ~options: sizeOptions=?) => hex = "bytesToHex"
28
11
  @module("viem") external concat: array<hex> => hex = "concat"
29
-
30
- exception ParseError(exn)
31
- exception UnknownContractName({contractName: string})
32
-
33
- let parseLogOrThrow = (
34
- contractNameAbiMapping: dict<EvmTypes.Abi.t>,
35
- ~contractName,
36
- ~topics,
37
- ~data,
38
- ) => {
39
- switch contractNameAbiMapping->Utils.Dict.dangerouslyGetNonOption(contractName) {
40
- | None => throw(UnknownContractName({contractName: contractName}))
41
- | Some(abi) =>
42
- let viemLog: eventLog = {
43
- abi,
44
- data,
45
- topics,
46
- }
47
-
48
- try viemLog->decodeEventLogOrThrow catch {
49
- | exn => throw(ParseError(exn))
50
- }
51
- }
52
- }
@@ -1,44 +1,2 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
-
3
- import * as Viem from "viem";
4
- import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
5
- import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
6
-
7
- let ParseError = /* @__PURE__ */Primitive_exceptions.create("Viem.ParseError");
8
-
9
- let UnknownContractName = /* @__PURE__ */Primitive_exceptions.create("Viem.UnknownContractName");
10
-
11
- function parseLogOrThrow(contractNameAbiMapping, contractName, topics, data) {
12
- let abi = contractNameAbiMapping[contractName];
13
- if (abi !== undefined) {
14
- let viemLog_abi = Primitive_option.valFromOption(abi);
15
- let viemLog = {
16
- abi: viemLog_abi,
17
- data: data,
18
- topics: topics
19
- };
20
- try {
21
- return Viem.decodeEventLog(viemLog);
22
- } catch (raw_exn) {
23
- let exn = Primitive_exceptions.internalToException(raw_exn);
24
- throw {
25
- RE_EXN_ID: ParseError,
26
- _1: exn,
27
- Error: new Error()
28
- };
29
- }
30
- } else {
31
- throw {
32
- RE_EXN_ID: UnknownContractName,
33
- contractName: contractName,
34
- Error: new Error()
35
- };
36
- }
37
- }
38
-
39
- export {
40
- ParseError,
41
- UnknownContractName,
42
- parseLogOrThrow,
43
- }
44
- /* viem Not a pure module */
2
+ /* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */