envio 3.3.0-alpha.1 → 3.3.0-alpha.10

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 (136) hide show
  1. package/evm.schema.json +10 -0
  2. package/index.d.ts +45 -25
  3. package/package.json +7 -7
  4. package/src/Address.res +5 -2
  5. package/src/Address.res.mjs +3 -1
  6. package/src/Api.res +1 -1
  7. package/src/Api.res.mjs +1 -1
  8. package/src/Batch.res +0 -6
  9. package/src/Batch.res.mjs +1 -12
  10. package/src/BatchProcessing.res +7 -12
  11. package/src/BatchProcessing.res.mjs +8 -7
  12. package/src/Bin.res +3 -0
  13. package/src/Bin.res.mjs +4 -0
  14. package/src/ChainFetching.res +43 -9
  15. package/src/ChainFetching.res.mjs +34 -15
  16. package/src/ChainMetadata.res +1 -11
  17. package/src/ChainMetadata.res.mjs +1 -10
  18. package/src/ChainState.res +605 -151
  19. package/src/ChainState.res.mjs +427 -104
  20. package/src/ChainState.resi +72 -4
  21. package/src/Config.res +61 -33
  22. package/src/Config.res.mjs +50 -10
  23. package/src/ContractRegisterContext.res +2 -12
  24. package/src/ContractRegisterContext.res.mjs +3 -5
  25. package/src/Core.res +14 -3
  26. package/src/CrossChainState.res +113 -89
  27. package/src/CrossChainState.res.mjs +64 -60
  28. package/src/CrossChainState.resi +1 -1
  29. package/src/Ecosystem.res +5 -6
  30. package/src/Ecosystem.res.mjs +3 -3
  31. package/src/Envio.res +17 -11
  32. package/src/EnvioGlobal.res +53 -0
  33. package/src/EnvioGlobal.res.mjs +31 -0
  34. package/src/EventConfigBuilder.res +177 -88
  35. package/src/EventConfigBuilder.res.mjs +99 -42
  36. package/src/EventProcessing.res +74 -28
  37. package/src/EventProcessing.res.mjs +55 -29
  38. package/src/ExitOnCaughtUp.res +10 -2
  39. package/src/ExitOnCaughtUp.res.mjs +10 -1
  40. package/src/FetchState.res +544 -356
  41. package/src/FetchState.res.mjs +412 -471
  42. package/src/HandlerLoader.res +8 -104
  43. package/src/HandlerLoader.res.mjs +2 -81
  44. package/src/HandlerRegister.res +518 -144
  45. package/src/HandlerRegister.res.mjs +285 -133
  46. package/src/HandlerRegister.resi +24 -8
  47. package/src/IndexerState.res +10 -3
  48. package/src/IndexerState.res.mjs +11 -4
  49. package/src/IndexerState.resi +2 -1
  50. package/src/IndexingAddresses.res +108 -0
  51. package/src/IndexingAddresses.res.mjs +101 -0
  52. package/src/IndexingAddresses.resi +34 -0
  53. package/src/Internal.res +155 -46
  54. package/src/Internal.res.mjs +30 -2
  55. package/src/LoadLayer.res +5 -5
  56. package/src/LoadLayer.res.mjs +6 -6
  57. package/src/LogSelection.res +102 -165
  58. package/src/LogSelection.res.mjs +101 -116
  59. package/src/Main.res +71 -236
  60. package/src/Main.res.mjs +60 -145
  61. package/src/Metrics.res +74 -0
  62. package/src/Metrics.res.mjs +75 -0
  63. package/src/PgStorage.res +4 -4
  64. package/src/PgStorage.res.mjs +5 -5
  65. package/src/Prometheus.res +10 -63
  66. package/src/Prometheus.res.mjs +124 -171
  67. package/src/PruneStaleHistory.res +2 -2
  68. package/src/PruneStaleHistory.res.mjs +3 -3
  69. package/src/RawEvent.res +7 -2
  70. package/src/RawEvent.res.mjs +4 -4
  71. package/src/Rollback.res +3 -3
  72. package/src/Rollback.res.mjs +4 -4
  73. package/src/RollbackCommit.res +4 -1
  74. package/src/RollbackCommit.res.mjs +3 -2
  75. package/src/SimulateDeadInputTracker.res +85 -0
  76. package/src/SimulateDeadInputTracker.res.mjs +73 -0
  77. package/src/SimulateDeadInputTracker.resi +12 -0
  78. package/src/SimulateItems.res +91 -23
  79. package/src/SimulateItems.res.mjs +55 -32
  80. package/src/TestIndexer.res +54 -40
  81. package/src/TestIndexer.res.mjs +37 -30
  82. package/src/bindings/Performance.res +7 -0
  83. package/src/bindings/Performance.res.mjs +21 -0
  84. package/src/bindings/Performance.resi +7 -0
  85. package/src/bindings/Viem.res +0 -41
  86. package/src/bindings/Viem.res.mjs +1 -43
  87. package/src/sources/BlockStore.res +46 -0
  88. package/src/sources/BlockStore.res.mjs +24 -0
  89. package/src/sources/EventRouter.res +36 -33
  90. package/src/sources/EventRouter.res.mjs +13 -14
  91. package/src/sources/Evm.res +83 -72
  92. package/src/sources/Evm.res.mjs +53 -69
  93. package/src/sources/EvmChain.res +18 -20
  94. package/src/sources/EvmChain.res.mjs +15 -15
  95. package/src/sources/EvmRpcClient.res +74 -5
  96. package/src/sources/EvmRpcClient.res.mjs +13 -4
  97. package/src/sources/FieldMask.res +39 -0
  98. package/src/sources/FieldMask.res.mjs +42 -0
  99. package/src/sources/Fuel.res +9 -6
  100. package/src/sources/Fuel.res.mjs +5 -10
  101. package/src/sources/HyperFuelSource.res +46 -50
  102. package/src/sources/HyperFuelSource.res.mjs +64 -54
  103. package/src/sources/HyperSync.res +39 -7
  104. package/src/sources/HyperSync.res.mjs +57 -37
  105. package/src/sources/HyperSync.resi +12 -2
  106. package/src/sources/HyperSyncClient.res +22 -111
  107. package/src/sources/HyperSyncClient.res.mjs +2 -30
  108. package/src/sources/HyperSyncHeightStream.res +1 -8
  109. package/src/sources/HyperSyncHeightStream.res.mjs +0 -2
  110. package/src/sources/HyperSyncSource.res +94 -107
  111. package/src/sources/HyperSyncSource.res.mjs +82 -86
  112. package/src/sources/Rpc.res +15 -47
  113. package/src/sources/Rpc.res.mjs +25 -56
  114. package/src/sources/RpcSource.res +320 -467
  115. package/src/sources/RpcSource.res.mjs +268 -385
  116. package/src/sources/RpcWebSocketHeightStream.res +0 -5
  117. package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -2
  118. package/src/sources/SimulateSource.res +10 -4
  119. package/src/sources/SimulateSource.res.mjs +16 -6
  120. package/src/sources/Source.res +34 -6
  121. package/src/sources/SourceManager.res +77 -19
  122. package/src/sources/SourceManager.res.mjs +63 -21
  123. package/src/sources/SourceManager.resi +10 -0
  124. package/src/sources/Svm.res +31 -16
  125. package/src/sources/Svm.res.mjs +36 -13
  126. package/src/sources/SvmHyperSyncClient.res +5 -32
  127. package/src/sources/SvmHyperSyncSource.res +159 -134
  128. package/src/sources/SvmHyperSyncSource.res.mjs +164 -129
  129. package/src/sources/TransactionStore.res +49 -0
  130. package/src/sources/TransactionStore.res.mjs +30 -0
  131. package/src/tui/Tui.res +13 -16
  132. package/src/tui/Tui.res.mjs +12 -14
  133. package/svm.schema.json +49 -37
  134. package/src/bindings/Hrtime.res +0 -58
  135. package/src/bindings/Hrtime.res.mjs +0 -90
  136. package/src/bindings/Hrtime.resi +0 -30
