envio 3.3.0-alpha.1 → 3.3.0-alpha.11

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