envio 3.0.0-alpha.3 → 3.0.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 (79) hide show
  1. package/README.md +2 -2
  2. package/evm.schema.json +0 -1
  3. package/index.d.ts +333 -2
  4. package/index.js +4 -0
  5. package/package.json +13 -6
  6. package/rescript.json +4 -1
  7. package/src/ChainFetcher.res +25 -1
  8. package/src/ChainFetcher.res.mjs +19 -1
  9. package/src/Config.res +212 -19
  10. package/src/Config.res.mjs +228 -29
  11. package/src/{Indexer.res → Ctx.res} +1 -1
  12. package/src/Ecosystem.res +2 -2
  13. package/src/Ecosystem.res.mjs +1 -1
  14. package/src/Envio.gen.ts +1 -1
  15. package/src/Envio.res +1 -1
  16. package/src/EventProcessing.res +18 -18
  17. package/src/EventProcessing.res.mjs +14 -14
  18. package/src/GlobalState.res +29 -35
  19. package/src/GlobalState.res.mjs +47 -47
  20. package/src/GlobalStateManager.res +68 -0
  21. package/src/GlobalStateManager.res.mjs +75 -0
  22. package/src/GlobalStateManager.resi +7 -0
  23. package/src/Internal.res +41 -1
  24. package/src/LogSelection.res +33 -27
  25. package/src/LogSelection.res.mjs +6 -0
  26. package/src/Main.res +342 -0
  27. package/src/Main.res.mjs +289 -0
  28. package/src/PgStorage.gen.ts +10 -0
  29. package/src/PgStorage.res +24 -2
  30. package/src/PgStorage.res.d.mts +5 -0
  31. package/src/PgStorage.res.mjs +22 -1
  32. package/src/Types.ts +1 -1
  33. package/src/UserContext.res +0 -1
  34. package/src/UserContext.res.mjs +0 -2
  35. package/src/Utils.res +28 -0
  36. package/src/Utils.res.mjs +18 -0
  37. package/src/bindings/ClickHouse.res +31 -1
  38. package/src/bindings/ClickHouse.res.mjs +27 -1
  39. package/src/bindings/Ethers.res +27 -67
  40. package/src/bindings/Ethers.res.mjs +18 -70
  41. package/src/bindings/Postgres.gen.ts +8 -0
  42. package/src/bindings/Postgres.res +3 -0
  43. package/src/bindings/Postgres.res.d.mts +5 -0
  44. package/src/bindings/RescriptMocha.res +123 -0
  45. package/src/bindings/RescriptMocha.res.mjs +18 -0
  46. package/src/bindings/Yargs.res +8 -0
  47. package/src/bindings/Yargs.res.mjs +2 -0
  48. package/src/sources/FuelSDK.res +4 -3
  49. package/src/sources/HyperSyncHeightStream.res +28 -110
  50. package/src/sources/HyperSyncHeightStream.res.mjs +30 -63
  51. package/src/sources/HyperSyncSource.res +11 -13
  52. package/src/sources/HyperSyncSource.res.mjs +20 -20
  53. package/src/sources/Rpc.res +43 -0
  54. package/src/sources/Rpc.res.mjs +31 -0
  55. package/src/sources/RpcSource.res +9 -4
  56. package/src/sources/RpcSource.res.mjs +9 -4
  57. package/src/sources/Source.res +1 -0
  58. package/src/sources/SourceManager.res +164 -81
  59. package/src/sources/SourceManager.res.mjs +146 -83
  60. package/src/sources/{Solana.res → Svm.res} +4 -4
  61. package/src/sources/{Solana.res.mjs → Svm.res.mjs} +4 -4
  62. package/src/tui/Tui.res +266 -0
  63. package/src/tui/Tui.res.mjs +342 -0
  64. package/src/tui/bindings/Ink.res +376 -0
  65. package/src/tui/bindings/Ink.res.mjs +75 -0
  66. package/src/tui/bindings/Style.res +123 -0
  67. package/src/tui/bindings/Style.res.mjs +2 -0
  68. package/src/tui/components/BufferedProgressBar.res +40 -0
  69. package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
  70. package/src/tui/components/CustomHooks.res +114 -0
  71. package/src/tui/components/CustomHooks.res.mjs +162 -0
  72. package/src/tui/components/Messages.res +41 -0
  73. package/src/tui/components/Messages.res.mjs +75 -0
  74. package/src/tui/components/SyncETA.res +193 -0
  75. package/src/tui/components/SyncETA.res.mjs +269 -0
  76. package/src/tui/components/TuiData.res +46 -0
  77. package/src/tui/components/TuiData.res.mjs +29 -0
  78. package/src/bindings/Ethers.gen.ts +0 -14
  79. /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
@@ -55,11 +55,11 @@ var WriteThrottlers = {
55
55
  make: make
56
56
  };
57
57
 