@@ -1,12 +1,11 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Utils from "../Utils.res.mjs";
4
- import * as Hrtime from "../bindings/Hrtime.res.mjs";
5
4
  import * as Source from "./Source.res.mjs";
6
5
  import * as Logging from "../Logging.res.mjs";
7
6
  import * as HyperSync from "./HyperSync.res.mjs";
8
- import * as Prometheus from "../Prometheus.res.mjs";
9
7
  import * as EventRouter from "./EventRouter.res.mjs";
8
+ import * as Performance from "../bindings/Performance.res.mjs";
10
9
  import * as LogSelection from "../LogSelection.res.mjs";
11
10
  import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
12
11
  import * as ErrorHandling from "../ErrorHandling.res.mjs";
@@ -17,34 +16,33 @@ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js
17
16
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
18
17
  import * as HyperSyncHeightStream from "./HyperSyncHeightStream.res.mjs";
19
18
 
20
- function getSelectionConfig(selection, chain) {
19
+ function getSelectionConfig(selection) {
21
20
  let capitalizedBlockFields = new Set();
22
21
  let capitalizedTransactionFields = new Set();
23
- let staticTopicSelectionsByContract = {};
24
- let dynamicEventFiltersByContract = {};
25
- let dynamicWildcardEventFiltersByContract = {};
22
+ let topicSelectionsByContract = {};
23
+ let wildcardTopicSelectionsByContract = {};
26
24
  let noAddressesTopicSelections = [];
27
25
  let contractNames = new Set();
28
- selection.eventConfigs.forEach(param => {
29
- let contractName = param.contractName;
30
- Array.from(param.selectedBlockFields).forEach(name => {
26
+ selection.onEventRegistrations.forEach(reg => {
27
+ let eventConfig = reg.eventConfig;
28
+ let contractName = eventConfig.contractName;
29
+ let resolvedWhere = reg.resolvedWhere;
30
+ Array.from(eventConfig.selectedBlockFields).forEach(name => {
31
31
  capitalizedBlockFields.add(Utils.$$String.capitalize(name));
32
32
  });
33
- Array.from(param.selectedTransactionFields).forEach(name => {
34
- capitalizedTransactionFields.add(Utils.$$String.capitalize(name));
33
+ Array.from(eventConfig.selectedTransactionFields).forEach(name => {
34
+ if (name !== "transactionIndex") {
35
+ capitalizedTransactionFields.add(Utils.$$String.capitalize(name));
36
+ return;
37
+ }
35
38
  });
36
- let eventFilters = param.getEventFiltersOrThrow(chain);
37
- if (param.dependsOnAddresses) {
39
+ if (reg.dependsOnAddresses) {
38
40
  contractNames.add(contractName);
39
- if (eventFilters.TAG === "Static") {
40
- return Utils.Dict.pushMany(staticTopicSelectionsByContract, contractName, eventFilters._0);
41
- } else {
42
- return Utils.Dict.push(param.isWildcard ? dynamicWildcardEventFiltersByContract : dynamicEventFiltersByContract, contractName, eventFilters._0);
43
- }
41
+ return Utils.Dict.pushMany(reg.isWildcard ? wildcardTopicSelectionsByContract : topicSelectionsByContract, contractName, resolvedWhere.topicSelections);
42
+ } else {
43
+ noAddressesTopicSelections.push(...LogSelection.materializeTopicSelections(resolvedWhere.topicSelections, []));
44
+ return;
44
45
  }
45
- let tmp;
46
- tmp = eventFilters.TAG === "Static" ? eventFilters._0 : eventFilters._0([]);
47
- noAddressesTopicSelections.push(...tmp);
48
46
  });
49
47
  let fieldSelection_block = Array.from(capitalizedBlockFields);
50
48
  let fieldSelection_transaction = Array.from(capitalizedTransactionFields);
@@ -76,17 +74,13 @@ function getSelectionConfig(selection, chain) {
76
74
  if (addresses.length === 0) {
77
75
  return;
78
76
  }
79
- let topicSelections = staticTopicSelectionsByContract[contractName];
77
+ let topicSelections = topicSelectionsByContract[contractName];
80
78
  if (topicSelections !== undefined) {
81
- logSelections.push(LogSelection.make(addresses, topicSelections));
82
- }
83
- let fns = dynamicEventFiltersByContract[contractName];
84
- if (fns !== undefined) {
85
- logSelections.push(LogSelection.make(addresses, fns.flatMap(fn => fn(addresses))));
79
+ logSelections.push(LogSelection.make(addresses, LogSelection.materializeTopicSelections(topicSelections, addresses)));
86
80
  }
87
- let fns$1 = dynamicWildcardEventFiltersByContract[contractName];
88
- if (fns$1 !== undefined) {
89
- logSelections.push(LogSelection.make([], fns$1.flatMap(fn => fn(addresses))));
81
+ let topicSelections$1 = wildcardTopicSelectionsByContract[contractName];
82
+ if (topicSelections$1 !== undefined) {
83
+ logSelections.push(LogSelection.make([], LogSelection.materializeTopicSelections(topicSelections$1, addresses)));
90
84
  return;
91
85
  }
92
86
  });
@@ -98,8 +92,8 @@ function getSelectionConfig(selection, chain) {
98
92
  };
99
93
  }
100
94
 
101
- function memoGetSelectionConfig(chain) {
102
- return Utils.$$WeakMap.memoize(selection => getSelectionConfig(selection, chain));
95
+ function memoGetSelectionConfig() {
96
+ return Utils.$$WeakMap.memoize(getSelectionConfig);
103
97
  }
104
98
 
105
99
  function isUnauthorizedError(message) {
@@ -112,7 +106,7 @@ function make(param) {
112
106
  let endpointUrl = param.endpointUrl;
113
107
  let chain = param.chain;
114
108
  let name = "HyperSync";
115
- let getSelectionConfig = memoGetSelectionConfig(chain);
109
+ let getSelectionConfig$1 = Utils.$$WeakMap.memoize(getSelectionConfig);
116
110
  let apiToken$1 = apiToken !== undefined ? apiToken : Stdlib_JsError.throwWithMessage(`An Envio API token is required for using HyperSync as a data-source.
117
111
  Set the ENVIO_API_TOKEN environment variable in your .env file.
118
112
  Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
@@ -124,32 +118,28 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
124
118
  client = ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate the hypersync client, please double check your ABI", exn);
125
119
  }
126
120
  let UndefinedValue = /* @__PURE__ */Primitive_exceptions.create("UndefinedValue");
127
- let makeEventBatchQueueItem = (item, params, eventConfig) => {
128
- let block = item.block;
121
+ let makeEventBatchQueueItem = (item, params, onEventRegistration) => {
129
122
  let logIndex = item.logIndex;
130
123
  return {
131
124
  kind: 0,
132
- eventConfig: eventConfig,
133
- timestamp: block.timestamp,
125
+ onEventRegistration: onEventRegistration,
134
126
  chain: chain,
135
- blockNumber: block.number,
136
- blockHash: block.hash,
127
+ blockNumber: item.blockNumber,
137
128
  logIndex: logIndex,
129
+ transactionIndex: item.transactionIndex,
138
130
  payload: {
139
- contractName: eventConfig.contractName,
140
- eventName: eventConfig.name,
131
+ contractName: onEventRegistration.eventConfig.contractName,
132
+ eventName: onEventRegistration.eventConfig.name,
141
133
  params: params,
142
134
  chainId: chain,
143
135
  srcAddress: item.srcAddress,
144
- logIndex: logIndex,
145
- transaction: item.transaction,
146
- block: block
136
+ logIndex: logIndex
147
137
  }
148
138
  };
149
139
  };
150
- let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, indexingAddresses, knownHeight, param, selection, retry, logger) => {
151
- let totalTimeRef = Hrtime.makeTimer();
152
- let selectionConfig = getSelectionConfig(selection);
140
+ let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, contractNameByAddress, knownHeight, param, selection, itemsTarget, retry, logger) => {
141
+ let totalTimeRef = Performance.now();
142
+ let selectionConfig = getSelectionConfig$1(selection);
153
143
  let logSelections;
154
144
  try {
155
145
  logSelections = selectionConfig.getLogSelectionOrThrow(addressesByContractName);
@@ -157,11 +147,10 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
157
147
  let exn = Primitive_exceptions.internalToException(raw_exn);
158
148
  logSelections = ErrorHandling.mkLogAndRaise(logger, "Failed getting log selection for the query", exn);
159
149
  }
160
- let startFetchingBatchTimeRef = Hrtime.makeTimer();
161
- Prometheus.SourceRequestCount.increment(name, chain, "getLogs");
150
+ let startFetchingBatchTimeRef = Performance.now();
162
151
  let pageUnsafe;
163
152
  try {
164
- pageUnsafe = await HyperSync.GetLogs.query(client, fromBlock, toBlock, logSelections, selectionConfig.fieldSelection);
153
+ pageUnsafe = await HyperSync.GetLogs.query(client, fromBlock, toBlock, logSelections, selectionConfig.fieldSelection, itemsTarget);
165
154
  } catch (raw_error) {
166
155
  let error = Primitive_exceptions.internalToException(raw_error);
167
156
  if (error.RE_EXN_ID === HyperSync.GetLogs.$$Error) {
@@ -209,30 +198,38 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
209
198
  Error: new Error()
210
199
  };
211
200
  }
212
- let pageFetchTime = Hrtime.toSecondsFloat(Hrtime.timeSince(startFetchingBatchTimeRef));
201
+ let pageFetchTime = Performance.secondsSince(startFetchingBatchTimeRef);
202
+ let requestStats = [{
203
+ method: "getLogs",
204
+ seconds: pageFetchTime
205
+ }];
213
206
  let knownHeight$1 = pageUnsafe.archiveHeight;
214
207
  let heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
215
- let parsingTimeRef = Hrtime.makeTimer();
208
+ let parsingTimeRef = Performance.now();
216
209
  let parsedQueueItems = [];
210
+ let blocksByNumber = new Map();
211
+ pageUnsafe.blocks.forEach(block => {
212
+ blocksByNumber.set(block.number, block);
213
+ });
217
214
  pageUnsafe.items.forEach(item => {
218
- let maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(item.topic0, item.topicCount), item.srcAddress, item.block.number, indexingAddresses);
215
+ let maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(item.topic0, item.topicCount), item.srcAddress, contractNameByAddress);
219
216
  if (maybeEventConfig === undefined) {
220
217
  return;
221
218
  }
222
- let params = Stdlib_Option.flatMap(Primitive_option.fromNullable(item.params), __x => __x[maybeEventConfig.contractName]);
219
+ let params = Stdlib_Option.flatMap(Primitive_option.fromNullable(item.params), __x => __x[maybeEventConfig.eventConfig.contractName]);
223
220
  if (params !== undefined) {
224
221
  parsedQueueItems.push(makeEventBatchQueueItem(item, Primitive_option.valFromOption(params), maybeEventConfig));
225
222
  return;
226
223
  } else {
227
224
  let logIndex = item.logIndex;
228
- let blockNumber = item.block.number;
225
+ let blockNumber = item.blockNumber;
229
226
  let exn = {
230
227
  RE_EXN_ID: UndefinedValue
231
228
  };
232
229
  if (maybeEventConfig.isWildcard) {
233
230
  return;
234
231
  }
235
- let msg = `Event ` + maybeEventConfig.name + ` was unexpectedly parsed as undefined`;
232
+ let msg = `Event ` + maybeEventConfig.eventConfig.name + ` was unexpectedly parsed as undefined`;
236
233
  let logger$1 = Logging.createChildFrom(logger, {
237
234
  chainId: chain,
238
235
  blockNumber: blockNumber,
@@ -242,19 +239,13 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
242
239
  return ErrorHandling.mkLogAndRaise(logger$1, msg, exn);
243
240
  }
244
241
  });
245
- let parsingTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(parsingTimeRef));
242
+ let parsingTimeElapsed = Performance.secondsSince(parsingTimeRef);
246
243
  let blockHashes = [];
247
- pageUnsafe.items.forEach(param => {
248
- let block = param.block;
249
- let match = block.number;
250
- let match$1 = block.hash;
251
- if (match !== undefined && match$1 !== undefined) {
252
- blockHashes.push({
253
- blockHash: match$1,
254
- blockNumber: match
255
- });
256
- return;
257
- }
244
+ pageUnsafe.blocks.forEach(block => {
245
+ blockHashes.push({
246
+ blockHash: block.hash,
247
+ blockNumber: block.number
248
+ });
258
249
  });
259
250
  let match = pageUnsafe.rollbackGuard;
260
251
  if (match !== undefined) {
@@ -272,15 +263,10 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
272
263
  if (match$1 !== undefined) {
273
264
  latestFetchedBlockTimestamp = match$1.timestamp;
274
265
  } else {
275
- let match$2 = pageUnsafe.items[pageUnsafe.items.length - 1 | 0];
276
- if (match$2 !== undefined) {
277
- let block = match$2.block;
278
- latestFetchedBlockTimestamp = block.number === heighestBlockQueried ? block.timestamp : 0;
279
- } else {
280
- latestFetchedBlockTimestamp = 0;
281
- }
266
+ let item = pageUnsafe.items[pageUnsafe.items.length - 1 | 0];
267
+ latestFetchedBlockTimestamp = item !== undefined && item.blockNumber === heighestBlockQueried ? blocksByNumber.get(item.blockNumber).timestamp : 0;
282
268
  }
283
- let totalTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(totalTimeRef));
269
+ let totalTimeElapsed = Performance.secondsSince(totalTimeRef);
284
270
  let stats_parsing$unknowntime$unknown$lpars$rpar = parsingTimeElapsed;
285
271
  let stats_page$unknownfetch$unknowntime$unknown$lpars$rpar = pageFetchTime;
286
272
  let stats = {
@@ -292,13 +278,19 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
292
278
  knownHeight: knownHeight$1,
293
279
  blockHashes: blockHashes,
294
280
  parsedQueueItems: parsedQueueItems,
281
+ transactionStore: Primitive_option.some(pageUnsafe.transactionStore),
282
+ blockStore: Primitive_option.some(pageUnsafe.blockStore),
295
283
  fromBlockQueried: fromBlock,
296
284
  latestFetchedBlockNumber: heighestBlockQueried,
297
285
  latestFetchedBlockTimestamp: latestFetchedBlockTimestamp,
298
- stats: stats
286
+ stats: stats,
287
+ requestStats: requestStats
299
288
  };
300
289
  };
301
- let getBlockHashes = (blockNumbers, logger) => HyperSync.queryBlockDataMulti(client, blockNumbers, name, chain, logger).then(HyperSync.mapExn);
290
+ let getBlockHashes = (blockNumbers, logger) => HyperSync.queryBlockDataMulti(client, blockNumbers, name, chain, logger).then(param => ({
291
+ result: HyperSync.mapExn(param[0]),
292
+ requestStats: param[1]
293
+ }));
302
294
  return {
303
295
  name: name,
304
296
  sourceFor: "Sync",
@@ -307,10 +299,10 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
307
299
  pollingInterval: 100,
308
300
  getBlockHashes: getBlockHashes,
309
301
  getHeightOrThrow: async () => {
310
- let timerRef = Hrtime.makeTimer();
311
- let result;
302
+ let timerRef = Performance.now();
303
+ let height;
312
304
  try {
313
- result = await client.getHeight();
305
+ height = await client.getHeight();
314
306
  } catch (raw_e) {
315
307
  let e = Primitive_exceptions.internalToException(raw_e);
316
308
  if (e.RE_EXN_ID === "JsExn") {
@@ -320,7 +312,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
320
312
  if (message.includes("401 Unauthorized")) {
321
313
  Logging.error(`Your ENVIO_API_TOKEN was rejected by HyperSync (401 Unauthorized). The indexer will not be able to fetch events. Update the token and try again using 'envio start' or 'envio dev'. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens`);
322
314
  await new Promise((param, param$1) => {});
323
- result = 0;
315
+ height = 0;
324
316
  } else {
325
317
  throw {
326
318
  RE_EXN_ID: "JsExn",
@@ -339,10 +331,14 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
339
331
  throw e;
340
332
  }
341
333
  }
342
- let seconds = Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef));
343
- Prometheus.SourceRequestCount.increment(name, chain, "getHeight");
344
- Prometheus.SourceRequestCount.addSeconds(name, chain, "getHeight", seconds);
345
- return result;
334
+ let seconds = Performance.secondsSince(timerRef);
335
+ return {
336
+ height: height,
337
+ requestStats: [{
338
+ method: "getHeight",
339
+ seconds: seconds
340
+ }]
341
+ };
346
342
  },
347
343
  getItemsOrThrow: getItemsOrThrow,
348
344
  createHeightSubscription: onHeight => HyperSyncHeightStream.subscribe(endpointUrl, apiToken$1, chain, onHeight)
@@ -38,7 +38,21 @@ let jsonRpcFetcher: Rest.ApiFetcher.t = async args => {
38
38
  }
39
39
  }
40
40
 
41
- let makeClient = url => Rest.client(url, ~fetcher=jsonRpcFetcher)
41
+ let makeClient = (url, ~headers=?) => {
42
+ let fetcher: Rest.ApiFetcher.t = switch headers {
43
+ | None => jsonRpcFetcher
44
+ | Some(customHeaders) =>
45
+ async args => {
46
+ let headers = switch args.headers {
47
+ | Some(headers) => headers
48
+ | None => Dict.make()
49
+ }
50
+ customHeaders->Dict.forEachWithKey((value, key) => headers->Dict.set(key, value->Obj.magic))
51
+ await jsonRpcFetcher({...args, headers: Some(headers)})
52
+ }
53
+ }
54
+ Rest.client(url, ~fetcher)
55
+ }
42
56
 
43
57
  type hex = string
44
58
  let makeHexSchema = fromStr =>
@@ -70,13 +84,7 @@ let decimalFloatSchema: S.schema<float> = S.string->S.transform(s => {
70
84
  module GetLogs = {
71
85
  @unboxed
72
86
  type topicFilter = Single(hex) | Multiple(array<hex>) | @as(null) Null
73
- let topicFilterSchema = S.union([
74
- S.literal(Null),
75
- S.schema(s => Multiple(s.matches(S.array(S.string)))),
76
- S.schema(s => Single(s.matches(S.string))),
77
- ])
78
87
  type topicQuery = array<topicFilter>
79
- let topicQuerySchema = S.array(topicFilterSchema)
80
88
 
81
89
  let makeTopicQuery = (~topic0=[], ~topic1=[], ~topic2=[], ~topic3=[]) => {
82
90
  let topics = [topic0, topic1, topic2, topic3]
@@ -106,51 +114,15 @@ module GetLogs = {
106
114
  let mapTopicQuery = ({topic0, topic1, topic2, topic3}: Internal.topicSelection): topicQuery =>
107
115
  makeTopicQuery(~topic0, ~topic1, ~topic2, ~topic3)
108
116
 
109
- type param = {
110
- fromBlock: int,
111
- toBlock: int,
112
- address?: array<Address.t>,
113
- topics: topicQuery,
114
- // blockHash?: string,
115
- }
116
-
117
- let paramsSchema = S.object((s): param => {
118
- fromBlock: s.field("fromBlock", hexIntSchema),
119
- toBlock: s.field("toBlock", hexIntSchema),
120
- address: ?s.field("address", S.option(S.array(Address.schema))),
121
- topics: s.field("topics", topicQuerySchema),
122
- // blockHash: ?s.field("blockHash", S.option(S.string)),
123
- })
124
-
125
- let fullParamsSchema = S.tuple1(paramsSchema)
126
-
127
117
  type log = {
128
118
  address: Address.t,
129
119
  topics: array<hex>,
130
- data: hex,
131
120
  blockNumber: int,
132
121
  transactionHash: hex,
133
122
  transactionIndex: int,
134
123
  blockHash: hex,
135
124
  logIndex: int,
136
- removed: bool,
137
125
  }
138
-
139
- let logSchema = S.object((s): log => {
140
- address: s.field("address", Address.schema),
141
- topics: s.field("topics", S.array(S.string)),
142
- data: s.field("data", S.string),
143
- blockNumber: s.field("blockNumber", hexIntSchema),
144
- transactionHash: s.field("transactionHash", S.string),
145
- transactionIndex: s.field("transactionIndex", hexIntSchema),
146
- blockHash: s.field("blockHash", S.string),
147
- logIndex: s.field("logIndex", hexIntSchema),
148
- removed: s.field("removed", S.bool),
149
- })
150
-
151
- let resultSchema = S.array(logSchema)
152
-
153
- let route = makeRpcRoute("eth_getLogs", fullParamsSchema, resultSchema)
154
126
  }
155
127
 
156
128
  module GetBlockByNumber = {
@@ -230,10 +202,6 @@ module GetTransactionReceipt = {
230
202
  )
231
203
  }
232
204
 
233
- let getLogs = async (~client: Rest.client, ~param: GetLogs.param) => {
234
- await GetLogs.route->Rest.fetch(param, ~client)
235
- }
236
-
237
205
  let getBlock = async (~client: Rest.client, ~blockNumber: int) => {
238
206
  await GetBlockByNumber.route->Rest.fetch(
239
207
  {"blockNumber": blockNumber, "includeTransactions": false},
@@ -4,6 +4,7 @@ import * as Rest from "../vendored/Rest.res.mjs";
4
4
  import * as Viem from "viem";
5
5
  import * as Utils from "../Utils.res.mjs";
6
6
  import * as Address from "../Address.res.mjs";
7
+ import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
7
8
  import * as Stdlib_BigInt from "@rescript/runtime/lib/es6/Stdlib_BigInt.js";
8
9
  import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
9
10
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
@@ -48,8 +49,21 @@ async function jsonRpcFetcher(args) {
48
49
  return response;
49
50
  }
50
51
 
51
- function makeClient(url) {
52
- return Rest.client(url, jsonRpcFetcher);
52
+ function makeClient(url, headers) {
53
+ let fetcher = headers !== undefined ? async args => {
54
+ let headers$1 = args.headers;
55
+ let headers$2 = headers$1 !== undefined ? headers$1 : ({});
56
+ Stdlib_Dict.forEachWithKey(headers, (value, key) => {
57
+ headers$2[key] = value;
58
+ });
59
+ return await jsonRpcFetcher({
60
+ body: args.body,
61
+ headers: headers$2,
62
+ method: args.method,
63
+ path: args.path
64
+ });
65
+ } : jsonRpcFetcher;
66
+ return Rest.client(url, fetcher);
53
67
  }
54
68
 
55
69
  function makeHexSchema(fromStr) {
@@ -81,14 +95,6 @@ let decimalFloatSchema = S$RescriptSchema.transform(S$RescriptSchema.string, s =
81
95
  }
82
96
  }));
83
97
 
84
- let topicFilterSchema = S$RescriptSchema.union([
85
- S$RescriptSchema.literal(null),
86
- S$RescriptSchema.schema(s => (s.m(S$RescriptSchema.array(S$RescriptSchema.string)))),
87
- S$RescriptSchema.schema(s => (s.m(S$RescriptSchema.string)))
88
- ]);
89
-
90
- let topicQuerySchema = S$RescriptSchema.array(topicFilterSchema);
91
-
92
98
  function makeTopicQuery(topic0Opt, topic1Opt, topic2Opt, topic3Opt) {
93
99
  let topic0 = topic0Opt !== undefined ? topic0Opt : [];
94
100
  let topic1 = topic1Opt !== undefined ? topic1Opt : [];
@@ -130,41 +136,9 @@ function mapTopicQuery(param) {
130
136
  return makeTopicQuery(param.topic0, param.topic1, param.topic2, param.topic3);
131
137
  }
132
138
 
133
- let paramsSchema = S$RescriptSchema.object(s => ({
134
- fromBlock: s.f("fromBlock", hexIntSchema),
135
- toBlock: s.f("toBlock", hexIntSchema),
136
- address: s.f("address", S$RescriptSchema.option(S$RescriptSchema.array(Address.schema))),
137
- topics: s.f("topics", topicQuerySchema)
138
- }));
139
-
140
- let fullParamsSchema = S$RescriptSchema.tuple1(paramsSchema);
141
-
142
- let logSchema = S$RescriptSchema.object(s => ({
143
- address: s.f("address", Address.schema),
144
- topics: s.f("topics", S$RescriptSchema.array(S$RescriptSchema.string)),
145
- data: s.f("data", S$RescriptSchema.string),
146
- blockNumber: s.f("blockNumber", hexIntSchema),
147
- transactionHash: s.f("transactionHash", S$RescriptSchema.string),
148
- transactionIndex: s.f("transactionIndex", hexIntSchema),
149
- blockHash: s.f("blockHash", S$RescriptSchema.string),
150
- logIndex: s.f("logIndex", hexIntSchema),
151
- removed: s.f("removed", S$RescriptSchema.bool)
152
- }));
153
-
154
- let resultSchema = S$RescriptSchema.array(logSchema);
155
-
156
- let route = makeRpcRoute("eth_getLogs", fullParamsSchema, resultSchema);
157
-
158
139
  let GetLogs = {
159
- topicFilterSchema: topicFilterSchema,
160
- topicQuerySchema: topicQuerySchema,
161
140
  makeTopicQuery: makeTopicQuery,
162
- mapTopicQuery: mapTopicQuery,
163
- paramsSchema: paramsSchema,
164
- fullParamsSchema: fullParamsSchema,
165
- logSchema: logSchema,
166
- resultSchema: resultSchema,
167
- route: route
141
+ mapTopicQuery: mapTopicQuery
168
142
  };
169
143
 
170
144
  let blockSchema = S$RescriptSchema.object(s => ({
@@ -190,22 +164,22 @@ let blockSchema = S$RescriptSchema.object(s => ({
190
164
  uncles: s.f("uncles", S$RescriptSchema.$$null(S$RescriptSchema.array(S$RescriptSchema.string)))
191
165
  }));
192
166
 
193
- let paramsSchema$1 = S$RescriptSchema.tuple(s => ({
167
+ let paramsSchema = S$RescriptSchema.tuple(s => ({
194
168
  blockNumber: s.item(0, hexIntSchema),
195
169
  includeTransactions: s.item(1, S$RescriptSchema.bool)
196
170
  }));
197
171
 
198
- let resultSchema$1 = S$RescriptSchema.$$null(blockSchema);
172
+ let resultSchema = S$RescriptSchema.$$null(blockSchema);
199
173
 
200
- let route$1 = makeRpcRoute("eth_getBlockByNumber", paramsSchema$1, resultSchema$1);
174
+ let route = makeRpcRoute("eth_getBlockByNumber", paramsSchema, resultSchema);
201
175
 
202
- let rawRoute = makeRpcRoute("eth_getBlockByNumber", paramsSchema$1, S$RescriptSchema.$$null(S$RescriptSchema.json(false)));
176
+ let rawRoute = makeRpcRoute("eth_getBlockByNumber", paramsSchema, S$RescriptSchema.$$null(S$RescriptSchema.json(false)));
203
177
 
204
178
  let GetBlockByNumber = {
205
179
  blockSchema: blockSchema,
206
- paramsSchema: paramsSchema$1,
207
- resultSchema: resultSchema$1,
208
- route: route$1,
180
+ paramsSchema: paramsSchema,
181
+ resultSchema: resultSchema,
182
+ route: route,
209
183
  rawRoute: rawRoute
210
184
  };
211
185
 
@@ -221,12 +195,8 @@ let GetTransactionReceipt = {
221
195
  rawRoute: rawRoute$2
222
196
  };
223
197
 
224
- async function getLogs(client, param) {
225
- return await Rest.fetch(route, param, client);
226
- }
227
-
228
198
  async function getBlock(client, blockNumber) {
229
- return await Rest.fetch(route$1, {
199
+ return await Rest.fetch(route, {
230
200
  blockNumber: blockNumber,
231
201
  includeTransactions: false
232
202
  }, client);
@@ -252,7 +222,6 @@ export {
252
222
  GetBlockByNumber,
253
223
  GetTransactionByHash,
254
224
  GetTransactionReceipt,
255
- getLogs,
256
225
  getBlock,
257
226
  getRawBlock,
258
227
  }