envio 3.0.2 → 3.1.0-rc.1

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 (101) hide show
  1. package/README.md +0 -1
  2. package/evm.schema.json +15 -8
  3. package/fuel.schema.json +19 -12
  4. package/index.d.ts +0 -2
  5. package/package.json +6 -7
  6. package/rescript.json +1 -1
  7. package/src/Batch.res +4 -214
  8. package/src/Batch.res.mjs +6 -165
  9. package/src/ChainFetcher.res +12 -28
  10. package/src/ChainFetcher.res.mjs +8 -17
  11. package/src/ChainManager.res +10 -9
  12. package/src/ChainManager.res.mjs +6 -10
  13. package/src/Config.res +9 -25
  14. package/src/Config.res.mjs +17 -27
  15. package/src/Core.res +7 -0
  16. package/src/Ctx.res +1 -0
  17. package/src/Env.res +0 -8
  18. package/src/Env.res.mjs +0 -6
  19. package/src/EventConfigBuilder.res +13 -123
  20. package/src/EventConfigBuilder.res.mjs +6 -73
  21. package/src/EventProcessing.res +5 -29
  22. package/src/EventProcessing.res.mjs +11 -20
  23. package/src/EventUtils.res +0 -27
  24. package/src/EventUtils.res.mjs +0 -24
  25. package/src/FetchState.res +2 -15
  26. package/src/FetchState.res.mjs +3 -18
  27. package/src/GlobalState.res +26 -39
  28. package/src/GlobalState.res.mjs +12 -40
  29. package/src/HandlerLoader.res +6 -5
  30. package/src/HandlerLoader.res.mjs +27 -9
  31. package/src/HandlerRegister.res +1 -12
  32. package/src/HandlerRegister.res.mjs +1 -6
  33. package/src/HandlerRegister.resi +1 -1
  34. package/src/Hasura.res +96 -32
  35. package/src/Hasura.res.mjs +93 -38
  36. package/src/InMemoryStore.res +205 -45
  37. package/src/InMemoryStore.res.mjs +157 -40
  38. package/src/InMemoryTable.res +165 -249
  39. package/src/InMemoryTable.res.mjs +156 -227
  40. package/src/Internal.res +10 -34
  41. package/src/Internal.res.mjs +9 -3
  42. package/src/LoadLayer.res +5 -5
  43. package/src/LoadLayer.res.mjs +5 -5
  44. package/src/LogSelection.res +15 -19
  45. package/src/LogSelection.res.mjs +5 -6
  46. package/src/Main.res +4 -6
  47. package/src/Main.res.mjs +26 -15
  48. package/src/Persistence.res +7 -132
  49. package/src/Persistence.res.mjs +1 -102
  50. package/src/PgStorage.res +57 -40
  51. package/src/PgStorage.res.mjs +60 -34
  52. package/src/ReorgDetection.res +35 -58
  53. package/src/ReorgDetection.res.mjs +21 -29
  54. package/src/SimulateItems.res.mjs +21 -3
  55. package/src/Sink.res +2 -2
  56. package/src/Sink.res.mjs +1 -1
  57. package/src/TableIndices.res +9 -2
  58. package/src/TableIndices.res.mjs +7 -1
  59. package/src/TestIndexer.res +53 -60
  60. package/src/TestIndexer.res.mjs +77 -63
  61. package/src/TestIndexerProxyStorage.res +4 -14
  62. package/src/TestIndexerProxyStorage.res.mjs +1 -5
  63. package/src/UserContext.res +2 -4
  64. package/src/UserContext.res.mjs +4 -5
  65. package/src/Utils.res +0 -2
  66. package/src/Utils.res.mjs +0 -3
  67. package/src/bindings/ClickHouse.res +45 -38
  68. package/src/bindings/ClickHouse.res.mjs +16 -17
  69. package/src/bindings/Vitest.res +3 -0
  70. package/src/db/InternalTable.res +59 -18
  71. package/src/db/InternalTable.res.mjs +82 -51
  72. package/src/db/Table.res +9 -2
  73. package/src/db/Table.res.mjs +10 -7
  74. package/src/sources/EnvioApiClient.res +15 -0
  75. package/src/sources/EnvioApiClient.res.mjs +24 -0
  76. package/src/sources/EvmChain.res +32 -10
  77. package/src/sources/EvmChain.res.mjs +31 -5
  78. package/src/sources/HyperFuelSource.res +15 -58
  79. package/src/sources/HyperFuelSource.res.mjs +20 -39
  80. package/src/sources/HyperSync.res +54 -100
  81. package/src/sources/HyperSync.res.mjs +67 -96
  82. package/src/sources/HyperSync.resi +4 -22
  83. package/src/sources/HyperSyncClient.res +70 -247
  84. package/src/sources/HyperSyncClient.res.mjs +47 -46
  85. package/src/sources/HyperSyncSource.res +94 -166
  86. package/src/sources/HyperSyncSource.res.mjs +100 -127
  87. package/src/sources/RpcSource.res +43 -22
  88. package/src/sources/RpcSource.res.mjs +50 -35
  89. package/src/sources/SimulateSource.res +1 -7
  90. package/src/sources/SimulateSource.res.mjs +1 -7
  91. package/src/sources/Source.res +10 -1
  92. package/src/sources/Source.res.mjs +3 -0
  93. package/src/sources/SourceManager.res +177 -8
  94. package/src/sources/SourceManager.res.mjs +141 -3
  95. package/src/sources/SourceManager.resi +19 -0
  96. package/src/tui/Tui.res +44 -6
  97. package/src/tui/Tui.res.mjs +56 -8
  98. package/src/tui/components/TuiData.res +3 -0
  99. package/svm.schema.json +11 -4
  100. package/src/sources/HyperSyncJsonApi.res +0 -390
  101. package/src/sources/HyperSyncJsonApi.res.mjs +0 -237