58
- function make$1(indexer, chainManager, isDevelopmentModeOpt, shouldUseTuiOpt) {
58
+ function make$1(ctx, chainManager, isDevelopmentModeOpt, shouldUseTuiOpt) {
59
59
  var isDevelopmentMode = isDevelopmentModeOpt !== undefined ? isDevelopmentModeOpt : false;
60
60
  var shouldUseTui = shouldUseTuiOpt !== undefined ? shouldUseTuiOpt : false;
61
61
  return {
62
- indexer: indexer,
62
+ ctx: ctx,
63
63
  chainManager: chainManager,
64
64
  processedBatches: 0,
65
65
  currentlyProcessingBatch: false,
@@ -78,7 +78,7 @@ function getId(self) {
78
78
 
79
79
  function incrementId(self) {
80
80
  return {
81
- indexer: self.indexer,
81
+ ctx: self.ctx,
82
82
  chainManager: self.chainManager,
83
83
  processedBatches: self.processedBatches,
84
84
  currentlyProcessingBatch: self.currentlyProcessingBatch,
@@ -93,7 +93,7 @@ function incrementId(self) {
93
93
 
94
94
  function setChainManager(self, chainManager) {
95
95
  return {
96
- indexer: self.indexer,
96
+ ctx: self.ctx,
97
97
  chainManager: chainManager,
98
98
  processedBatches: self.processedBatches,
99
99
  currentlyProcessingBatch: self.currentlyProcessingBatch,
@@ -138,7 +138,7 @@ function updateChainMetadataTable(cm, persistence, throttler) {
138
138
  }));
139
139
  }
140
140
 
141
- function updateProgressedChains(chainManager, batch, indexer) {
141
+ function updateProgressedChains(chainManager, batch, ctx) {
142
142
  Prometheus.ProgressBatchCount.increment();
143
143
  var nextQueueItemIsNone = ChainManager.nextItemIsNone(chainManager);
144
144
  var allChainsAtHead = ChainManager.isProgressAtHead(chainManager);
@@ -155,7 +155,7 @@ function updateProgressedChains(chainManager, batch, indexer) {
155
155
  }
156
156
  var eventItem = Batch.findLastEventItem(batch, chain);
157
157
  if (eventItem !== undefined) {
158
- var blockTimestamp = indexer.config.ecosystem.getTimestamp(eventItem.event.block);
158
+ var blockTimestamp = ctx.config.ecosystem.getTimestamp(eventItem.event.block);
159
159
  var currentTimeMs = Date.now() | 0;
160
160
  var blockTimestampMs = Math.imul(blockTimestamp, 1000);
161
161
  var latencyMs = currentTimeMs - blockTimestampMs | 0;
@@ -181,7 +181,7 @@ function updateProgressedChains(chainManager, batch, indexer) {
181
181
  cf$1 = cf;
182
182
  }
183
183
  if (ChainFetcher.hasProcessedToEndblock(cf$1)) {
184
- var timestampCaughtUpToHeadOrEndblock = Belt_Option.isSome(cf$1.timestampCaughtUpToHeadOrEndblock) ? cf$1.timestampCaughtUpToHeadOrEndblock : Caml_option.some(new Date());
184
+ var timestampCaughtUpToHeadOrEndblock = ChainFetcher.isLive(cf$1) ? cf$1.timestampCaughtUpToHeadOrEndblock : Caml_option.some(new Date());
185
185
  return {
186
186
  logger: cf$1.logger,
187
187
  fetchState: cf$1.fetchState,
@@ -197,7 +197,7 @@ function updateProgressedChains(chainManager, batch, indexer) {
197
197
  safeCheckpointTracking: cf$1.safeCheckpointTracking
198
198
  };
199
199
  }
200
- if (!(Belt_Option.isNone(cf$1.timestampCaughtUpToHeadOrEndblock) && cf$1.isProgressAtHead)) {
200
+ if (!(!ChainFetcher.isLive(cf$1) && cf$1.isProgressAtHead)) {
201
201
  return cf$1;
202
202
  }
203
203
  if (nextQueueItemIsNone && allChainsAtHead) {
@@ -237,7 +237,7 @@ function updateProgressedChains(chainManager, batch, indexer) {
237
237
  }
238
238
  }));
239
239
  var allChainsSyncedAtHead = Belt_Array.every(ChainMap.values(chainFetchers), (function (cf) {
240
- return Belt_Option.isSome(cf.timestampCaughtUpToHeadOrEndblock);
240
+ return ChainFetcher.isLive(cf);
241
241
  }));
242
242
  if (allChainsSyncedAtHead) {
243
243
  Prometheus.setAllChainsSyncedToHead();
@@ -302,7 +302,7 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
302
302
  safeCheckpointTracking: updatedChainFetcher_safeCheckpointTracking
303
303
  };
304
304
  var init = state.chainManager;
305
- var nextState_indexer = state.indexer;
305
+ var nextState_ctx = state.ctx;
306
306
  var nextState_chainManager = {
307
307
  committedCheckpointId: init.committedCheckpointId,
308
308
  chainFetchers: ChainMap.set(state.chainManager.chainFetchers, chain, updatedChainFetcher),
@@ -318,7 +318,7 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
318
318
  var nextState_keepProcessAlive = state.keepProcessAlive;
319
319
  var nextState_id = state.id;
320
320
  var nextState = {
321
- indexer: nextState_indexer,
321
+ ctx: nextState_ctx,
322
322
  chainManager: nextState_chainManager,
323
323
  processedBatches: nextState_processedBatches,
324
324
  currentlyProcessingBatch: nextState_currentlyProcessingBatch,
@@ -334,10 +334,10 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
334
334
  rollbackWithReorgDetectedBlockNumber = undefined;
335
335
  } else {
336
336
  var reorgDetected = reorgResult._0;
337
- Logging.childInfo(chainFetcher.logger, ReorgDetection.reorgDetectedToLogParams(reorgDetected, state.indexer.config.shouldRollbackOnReorg));
337
+ Logging.childInfo(chainFetcher.logger, ReorgDetection.reorgDetectedToLogParams(reorgDetected, state.ctx.config.shouldRollbackOnReorg));
338
338
  Prometheus.ReorgCount.increment(chain);
339
339
  Prometheus.ReorgDetectionBlockNumber.set(reorgDetected.scannedBlock.blockNumber, chain);
340
- rollbackWithReorgDetectedBlockNumber = state.indexer.config.shouldRollbackOnReorg ? reorgDetected.scannedBlock.blockNumber : undefined;
340
+ rollbackWithReorgDetectedBlockNumber = state.ctx.config.shouldRollbackOnReorg ? reorgDetected.scannedBlock.blockNumber : undefined;
341
341
  }
342
342
  if (rollbackWithReorgDetectedBlockNumber === undefined) {
343
343
  return [
@@ -385,7 +385,7 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
385
385
  var init$2 = incrementId(nextState);
386
386
  return [
387
387
  {
388
- indexer: init$2.indexer,
388
+ ctx: init$2.ctx,
389
389
  chainManager: chainManager,
390
390
  processedBatches: init$2.processedBatches,
391
391
  currentlyProcessingBatch: init$2.currentlyProcessingBatch,
@@ -437,7 +437,7 @@ function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHei
437
437
  Logging.childInfo(updatedChainFetcher_logger, "All events have been fetched");
438
438
  }
439
439
  var init = state.chainManager;
440
- var nextState_indexer = state.indexer;
440
+ var nextState_ctx = state.ctx;
441
441
  var nextState_chainManager = {
442
442
  committedCheckpointId: init.committedCheckpointId,
443
443
  chainFetchers: ChainMap.set(state.chainManager.chainFetchers, chain, updatedChainFetcher$1),
@@ -453,7 +453,7 @@ function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHei
453
453
  var nextState_keepProcessAlive = state.keepProcessAlive;
454
454
  var nextState_id = state.id;
455
455
  var nextState = {
456
- indexer: nextState_indexer,
456
+ ctx: nextState_ctx,
457
457
  chainManager: nextState_chainManager,
458
458
  processedBatches: nextState_processedBatches,
459
459
  currentlyProcessingBatch: nextState_currentlyProcessingBatch,
@@ -496,7 +496,7 @@ async function processPartitionQueryResponse(state, param, dispatchAction) {
496
496
  }
497
497
  newItems.push(item);
498
498
  }
499
- var newItemsWithDcs = itemsWithContractRegister.length !== 0 ? await ChainFetcher.runContractRegistersOrThrow(itemsWithContractRegister, chain, state.indexer.config) : itemsWithContractRegister;
499
+ var newItemsWithDcs = itemsWithContractRegister.length !== 0 ? await ChainFetcher.runContractRegistersOrThrow(itemsWithContractRegister, chain, state.ctx.config) : itemsWithContractRegister;
500
500
  return dispatchAction({
501
501
  TAG: "SubmitPartitionQueryResponse",
502
502
  newItems: newItems,
@@ -515,7 +515,7 @@ function updateChainFetcher(chainFetcherUpdate, state, chain) {
515
515
  var init = state.chainManager;
516
516
  return [
517
517
  {
518
- indexer: state.indexer,
518
+ ctx: state.ctx,
519
519
  chainManager: {
520
520
  committedCheckpointId: init.committedCheckpointId,
521
521
  chainFetchers: ChainMap.update(state.chainManager.chainFetchers, chain, chainFetcherUpdate),
@@ -556,7 +556,7 @@ function onEnterReorgThreshold(state) {
556
556
  }));
557
557
  var init = state.chainManager;
558
558
  return {
559
- indexer: state.indexer,
559
+ ctx: state.ctx,
560
560
  chainManager: {
561
561
  committedCheckpointId: init.committedCheckpointId,
562
562
  chainFetchers: chainFetchers,
@@ -580,7 +580,7 @@ function actionReducer(state, action) {
580
580
  case "StartProcessingBatch" :
581
581
  return [
582
582
  {
583
- indexer: state.indexer,
583
+ ctx: state.ctx,
584
584
  chainManager: state.chainManager,
585
585
  processedBatches: state.processedBatches,
586
586
  currentlyProcessingBatch: true,
@@ -596,7 +596,7 @@ function actionReducer(state, action) {
596
596
  case "StartFindingReorgDepth" :
597
597
  return [
598
598
  {
599
- indexer: state.indexer,
599
+ ctx: state.ctx,
600
600
  chainManager: state.chainManager,
601
601
  processedBatches: state.processedBatches,
602
602
  currentlyProcessingBatch: state.currentlyProcessingBatch,
@@ -656,12 +656,12 @@ function actionReducer(state, action) {
656
656
  return chainFetcher;
657
657
  }
658
658
  }));
659
- var isBelowReorgThreshold = !state.chainManager.isInReorgThreshold && state.indexer.config.shouldRollbackOnReorg;
659
+ var isBelowReorgThreshold = !state.chainManager.isInReorgThreshold && state.ctx.config.shouldRollbackOnReorg;
660
660
  var shouldEnterReorgThreshold = isBelowReorgThreshold && Belt_Array.every(ChainMap.values(updatedChainFetchers), (function (chainFetcher) {
661
661
  return FetchState.isReadyToEnterReorgThreshold(chainFetcher.fetchState);
662
662
  }));
663
663
  var init = state.chainManager;
664
- var state_indexer = state.indexer;
664
+ var state_ctx = state.ctx;
665
665
  var state_chainManager = {
666
666
  committedCheckpointId: init.committedCheckpointId,
667
667
  chainFetchers: updatedChainFetchers,
@@ -677,7 +677,7 @@ function actionReducer(state, action) {
677
677
  var state_keepProcessAlive = state.keepProcessAlive;
678
678
  var state_id = state.id;
679
679
  var state$1 = {
680
- indexer: state_indexer,
680
+ ctx: state_ctx,
681
681
  chainManager: state_chainManager,
682
682
  processedBatches: state_processedBatches,
683
683
  currentlyProcessingBatch: state_currentlyProcessingBatch,
@@ -715,9 +715,9 @@ function actionReducer(state, action) {
715
715
  ];
716
716
  }
717
717
  case "EventBatchProcessed" :
718
- var maybePruneEntityHistory = Config.shouldPruneHistory(state.indexer.config, state.chainManager.isInReorgThreshold) ? ["PruneStaleEntityHistory"] : [];
719
- var state_indexer$1 = state.indexer;
720
- var state_chainManager$1 = updateProgressedChains(state.chainManager, action.batch, state.indexer);
718
+ var maybePruneEntityHistory = Config.shouldPruneHistory(state.ctx.config, state.chainManager.isInReorgThreshold) ? ["PruneStaleEntityHistory"] : [];
719
+ var state_ctx$1 = state.ctx;
720
+ var state_chainManager$1 = updateProgressedChains(state.chainManager, action.batch, state.ctx);
721
721
  var state_processedBatches$1 = state.processedBatches + 1 | 0;
722
722
  var state_indexerStartTime$1 = state.indexerStartTime;
723
723
  var state_writeThrottlers$1 = state.writeThrottlers;
@@ -725,7 +725,7 @@ function actionReducer(state, action) {
725
725
  var state_keepProcessAlive$1 = state.keepProcessAlive;
726
726
  var state_id$1 = state.id;
727
727
  var state$2 = {
728
- indexer: state_indexer$1,
728
+ ctx: state_ctx$1,
729
729
  chainManager: state_chainManager$1,
730
730
  processedBatches: state_processedBatches$1,
731
731
  currentlyProcessingBatch: false,
@@ -750,7 +750,7 @@ function actionReducer(state, action) {
750
750
  case "FindReorgDepth" :
751
751
  return [
752
752
  {
753
- indexer: state.indexer,
753
+ ctx: state.ctx,
754
754
  chainManager: state.chainManager,
755
755
  processedBatches: state.processedBatches,
756
756
  currentlyProcessingBatch: state.currentlyProcessingBatch,
@@ -800,7 +800,7 @@ function actionReducer(state, action) {
800
800
  };
801
801
  return [
802
802
  {
803
- indexer: state.indexer,
803
+ ctx: state.ctx,
804
804
  chainManager: chainManager,
805
805
  processedBatches: state.processedBatches,
806
806
  currentlyProcessingBatch: state.currentlyProcessingBatch,
@@ -826,7 +826,7 @@ function actionReducer(state, action) {
826
826
  case "SetRollbackState" :
827
827
  return [
828
828
  {
829
- indexer: state.indexer,
829
+ ctx: state.ctx,
830
830
  chainManager: action.rollbackedChainManager,
831
831
  processedBatches: state.processedBatches,
832
832
  currentlyProcessingBatch: state.currentlyProcessingBatch,
@@ -862,8 +862,8 @@ function invalidatedActionReducer(state, action) {
862
862
  Logging.info("Finished processing batch before rollback, actioning rollback");
863
863
  return [
864
864
  {
865
- indexer: state.indexer,
866
- chainManager: updateProgressedChains(state.chainManager, action.batch, state.indexer),
865
+ ctx: state.ctx,
866
+ chainManager: updateProgressedChains(state.chainManager, action.batch, state.ctx),
867
867
  processedBatches: state.processedBatches + 1 | 0,
868
868
  currentlyProcessingBatch: false,
869
869
  rollbackState: state.rollbackState,
@@ -942,12 +942,12 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
942
942
  var match = state.rollbackState;
943
943
  var rollbackInMemStore;
944
944
  rollbackInMemStore = typeof match !== "object" || match.TAG !== "RollbackReady" ? undefined : match.diffInMemoryStore;
945
- var batch = ChainManager.createBatch(state.chainManager, state.indexer.config.batchSize, rollbackInMemStore !== undefined);
945
+ var batch = ChainManager.createBatch(state.chainManager, state.ctx.config.batchSize, rollbackInMemStore !== undefined);
946
946
  var progressedChainsById = batch.progressedChainsById;
947
947
  var totalBatchSize = batch.totalBatchSize;
948
948
  var isInReorgThreshold = state.chainManager.isInReorgThreshold;
949
- var shouldSaveHistory = Config.shouldSaveHistory(state.indexer.config, isInReorgThreshold);
950
- var isBelowReorgThreshold = !state.chainManager.isInReorgThreshold && state.indexer.config.shouldRollbackOnReorg;
949
+ var shouldSaveHistory = Config.shouldSaveHistory(state.ctx.config, isInReorgThreshold);
950
+ var isBelowReorgThreshold = !state.chainManager.isInReorgThreshold && state.ctx.config.shouldRollbackOnReorg;
951
951
  var shouldEnterReorgThreshold = isBelowReorgThreshold && Belt_Array.every(ChainMap.values(state.chainManager.chainFetchers), (function (chainFetcher) {
952
952
  var chainAfterBatch = progressedChainsById[chainFetcher.fetchState.chainId];
953
953
  var fetchState = chainAfterBatch !== undefined ? chainAfterBatch.fetchState : chainFetcher.fetchState;
@@ -968,11 +968,11 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
968
968
  progressedChainsById: progressedChainsById,
969
969
  shouldEnterReorgThreshold: shouldEnterReorgThreshold
970
970
  });
971
- var inMemoryStore = Belt_Option.getWithDefault(rollbackInMemStore, InMemoryStore.make(state.indexer.persistence.allEntities, undefined));
971
+ var inMemoryStore = Belt_Option.getWithDefault(rollbackInMemStore, InMemoryStore.make(state.ctx.persistence.allEntities, undefined));
972
972
  InMemoryStore.setBatchDcs(inMemoryStore, batch, shouldSaveHistory);
973
973
  var res;
974
974
  try {
975
- res = await EventProcessing.processEventBatch(batch, inMemoryStore, isInReorgThreshold, state.loadManager, state.indexer, state.chainManager.chainFetchers);
975
+ res = await EventProcessing.processEventBatch(batch, inMemoryStore, isInReorgThreshold, state.loadManager, state.ctx, state.chainManager.chainFetchers);
976
976
  }
977
977
  catch (raw_exn){
978
978
  var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
@@ -1030,12 +1030,12 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
1030
1030
  });
1031
1031
  Logging.childInfo(logger, "Started rollback on reorg");
1032
1032
  Prometheus.RollbackTargetBlockNumber.set(rollbackTargetBlockNumber$1, reorgChain);
1033
- var match$3 = await state.indexer.persistence.storage.getRollbackTargetCheckpoint(reorgChain, rollbackTargetBlockNumber$1);
1033
+ var match$3 = await state.ctx.persistence.storage.getRollbackTargetCheckpoint(reorgChain, rollbackTargetBlockNumber$1);
1034
1034
  var rollbackTargetCheckpointId = match$3.length !== 1 ? 0 : match$3[0].id;
1035
1035
  var eventsProcessedDiffByChain = {};
1036
1036
  var newProgressBlockNumberPerChain = {};
1037
1037
  var rollbackedProcessedEvents = 0;
1038
- var rollbackProgressDiff = await state.indexer.persistence.storage.getRollbackProgressDiff(rollbackTargetCheckpointId);
1038
+ var rollbackProgressDiff = await state.ctx.persistence.storage.getRollbackProgressDiff(rollbackTargetCheckpointId);
1039
1039
  for(var idx = 0 ,idx_finish = rollbackProgressDiff.length; idx < idx_finish; ++idx){
1040
1040
  var diff = rollbackProgressDiff[idx];
1041
1041
  var eventsProcessedDiff = Belt_Int.fromString(diff.events_processed_diff);
@@ -1078,7 +1078,7 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
1078
1078
  safeCheckpointTracking: safeCheckpointTracking !== undefined ? SafeCheckpointTracking.rollback(safeCheckpointTracking, newProgressBlockNumber) : undefined
1079
1079
  };
1080
1080
  }));
1081
- var diff$1 = await Persistence.prepareRollbackDiff(state.indexer.persistence, rollbackTargetCheckpointId, state.chainManager.committedCheckpointId + 1);
1081
+ var diff$1 = await Persistence.prepareRollbackDiff(state.ctx.persistence, rollbackTargetCheckpointId, state.chainManager.committedCheckpointId + 1);
1082
1082
  var init = state.chainManager;
1083
1083
  var chainManager_committedCheckpointId = init.committedCheckpointId;
1084
1084
  var chainManager_multichain = init.multichain;
@@ -1116,15 +1116,15 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
1116
1116
  if (safeCheckpointId === undefined) {
1117
1117
  return ;
1118
1118
  }
1119
- await state.indexer.persistence.storage.pruneStaleCheckpoints(safeCheckpointId);
1120
- for(var idx = 0 ,idx_finish = state.indexer.persistence.allEntities.length; idx < idx_finish; ++idx){
1119
+ await state.ctx.persistence.storage.pruneStaleCheckpoints(safeCheckpointId);
1120
+ for(var idx = 0 ,idx_finish = state.ctx.persistence.allEntities.length; idx < idx_finish; ++idx){
1121
1121
  if (idx !== 0) {
1122
1122
  await Utils.delay(1000);
1123
1123
  }
1124
- var entityConfig = state.indexer.persistence.allEntities[idx];
1124
+ var entityConfig = state.ctx.persistence.allEntities[idx];
1125
1125
  var timeRef = Hrtime.makeTimer();
1126
1126
  try {
1127
- await state.indexer.persistence.storage.pruneStaleEntityHistory(entityConfig.name, entityConfig.index, safeCheckpointId);
1127
+ await state.ctx.persistence.storage.pruneStaleEntityHistory(entityConfig.name, entityConfig.index, safeCheckpointId);
1128
1128
  }
1129
1129
  catch (raw_exn){
1130
1130
  var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
@@ -1158,10 +1158,10 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
1158
1158
  var writeThrottlers = state.writeThrottlers;
1159
1159
  var chainManager$1 = state.chainManager;
1160
1160
  if (task._0 === "ExitWithSuccess") {
1161
- updateChainMetadataTable(chainManager$1, state.indexer.persistence, writeThrottlers.chainMetaData);
1161
+ updateChainMetadataTable(chainManager$1, state.ctx.persistence, writeThrottlers.chainMetaData);
1162
1162
  return dispatchAction("SuccessExit");
1163
1163
  }
1164
- updateChainMetadataTable(chainManager$1, state.indexer.persistence, writeThrottlers.chainMetaData);
1164
+ updateChainMetadataTable(chainManager$1, state.ctx.persistence, writeThrottlers.chainMetaData);
1165
1165
  return ;
1166
1166
 
1167
1167
  }
@@ -0,0 +1,68 @@
1
+ open Belt
2
+ module type State = {
3
+ type t
4
+ type action
5
+ type task
6
+
7
+ let taskReducer: (t, task, ~dispatchAction: action => unit) => promise<unit>
8
+ let actionReducer: (t, action) => (t, array<task>)
9
+ let invalidatedActionReducer: (t, action) => (t, array<task>)
10
+ let getId: t => int
11
+ }
12
+
13
+ module MakeManager = (S: State) => {
14
+ type t = {mutable state: S.t, onError: exn => unit}
15
+
16
+ let make = (
17
+ state: S.t,
18
+ ~onError=e => {
19
+ e->ErrorHandling.make(~msg="Indexer has failed with an unexpected error")->ErrorHandling.log
20
+ NodeJs.process->NodeJs.exitWithCode(Failure)
21
+ },
22
+ ) => {
23
+ state,
24
+ onError,
25
+ }
26
+
27
+ let rec dispatchAction = (~stateId=0, self: t, action: S.action) => {
28
+ try {
29
+ let reducer = if stateId == self.state->S.getId {
30
+ S.actionReducer
31
+ } else {
32
+ S.invalidatedActionReducer
33
+ }
34
+ let (nextState, nextTasks) = reducer(self.state, action)
35
+ self.state = nextState
36
+ nextTasks->Array.forEach(task => dispatchTask(self, task))
37
+ } catch {
38
+ | e => e->self.onError
39
+ }
40
+ }
41
+ and dispatchTask = (self, task: S.task) => {
42
+ let stateId = self.state->S.getId
43
+ Js.Global.setTimeout(() => {
44
+ if stateId !== self.state->S.getId {
45
+ Logging.info("Invalidated task discarded")
46
+ } else {
47
+ try {
48
+ S.taskReducer(self.state, task, ~dispatchAction=action =>
49
+ dispatchAction(~stateId, self, action)
50
+ )
51
+ ->Promise.catch(e => {
52
+ e->self.onError
53
+ Promise.resolve()
54
+ })
55
+ ->ignore
56
+ } catch {
57
+ | e => e->self.onError
58
+ }
59
+ }
60
+ }, 0)->ignore
61
+ }
62
+
63
+ let getState = self => self.state
64
+ let setState = (self: t, state: S.t) => self.state = state
65
+ }
66
+
67
+ module Manager = MakeManager(GlobalState)
68
+ include Manager
@@ -0,0 +1,75 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Logging from "./Logging.res.mjs";
4
+ import * as $$Promise from "./bindings/Promise.res.mjs";
5
+ import * as Process from "process";
6
+ import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
7
+ import * as GlobalState from "./GlobalState.res.mjs";
8
+ import * as ErrorHandling from "./ErrorHandling.res.mjs";
9
+ import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
10
+
11
+ function make(state, onErrorOpt) {
12
+ var onError = onErrorOpt !== undefined ? onErrorOpt : (function (e) {
13
+ ErrorHandling.log(ErrorHandling.make(e, undefined, "Indexer has failed with an unexpected error"));
14
+ Process.exit(1);
15
+ });
16
+ return {
17
+ state: state,
18
+ onError: onError
19
+ };
20
+ }
21
+
22
+ function dispatchAction(stateIdOpt, self, action) {
23
+ var stateId = stateIdOpt !== undefined ? stateIdOpt : 0;
24
+ try {
25
+ var reducer = stateId === GlobalState.getId(self.state) ? GlobalState.actionReducer : GlobalState.invalidatedActionReducer;
26
+ var match = reducer(self.state, action);
27
+ self.state = match[0];
28
+ return Belt_Array.forEach(match[1], (function (task) {
29
+ dispatchTask(self, task);
30
+ }));
31
+ }
32
+ catch (raw_e){
33
+ var e = Caml_js_exceptions.internalToOCamlException(raw_e);
34
+ return self.onError(e);
35
+ }
36
+ }
37
+
38
+ function dispatchTask(self, task) {
39
+ var stateId = GlobalState.getId(self.state);
40
+ setTimeout((function () {
41
+ if (stateId !== GlobalState.getId(self.state)) {
42
+ return Logging.info("Invalidated task discarded");
43
+ }
44
+ try {
45
+ $$Promise.$$catch(GlobalState.taskReducer(self.state, task, (function (action) {
46
+ dispatchAction(stateId, self, action);
47
+ })), (function (e) {
48
+ self.onError(e);
49
+ return Promise.resolve();
50
+ }));
51
+ return ;
52
+ }
53
+ catch (raw_e){
54
+ var e = Caml_js_exceptions.internalToOCamlException(raw_e);
55
+ return self.onError(e);
56
+ }
57
+ }), 0);
58
+ }
59
+
60
+ function getState(self) {
61
+ return self.state;
62
+ }
63
+
64
+ function setState(self, state) {
65
+ self.state = state;
66
+ }
67
+
68
+ export {
69
+ make ,
70
+ dispatchAction ,
71
+ dispatchTask ,
72
+ getState ,
73
+ setState ,
74
+ }
75
+ /* Logging Not a pure module */
@@ -0,0 +1,7 @@
1
+ type t
2
+
3
+ let make: (GlobalState.t, ~onError: exn => unit=?) => t
4
+ let dispatchAction: (~stateId: int=?, t, GlobalState.action) => unit
5
+ let dispatchTask: (t, GlobalState.task) => unit
6
+ let getState: t => GlobalState.t
7
+ let setState: (t, GlobalState.t) => unit
package/src/Internal.res CHANGED
@@ -2,6 +2,47 @@ type eventParams
2
2
  type eventBlock
3
3
  type eventTransaction
4
4
 
5
+ // Shared EVM transaction fields type used by both RPC and HyperSync sources
6
+ // Field names match HyperSyncClient.ResponseTypes.transaction for consistency
7
+ type evmTransactionFields = {
8
+ from?: Address.t,
9
+ to?: Address.t,
10
+ gas?: bigint,
11
+ gasPrice?: bigint,
12
+ hash?: string,
13
+ input?: string,
14
+ nonce?: bigint,
15
+ transactionIndex?: int,
16
+ value?: bigint,
17
+ // Signature fields - optional for ZKSync EIP-712 compatibility
18
+ v?: string,
19
+ r?: string,
20
+ s?: string,
21
+ yParity?: string,
22
+ // EIP-1559 fields
23
+ maxPriorityFeePerGas?: bigint,
24
+ maxFeePerGas?: bigint,
25
+ // EIP-4844 blob fields
26
+ maxFeePerBlobGas?: bigint,
27
+ blobVersionedHashes?: array<string>,
28
+ // Receipt fields (from joined transaction receipts)
29
+ cumulativeGasUsed?: bigint,
30
+ effectiveGasPrice?: bigint,
31
+ gasUsed?: bigint,
32
+ contractAddress?: string,
33
+ logsBloom?: string,
34
+ @as("type")
35
+ type_?: int,
36
+ root?: string,
37
+ status?: int,
38
+ // L2 specific fields (Optimism, Arbitrum, etc.)
39
+ l1Fee?: bigint,
40
+ l1GasPrice?: bigint,
41
+ l1GasUsed?: bigint,
42
+ l1FeeScalar?: int,
43
+ gasUsedForL1?: bigint,
44
+ }
45
+
5
46
  @genType
6
47
  type genericEvent<'params, 'block, 'transaction> = {
7
48
  params: 'params,
@@ -65,7 +106,6 @@ type chains = dict<chainInfo>
65
106
  type loaderReturn
66
107
  type handlerContext = private {
67
108
  isPreload: bool,
68
- chains: chains,
69
109
  chain: chainInfo,
70
110
  }
71
111
  type handlerArgs = {
@@ -84,38 +84,44 @@ let parseEventFiltersOrThrow = {
84
84
  }
85
85
 
86
86
  let parse = (eventFilters: Js.Json.t): array<Internal.topicSelection> => {
87
- switch eventFilters {
88
- | Array([]) => [%raw(`{}`)]
89
- | Array(a) => a
90
- | _ => [eventFilters]
91
- }->Js.Array2.map(eventFilter => {
92
- switch eventFilter {
93
- | Object(eventFilter) => {
94
- let filterKeys = eventFilter->Js.Dict.keys
95
- switch filterKeys {
96
- | [] => default
97
- | _ => {
98
- filterKeys->Js.Array2.forEach(key => {
99
- if params->Js.Array2.includes(key)->not {
100
- // In TS type validation doesn't catch this
101
- // when we have eventFilters as a callback
102
- Js.Exn.raiseError(
103
- `Invalid event filters configuration. The event doesn't have an indexed parameter "${key}" and can't use it for filtering`,
104
- )
87
+ if eventFilters === Obj.magic(true) {
88
+ [default]
89
+ } else if eventFilters === Obj.magic(false) {
90
+ []
91
+ } else {
92
+ switch eventFilters {
93
+ | Array([]) => [%raw(`{}`)]
94
+ | Array(a) => a
95
+ | _ => [eventFilters]
96
+ }->Js.Array2.map(eventFilter => {
97
+ switch eventFilter {
98
+ | Object(eventFilter) => {
99
+ let filterKeys = eventFilter->Js.Dict.keys
100
+ switch filterKeys {
101
+ | [] => default
102
+ | _ => {
103
+ filterKeys->Js.Array2.forEach(key => {
104
+ if params->Js.Array2.includes(key)->not {
105
+ // In TS type validation doesn't catch this
106
+ // when we have eventFilters as a callback
107
+ Js.Exn.raiseError(
108
+ `Invalid event filters configuration. The event doesn't have an indexed parameter "${key}" and can't use it for filtering`,
109
+ )
110
+ }
111
+ })
112
+ {
113
+ Internal.topic0,
114
+ topic1: topic1(eventFilter),
115
+ topic2: topic2(eventFilter),
116
+ topic3: topic3(eventFilter),
105
117
  }
106
- })
107
- {
108
- Internal.topic0,
109
- topic1: topic1(eventFilter),
110
- topic2: topic2(eventFilter),
111
- topic3: topic3(eventFilter),
112
118
  }
113
119
  }
114
120
  }
121
+ | _ => Js.Exn.raiseError("Invalid event filters configuration. Expected an object")
115
122
  }
116
- | _ => Js.Exn.raiseError("Invalid event filters configuration. Expected an object")
117
- }
118
- })
123
+ })
124
+ }
119
125
  }
120
126
 
121
127
  let getEventFiltersOrThrow = switch eventFilters {
@@ -100,6 +100,12 @@ function parseEventFiltersOrThrow(eventFilters, sighash, params, topic1Opt, topi
100
100
  topic3: emptyTopics
101
101
  };
102
102
  var parse = function (eventFilters) {
103
+ if (eventFilters === true) {
104
+ return [$$default];
105
+ }
106
+ if (eventFilters === false) {
107
+ return [];
108
+ }
103
109
  var tmp;
104
110
  tmp = !Array.isArray(eventFilters) && (eventFilters === null || typeof eventFilters !== "object") && typeof eventFilters !== "number" && typeof eventFilters !== "string" && typeof eventFilters !== "boolean" ? [eventFilters] : (
105
111
  Array.isArray(eventFilters) ? (