@@ -1,24 +1,14 @@
1
- // Types moved to `Internal` so `Internal.evmEventConfig` can retain
2
- // `indexedParams: array<eventParam>` for post-registration filter rebuild.
3
- // Re-exported here as aliases for existing call sites.
4
- type eventParamComponent = Internal.eventParamComponent
5
- type eventParam = Internal.eventParam
6
-
7
- let eventParamComponentSchema = S.recursive(self =>
8
- S.object((s): eventParamComponent => {
1
+ type paramMeta = Internal.paramMeta
2
+
3
+ let paramMetaSchema = S.recursive(self =>
4
+ S.object((s): paramMeta => {
9
5
  name: s.field("name", S.string),
10
6
  abiType: s.field("abiType", S.string),
7
+ indexed: s.fieldOr("indexed", S.bool, false),
11
8
  components: ?s.field("components", S.option(S.array(self))),
12
9
  })
13
10
  )
14
11
 
15
- let eventParamSchema = S.object((s): eventParam => {
16
- name: s.field("name", S.string),
17
- abiType: s.field("abiType", S.string),
18
- indexed: s.fieldOr("indexed", S.bool, false),
19
- components: ?s.field("components", S.option(S.array(eventParamComponentSchema))),
20
- })
21
-
22
12
  // Normalize a value that could be a single item or an array into an array
23
13
  let normalizeOrThrow: 'a => array<'a> = value => {
24
14
  if Array.isArray(value->Obj.magic) {
@@ -151,7 +141,7 @@ let rec abiTypeToDefaultValue = (abiType: string): unknown => {
151
141
  let rec componentsToObjectSchema = (
152
142
  ~leafSchema: string => S.t<unknown>,
153
143
  abiType: string,
154
- components: array<eventParamComponent>,
144
+ components: array<paramMeta>,
155
145
  ): S.t<unknown> => {
156
146
  if abiType->String.endsWith("]") {
157
147
  let bracketIdx = abiType->String.lastIndexOf("[")
@@ -174,10 +164,7 @@ let rec componentsToObjectSchema = (
174
164
 
175
165
  // Default simulate value for a component tree — mirrors `abiTypeToDefaultValue`
176
166
  // but emits objects with named fields for tuples.
177
- let rec componentsToDefaultValue = (
178
- abiType: string,
179
- components: array<eventParamComponent>,
180
- ): unknown => {
167
+ let rec componentsToDefaultValue = (abiType: string, components: array<paramMeta>): unknown => {
181
168
  if abiType->String.endsWith("]") {
182
169
  []->(Utils.magic: array<unknown> => unknown)
183
170
  } else {
@@ -193,41 +180,9 @@ let rec componentsToDefaultValue = (
193
180
  }
194
181
  }
195
182
 
196
- // Build a post-processor that converts the raw positional tuple values
197
- // produced by the HyperSync decoder into objects with named fields. Walks
198
- // through array wrappers so `struct[]` becomes `array<{...}>`. Returns `None`
199
- // for leaf params where no remapping is needed.
200
- let rec componentsToRemapper = (
201
- abiType: string,
202
- components: array<eventParamComponent>,
203
- value: unknown,
204
- ): unknown => {
205
- if abiType->String.endsWith("]") {
206
- let bracketIdx = abiType->String.lastIndexOf("[")
207
- let baseType = abiType->String.slice(~start=0, ~end=bracketIdx)
208
- let arr = value->(Utils.magic: unknown => array<unknown>)
209
- arr
210
- ->Array.map(item => componentsToRemapper(baseType, components, item))
211
- ->(Utils.magic: array<unknown> => unknown)
212
- } else {
213
- // Must be a tuple at this level: build an object keyed by component names.
214
- let arr = value->(Utils.magic: unknown => array<unknown>)
215
- let dict = Dict.make()
216
- components->Array.forEachWithIndex((c, i) => {
217
- let raw = arr->Array.getUnsafe(i)
218
- let mapped = switch c.components {
219
- | Some(sub) => componentsToRemapper(c.abiType, sub, raw)
220
- | None => raw
221
- }
222
- dict->Dict.set(c.name, mapped)
223
- })
224
- dict->(Utils.magic: dict<unknown> => unknown)
225
- }
226
- }
227
-
228
183
  // ============== Build paramsRawEventSchema ==============
229
184
 
230
- let buildParamsSchema = (params: array<eventParam>): S.t<Internal.eventParams> => {
185
+ let buildParamsSchema = (params: array<paramMeta>): S.t<Internal.eventParams> => {
231
186
  if params->Array.length == 0 {
232
187
  S.literal(%raw(`null`))
233
188
  ->S.shape(_ => ())
@@ -256,7 +211,7 @@ let buildParamsSchema = (params: array<eventParam>): S.t<Internal.eventParams> =
256
211
  // Uses S.schema + s.matches with S.null->S.Option.getOr to fill missing fields with defaults.
257
212
  // When a param carries component metadata (Solidity struct), we accept and emit a
258
213
  // record with named fields rather than a positional tuple.
259
- let buildSimulateParamsSchema = (params: array<eventParam>): S.t<Internal.eventParams> => {
214
+ let buildSimulateParamsSchema = (params: array<paramMeta>): S.t<Internal.eventParams> => {
260
215
  if params->Array.length == 0 {
261
216
  S.unknown
262
217
  ->S.shape(_ => ())
@@ -279,71 +234,6 @@ let buildSimulateParamsSchema = (params: array<eventParam>): S.t<Internal.eventP
279
234
  }
280
235
  }
281
236
 
282
- // ============== Build HyperSync decoder via new Function() ==============
283
-
284
- // Param names from ABI are valid Solidity identifiers ([a-zA-Z_$][a-zA-Z0-9_$]*),
285
- // so they're safe to use in quoted property names within new Function() body.
286
- @new @variadic
287
- external makeFunction: array<string> => 'a = "Function"
288
-
289
- let buildHyperSyncDecoder = (params: array<eventParam>): (
290
- HyperSyncClient.Decoder.decodedEvent => Internal.eventParams
291
- ) => {
292
- if params->Array.length == 0 {
293
- _ => ()->(Utils.magic: unit => Internal.eventParams)
294
- } else {
295
- let indexedParams = params->Array.filter(p => p.indexed)
296
- let bodyParams = params->Array.filter(p => !p.indexed)
297
-
298
- let fields = []
299
- indexedParams->Array.forEachWithIndex((p, i) => {
300
- fields->Array.push(`"${p.name}": t(d.indexed[${i->Int.toString}])`)->ignore
301
- })
302
- bodyParams->Array.forEachWithIndex((p, i) => {
303
- fields->Array.push(`"${p.name}": t(d.body[${i->Int.toString}])`)->ignore
304
- })
305
- // Generate: function(t) { return function(d) { return { ... } } }
306
- let body = `return function(d) { return {${fields->Array.joinUnsafe(", ")}} }`
307
-
308
- let factory: (
309
- HyperSyncClient.Decoder.decodedRaw => HyperSyncClient.Decoder.decodedUnderlying
310
- ) => HyperSyncClient.Decoder.decodedEvent => Internal.eventParams =
311
- makeFunction(["t", body])->(
312
- Utils.magic: 'a => (
313
- HyperSyncClient.Decoder.decodedRaw => HyperSyncClient.Decoder.decodedUnderlying
314
- ) => HyperSyncClient.Decoder.decodedEvent => Internal.eventParams
315
- )
316
-
317
- let baseDecode = factory(HyperSyncClient.Decoder.toUnderlying)
318
-
319
- // For any param that has tuple component metadata, rewrite its value from a
320
- // positional array into a named record post-decode. We pre-collect the
321
- // params that need remapping so the hot path only walks those. Indexed
322
- // struct/tuple params arrive as keccak256 topic hashes (single hex strings)
323
- // rather than positional arrays, so they must be skipped here — running
324
- // componentsToRemapper on a hash would treat the hex string as an array
325
- // and read garbage.
326
- let paramsToRemap = params->Array.filter(p => !p.indexed && p.components->Option.isSome)
327
-
328
- if paramsToRemap->Array.length == 0 {
329
- baseDecode
330
- } else {
331
- decoded => {
332
- let result = baseDecode(decoded)
333
- let dict = result->(Utils.magic: Internal.eventParams => dict<unknown>)
334
- paramsToRemap->Array.forEach(p => {
335
- switch (p.components, dict->Dict.get(p.name)) {
336
- | (Some(components), Some(raw)) =>
337
- dict->Dict.set(p.name, componentsToRemapper(p.abiType, components, raw))
338
- | _ => ()
339
- }
340
- })
341
- dict->(Utils.magic: dict<unknown> => Internal.eventParams)
342
- }
343
- }
344
- }
345
- }
346
-
347
237
  // ============== Build topic filter getters ==============
348
238
 
349
239
  let getTopicEncoder = (abiType: string): (unknown => EvmTypes.Hex.t) => {
@@ -386,7 +276,7 @@ let getTopicEncoder = (abiType: string): (unknown => EvmTypes.Hex.t) => {
386
276
  }
387
277
  }
388
278
 
389
- let buildTopicGetter = (p: eventParam) => {
279
+ let buildTopicGetter = (p: paramMeta) => {
390
280
  let encoder = getTopicEncoder(p.abiType)
391
281
  (eventFilter: dict<JSON.t>) =>
392
282
  eventFilter
@@ -425,7 +315,7 @@ let buildEvmEventConfig = (
425
315
  ~contractName: string,
426
316
  ~eventName: string,
427
317
  ~sighash: string,
428
- ~params: array<eventParam>,
318
+ ~params: array<paramMeta>,
429
319
  ~isWildcard: bool,
430
320
  ~handler: option<Internal.handler>,
431
321
  ~contractRegister: option<Internal.contractRegister>,
@@ -486,11 +376,11 @@ let buildEvmEventConfig = (
486
376
  filterByAddresses,
487
377
  dependsOnAddresses: !isWildcard || filterByAddresses,
488
378
  startBlock: resolvedStartBlock,
489
- convertHyperSyncEventArgs: buildHyperSyncDecoder(params),
490
379
  selectedBlockFields,
491
380
  selectedTransactionFields,
492
381
  sighash,
493
- indexedParams,
382
+ topicCount,
383
+ paramsMetadata: params,
494
384
  }
495
385
  }
496
386
 
@@ -9,23 +9,16 @@ import * as LogSelection from "./LogSelection.res.mjs";
9
9
  import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
10
10
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
11
11
  import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
12
- import * as HyperSyncClient from "./sources/HyperSyncClient.res.mjs";
13
12
  import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
14
13
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
15
14
 
16
- let eventParamComponentSchema = S$RescriptSchema.recursive(self => S$RescriptSchema.object(s => ({
15
+ let paramMetaSchema = S$RescriptSchema.recursive(self => S$RescriptSchema.object(s => ({
17
16
  name: s.f("name", S$RescriptSchema.string),
18
17
  abiType: s.f("abiType", S$RescriptSchema.string),
18
+ indexed: s.fieldOr("indexed", S$RescriptSchema.bool, false),
19
19
  components: s.f("components", S$RescriptSchema.option(S$RescriptSchema.array(self)))
20
20
  })));
21
21
 
22
- let eventParamSchema = S$RescriptSchema.object(s => ({
23
- name: s.f("name", S$RescriptSchema.string),
24
- abiType: s.f("abiType", S$RescriptSchema.string),
25
- indexed: s.fieldOr("indexed", S$RescriptSchema.bool, false),
26
- components: s.f("components", S$RescriptSchema.option(S$RescriptSchema.array(eventParamComponentSchema)))
27
- }));
28
-
29
22
  function normalizeOrThrow(value) {
30
23
  if (Array.isArray(value)) {
31
24
  return value;
@@ -174,22 +167,6 @@ function componentsToDefaultValue(abiType, components) {
174
167
  return dict;
175
168
  }
176
169
 
177
- function componentsToRemapper(abiType, components, value) {
178
- if (abiType.endsWith("]")) {
179
- let bracketIdx = abiType.lastIndexOf("[");
180
- let baseType = abiType.slice(0, bracketIdx);
181
- return value.map(item => componentsToRemapper(baseType, components, item));
182
- }
183
- let dict = {};
184
- components.forEach((c, i) => {
185
- let raw = value[i];
186
- let sub = c.components;
187
- let mapped = sub !== undefined ? componentsToRemapper(c.abiType, sub, raw) : raw;
188
- dict[c.name] = mapped;
189
- });
190
- return dict;
191
- }
192
-
193
170
  function buildParamsSchema(params) {
194
171
  if (params.length === 0) {
195
172
  return S$RescriptSchema.shape(S$RescriptSchema.literal(null), param => {});
@@ -228,47 +205,6 @@ function buildSimulateParamsSchema(params) {
228
205
  }
229
206
  }
230
207
 
231
- function buildHyperSyncDecoder(params) {
232
- if (params.length === 0) {
233
- return param => {};
234
- }
235
- let indexedParams = params.filter(p => p.indexed);
236
- let bodyParams = params.filter(p => !p.indexed);
237
- let fields = [];
238
- indexedParams.forEach((p, i) => {
239
- fields.push(`"` + p.name + `": t(d.indexed[` + i.toString() + `])`);
240
- });
241
- bodyParams.forEach((p, i) => {
242
- fields.push(`"` + p.name + `": t(d.body[` + i.toString() + `])`);
243
- });
244
- let body = `return function(d) { return {` + fields.join(", ") + `} }`;
245
- let factory = new Function("t", body);
246
- let baseDecode = factory(HyperSyncClient.Decoder.toUnderlying);
247
- let paramsToRemap = params.filter(p => {
248
- if (p.indexed) {
249
- return false;
250
- } else {
251
- return Stdlib_Option.isSome(p.components);
252
- }
253
- });
254
- if (paramsToRemap.length === 0) {
255
- return baseDecode;
256
- } else {
257
- return decoded => {
258
- let result = baseDecode(decoded);
259
- paramsToRemap.forEach(p => {
260
- let match = p.components;
261
- let match$1 = result[p.name];
262
- if (match !== undefined && match$1 !== undefined) {
263
- result[p.name] = componentsToRemapper(p.abiType, match, Primitive_option.valFromOption(match$1));
264
- return;
265
- }
266
- });
267
- return result;
268
- };
269
- }
270
- }
271
-
272
208
  function getTopicEncoder(abiType) {
273
209
  if (abiType.endsWith("]") || abiType.startsWith("(")) {
274
210
  return TopicFilter.castToHexUnsafe;
@@ -344,11 +280,11 @@ function buildEvmEventConfig(contractName, eventName, sighash, params, isWildcar
344
280
  simulateParamsSchema: buildSimulateParamsSchema(params),
345
281
  startBlock: resolvedStartBlock,
346
282
  getEventFiltersOrThrow: match.getEventFiltersOrThrow,
347
- convertHyperSyncEventArgs: buildHyperSyncDecoder(params),
348
283
  selectedBlockFields: match$1[0],
349
284
  selectedTransactionFields: match$1[1],
350
285
  sighash: sighash,
351
- indexedParams: indexedParams
286
+ topicCount: topicCount,
287
+ paramsMetadata: params
352
288
  };
353
289
  }
354
290
 
@@ -412,8 +348,7 @@ function buildFuelEventConfig(contractName, eventName, kind, sighash, rawAbi, is
412
348
  }
413
349
 
414
350
  export {
415
- eventParamComponentSchema,
416
- eventParamSchema,
351
+ paramMetaSchema,
417
352
  normalizeOrThrow,
418
353
  splitTupleComponents,
419
354
  abiTypeToSchema,
@@ -421,10 +356,8 @@ export {
421
356
  abiTypeToDefaultValue,
422
357
  componentsToObjectSchema,
423
358
  componentsToDefaultValue,
424
- componentsToRemapper,
425
359
  buildParamsSchema,
426
360
  buildSimulateParamsSchema,
427
- buildHyperSyncDecoder,
428
361
  getTopicEncoder,
429
362
  buildTopicGetter,
430
363
  alwaysIncludedBlockFields,
@@ -432,4 +365,4 @@ export {
432
365
  buildEvmEventConfig,
433
366
  buildFuelEventConfig,
434
367
  }
435
- /* eventParamComponentSchema Not a pure module */
368
+ /* paramMetaSchema Not a pure module */
@@ -93,9 +93,7 @@ let addItemToRawEvents = (
93
93
  params,
94
94
  }
95
95
 
96
- let eventIdStr = eventId->BigInt.toString
97
-
98
- inMemoryStore.rawEvents->InMemoryTable.set({chainId, eventId: eventIdStr}, rawEvent)
96
+ inMemoryStore.rawEvents->Array.push(rawEvent)
99
97
  }
100
98
 
101
99
  exception ProcessingError({message: string, exn: exn, item: Internal.item})
@@ -107,7 +105,6 @@ let runEventHandlerOrThrow = async (
107
105
  ~inMemoryStore,
108
106
  ~loadManager,
109
107
  ~persistence,
110
- ~shouldSaveHistory,
111
108
  ~chains: Internal.chains,
112
109
  ~config: Config.t,
113
110
  ) => {
@@ -123,7 +120,6 @@ let runEventHandlerOrThrow = async (
123
120
  inMemoryStore,
124
121
  loadManager,
125
122
  persistence,
126
- shouldSaveHistory,
127
123
  isPreload: false,
128
124
  chains,
129
125
  config,
@@ -162,7 +158,6 @@ let runHandlerOrThrow = async (
162
158
  ~inMemoryStore,
163
159
  ~loadManager,
164
160
  ~ctx: Ctx.t,
165
- ~shouldSaveHistory,
166
161
  ~chains: Internal.chains,
167
162
  ) => {
168
163
  switch item {
@@ -173,7 +168,6 @@ let runHandlerOrThrow = async (
173
168
  inMemoryStore,
174
169
  loadManager,
175
170
  persistence: ctx.persistence,
176
- shouldSaveHistory,
177
171
  checkpointId,
178
172
  isPreload: false,
179
173
  chains,
@@ -207,7 +201,6 @@ let runHandlerOrThrow = async (
207
201
  ~inMemoryStore,
208
202
  ~loadManager,
209
203
  ~persistence=ctx.persistence,
210
- ~shouldSaveHistory,
211
204
  ~chains,
212
205
  ~config=ctx.config,
213
206
  )
@@ -265,7 +258,6 @@ let preloadBatchOrThrow = async (
265
258
  persistence,
266
259
  checkpointId,
267
260
  isPreload: true,
268
- shouldSaveHistory: false,
269
261
  chains,
270
262
  isResolved: false,
271
263
  config,
@@ -300,7 +292,6 @@ let preloadBatchOrThrow = async (
300
292
  persistence,
301
293
  checkpointId,
302
294
  isPreload: true,
303
- shouldSaveHistory: false,
304
295
  chains,
305
296
  isResolved: false,
306
297
  config,
@@ -325,7 +316,6 @@ let runBatchHandlersOrThrow = async (
325
316
  ~inMemoryStore,
326
317
  ~loadManager,
327
318
  ~ctx,
328
- ~shouldSaveHistory,
329
319
  ~chains: Internal.chains,
330
320
  ) => {
331
321
  let itemIdx = ref(0)
@@ -337,15 +327,7 @@ let runBatchHandlersOrThrow = async (
337
327
  for idx in 0 to checkpointEventsProcessed - 1 {
338
328
  let item = batch.items->Array.getUnsafe(itemIdx.contents + idx)
339
329
 
340
- await runHandlerOrThrow(
341
- item,
342
- ~checkpointId,
343
- ~inMemoryStore,
344
- ~loadManager,
345
- ~ctx,
346
- ~shouldSaveHistory,
347
- ~chains,
348
- )
330
+ await runHandlerOrThrow(item, ~checkpointId, ~inMemoryStore, ~loadManager, ~ctx, ~chains)
349
331
  }
350
332
  itemIdx := itemIdx.contents + checkpointEventsProcessed
351
333
  }
@@ -414,22 +396,16 @@ let processEventBatch = async (
414
396
  let elapsedTimeAfterLoaders = timeRef->Hrtime.timeSince->Hrtime.toSecondsFloat
415
397
 
416
398
  if batch.items->Utils.Array.notEmpty {
417
- await batch->runBatchHandlersOrThrow(
418
- ~inMemoryStore,
419
- ~loadManager,
420
- ~ctx,
421
- ~shouldSaveHistory=ctx.config->Config.shouldSaveHistory(~isInReorgThreshold),
422
- ~chains,
423
- )
399
+ await batch->runBatchHandlersOrThrow(~inMemoryStore, ~loadManager, ~ctx, ~chains)
424
400
  }
425
401
 
426
402
  let elapsedTimeAfterProcessing = timeRef->Hrtime.timeSince->Hrtime.toSecondsFloat
427
403
 
428
404
  try {
429
- await ctx.persistence->Persistence.writeBatch(
405
+ await inMemoryStore->InMemoryStore.writeBatch(
406
+ ~persistence=ctx.persistence,
430
407
  ~batch,
431
408
  ~config=ctx.config,
432
- ~inMemoryStore,
433
409
  ~isInReorgThreshold,
434
410
  )
435
411
 
@@ -1,7 +1,6 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Utils from "./Utils.res.mjs";
4
- import * as Config from "./Config.res.mjs";
5
4
  import * as Hrtime from "./bindings/Hrtime.res.mjs";
6
5
  import * as Logging from "./Logging.res.mjs";
7
6
  import * as ChainMap from "./ChainMap.res.mjs";
@@ -12,7 +11,7 @@ import * as Persistence from "./Persistence.res.mjs";
12
11
  import * as UserContext from "./UserContext.res.mjs";
13
12
  import * as ChainFetcher from "./ChainFetcher.res.mjs";
14
13
  import * as ErrorHandling from "./ErrorHandling.res.mjs";
15
- import * as InMemoryTable from "./InMemoryTable.res.mjs";
14
+ import * as InMemoryStore from "./InMemoryStore.res.mjs";
16
15
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
17
16
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
18
17
 
@@ -51,7 +50,6 @@ function addItemToRawEvents(eventItem, inMemoryStore, config) {
51
50
  let block = event.block;
52
51
  let logIndex = event.logIndex;
53
52
  let blockNumber = eventItem.blockNumber;
54
- let chain = eventItem.chain;
55
53
  let eventConfig = eventItem.eventConfig;
56
54
  let eventId = EventUtils.packEventIndex(blockNumber, logIndex);
57
55
  let blockFields = convertFieldsToJson(block);
@@ -59,13 +57,14 @@ function addItemToRawEvents(eventItem, inMemoryStore, config) {
59
57
  config.ecosystem.cleanUpRawEventFieldsInPlace(blockFields);
60
58
  let params = S$RescriptSchema.reverseConvertOrThrow(event.params, eventConfig.paramsRawEventSchema);
61
59
  let params$1 = params === null ? "null" : params;
60
+ let rawEvent_chain_id = eventItem.chain;
62
61
  let rawEvent_event_name = eventConfig.name;
63
62
  let rawEvent_contract_name = eventConfig.contractName;
64
63
  let rawEvent_src_address = event.srcAddress;
65
64
  let rawEvent_block_hash = config.ecosystem.getId(block);
66
65
  let rawEvent_block_timestamp = eventItem.timestamp;
67
66
  let rawEvent = {
68
- chain_id: chain,
67
+ chain_id: rawEvent_chain_id,
69
68
  event_id: eventId,
70
69
  event_name: rawEvent_event_name,
71
70
  contract_name: rawEvent_contract_name,
@@ -78,16 +77,12 @@ function addItemToRawEvents(eventItem, inMemoryStore, config) {
78
77
  transaction_fields: transactionFields,
79
78
  params: params$1
80
79
  };
81
- let eventIdStr = eventId.toString();
82
- InMemoryTable.set(inMemoryStore.rawEvents, {
83
- chainId: chain,
84
- eventId: eventIdStr
85
- }, rawEvent);
80
+ inMemoryStore.rawEvents.push(rawEvent);
86
81
  }
87
82
 
88
83
  let ProcessingError = /* @__PURE__ */Primitive_exceptions.create("EventProcessing.ProcessingError");
89
84
 
90
- async function runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore, loadManager, persistence, shouldSaveHistory, chains, config) {
85
+ async function runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore, loadManager, persistence, chains, config) {
91
86
  let timeBeforeHandler = Hrtime.makeTimer();
92
87
  try {
93
88
  let contextParams = {
@@ -97,7 +92,6 @@ async function runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore
97
92
  loadManager: loadManager,
98
93
  persistence: persistence,
99
94
  isPreload: false,
100
- shouldSaveHistory: shouldSaveHistory,
101
95
  chains: chains,
102
96
  config: config,
103
97
  isResolved: false
@@ -121,11 +115,11 @@ async function runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore
121
115
  return Prometheus.ProcessingHandler.increment(item.eventConfig.contractName, item.eventConfig.name, handlerDuration);
122
116
  }
123
117
 
124
- async function runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager, ctx, shouldSaveHistory, chains) {
118
+ async function runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager, ctx, chains) {
125
119
  if (item.kind === 0) {
126
120
  let handler = item.eventConfig.handler;
127
121
  if (handler !== undefined) {
128
- await runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore, loadManager, ctx.persistence, shouldSaveHistory, chains, ctx.config);
122
+ await runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore, loadManager, ctx.persistence, chains, ctx.config);
129
123
  }
130
124
  if (ctx.config.enableRawEvents) {
131
125
  return addItemToRawEvents(item, inMemoryStore, ctx.config);
@@ -141,7 +135,6 @@ async function runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager,
141
135
  loadManager: loadManager,
142
136
  persistence: ctx.persistence,
143
137
  isPreload: false,
144
- shouldSaveHistory: shouldSaveHistory,
145
138
  chains: chains,
146
139
  config: ctx.config,
147
140
  isResolved: false
@@ -186,7 +179,6 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inMe
186
179
  loadManager: loadManager,
187
180
  persistence: persistence,
188
181
  isPreload: true,
189
- shouldSaveHistory: false,
190
182
  chains: chains,
191
183
  config: config,
192
184
  isResolved: false
@@ -205,7 +197,6 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inMe
205
197
  loadManager: loadManager,
206
198
  persistence: persistence,
207
199
  isPreload: true,
208
- shouldSaveHistory: false,
209
200
  chains: chains,
210
201
  config: config,
211
202
  isResolved: false
@@ -220,14 +211,14 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inMe
220
211
  await Promise.all(promises);
221
212
  }
222
213
 
223
- async function runBatchHandlersOrThrow(batch, inMemoryStore, loadManager, ctx, shouldSaveHistory, chains) {
214
+ async function runBatchHandlersOrThrow(batch, inMemoryStore, loadManager, ctx, chains) {
224
215
  let itemIdx = 0;
225
216
  for (let checkpointIdx = 0, checkpointIdx_finish = batch.checkpointIds.length; checkpointIdx < checkpointIdx_finish; ++checkpointIdx) {
226
217
  let checkpointId = batch.checkpointIds[checkpointIdx];
227
218
  let checkpointEventsProcessed = batch.checkpointEventsProcessed[checkpointIdx];
228
219
  for (let idx = 0; idx < checkpointEventsProcessed; ++idx) {
229
220
  let item = batch.items[itemIdx + idx | 0];
230
- await runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager, ctx, shouldSaveHistory, chains);
221
+ await runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager, ctx, chains);
231
222
  }
232
223
  itemIdx = itemIdx + checkpointEventsProcessed | 0;
233
224
  }
@@ -262,11 +253,11 @@ async function processEventBatch(batch, inMemoryStore, isInReorgThreshold, loadM
262
253
  }
263
254
  let elapsedTimeAfterLoaders = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
264
255
  if (Utils.$$Array.notEmpty(batch.items)) {
265
- await runBatchHandlersOrThrow(batch, inMemoryStore, loadManager, ctx, Config.shouldSaveHistory(ctx.config, isInReorgThreshold), chains);
256
+ await runBatchHandlersOrThrow(batch, inMemoryStore, loadManager, ctx, chains);
266
257
  }
267
258
  let elapsedTimeAfterProcessing = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
268
259
  try {
269
- await Persistence.writeBatch(ctx.persistence, batch, ctx.config, inMemoryStore, isInReorgThreshold);
260
+ await InMemoryStore.writeBatch(inMemoryStore, ctx.persistence, batch, ctx.config, isInReorgThreshold);
270
261
  let elapsedTimeAfterDbWrite = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
271
262
  let handlerDuration = elapsedTimeAfterProcessing - elapsedTimeAfterLoaders;
272
263
  let dbWriteDuration = elapsedTimeAfterDbWrite - elapsedTimeAfterProcessing;
@@ -1,21 +1,3 @@
1
- //Comparator used when ordering multichain events
2
- let getOrderedBatchItemComparator = (item: Internal.item) => {
3
- switch item {
4
- | Internal.Event({timestamp, chain, blockNumber, logIndex}) => (
5
- timestamp,
6
- chain->ChainMap.Chain.toChainId,
7
- blockNumber,
8
- logIndex,
9
- )
10
- | Internal.Block(_) =>
11
- JsError.throwWithMessage("Block handlers are not supported for ordered multichain mode.")
12
- }
13
- }
14
-
15
- let isEarlier = (item1: (int, int, int, int), item2: (int, int, int, int)) => {
16
- item1 < item2
17
- }
18
-
19
1
  let isEarlierUnordered = (item1: (int, int, int), item2: (int, int, int)) => {
20
2
  item1 < item2
21
3
  }
@@ -74,12 +56,3 @@ let packEventIndex = (~blockNumber, ~logIndex) => {
74
56
  // let packEventIndexFromRecord = (eventIndex: eventIndex) => {
75
57
  // packEventIndex(~blockNumber=eventIndex.blockNumber, ~logIndex=eventIndex.logIndex)
76
58
  // }
77
-
78
- //Returns unique string id for an event using its chain id combined with event id
79
- //Used in IO for the key in the in mem rawEvents table
80
- let getEventIdKeyString = (~chainId: int, ~eventId: string) => {
81
- let chainIdStr = chainId->Belt.Int.toString
82
- let key = chainIdStr ++ "_" ++ eventId
83
-
84
- key
85
- }
@@ -1,23 +1,7 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
4
3
  import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
5
4
 
6
- function getOrderedBatchItemComparator(item) {
7
- if (item.kind === 0) {
8
- return [
9
- item.timestamp,
10
- item.chain,
11
- item.blockNumber,
12
- item.logIndex
13
- ];
14
- } else {
15
- return Stdlib_JsError.throwWithMessage("Block handlers are not supported for ordered multichain mode.");
16
- }
17
- }
18
-
19
- let isEarlier = Primitive_object.lessthan;
20
-
21
5
  let isEarlierUnordered = Primitive_object.lessthan;
22
6
 
23
7
  function packEventIndex(blockNumber, logIndex) {
@@ -27,16 +11,8 @@ function packEventIndex(blockNumber, logIndex) {
27
11
  return blockNumber$2 | logIndex$1;
28
12
  }
29
13
 
30
- function getEventIdKeyString(chainId, eventId) {
31
- let chainIdStr = String(chainId);
32
- return chainIdStr + "_" + eventId;
33
- }
34
-
35
14
  export {
36
- getOrderedBatchItemComparator,
37
- isEarlier,
38
15
  isEarlierUnordered,
39
16
  packEventIndex,
40
- getEventIdKeyString,
41
17
  }
42
18
  /* No side effect */