envio 2.20.1 → 2.21.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.
@@ -3,6 +3,8 @@
3
3
  /* eslint-disable */
4
4
  /* tslint:disable */
5
5
 
6
+ import type {GenericContractRegister as $$genericContractRegister} from './Types.ts';
7
+
6
8
  import type {Invalid as $$noEventFilters} from './Types.ts';
7
9
 
8
10
  import type {t as Address_t} from './Address.gen';
@@ -22,7 +24,7 @@ export type genericLoader<args,loaderReturn> = (_1:args) => Promise<loaderReturn
22
24
 
23
25
  export type genericContractRegisterArgs<event,context> = { readonly event: event; readonly context: context };
24
26
 
25
- export type genericContractRegister<args> = (_1:args) => void;
27
+ export type genericContractRegister<args> = $$genericContractRegister<args>;
26
28
 
27
29
  export type genericHandlerArgs<event,context,loaderReturn> = {
28
30
  readonly event: event;
package/src/Internal.res CHANGED
@@ -35,8 +35,8 @@ type genericContractRegisterArgs<'event, 'context> = {
35
35
  event: 'event,
36
36
  context: 'context,
37
37
  }
38
- @genType
39
- type genericContractRegister<'args> = 'args => unit
38
+ @genType.import(("./Types.ts", "GenericContractRegister"))
39
+ type genericContractRegister<'args> = 'args => promise<unit>
40
40
 
41
41
  type contractRegisterContext
42
42
  type contractRegisterArgs = genericContractRegisterArgs<event, contractRegisterContext>
package/src/Logging.res CHANGED
@@ -150,7 +150,8 @@ let getEventLogger = (eventItem: Internal.eventItem) => {
150
150
  | None => {
151
151
  let l = getLogger()->child(
152
152
  {
153
- "context": `Event '${eventItem.eventConfig.name}' for contract '${eventItem.eventConfig.contractName}'`,
153
+ "contractName": eventItem.eventConfig.contractName,
154
+ "eventName": eventItem.eventConfig.name,
154
155
  "chainId": eventItem.chain->ChainMap.Chain.toChainId,
155
156
  "block": eventItem.blockNumber,
156
157
  "logIndex": eventItem.logIndex,
@@ -162,18 +163,16 @@ let getEventLogger = (eventItem: Internal.eventItem) => {
162
163
  }
163
164
  }
164
165
 
165
- let getUserLogger = {
166
- @inline
167
- let log = (eventItem, level: Pino.logLevelUser, message: string, ~params) => {
168
- (eventItem->getEventLogger->Utils.magic->Js.Dict.unsafeGet((level :> string)))(params, message)
169
- }
166
+ @inline
167
+ let logForItem = (eventItem, level: Pino.logLevel, message: string, ~params=?) => {
168
+ (eventItem->getEventLogger->Utils.magic->Js.Dict.unsafeGet((level :> string)))(params, message)
169
+ }
170
170
 
171
- (eventItem): Envio.logger => {
172
- info: (message: string, ~params=?) => eventItem->log(#uinfo, message, ~params),
173
- debug: (message: string, ~params=?) => eventItem->log(#udebug, message, ~params),
174
- warn: (message: string, ~params=?) => eventItem->log(#uwarn, message, ~params),
175
- error: (message: string, ~params=?) => eventItem->log(#uerror, message, ~params),
176
- errorWithExn: (message: string, exn) =>
177
- eventItem->log(#uerror, message, ~params={"err": exn->Internal.prettifyExn}),
178
- }
171
+ let getUserLogger = (eventItem): Envio.logger => {
172
+ info: (message: string, ~params=?) => eventItem->logForItem(#uinfo, message, ~params?),
173
+ debug: (message: string, ~params=?) => eventItem->logForItem(#udebug, message, ~params?),
174
+ warn: (message: string, ~params=?) => eventItem->logForItem(#uwarn, message, ~params?),
175
+ error: (message: string, ~params=?) => eventItem->logForItem(#uerror, message, ~params?),
176
+ errorWithExn: (message: string, exn) =>
177
+ eventItem->logForItem(#uerror, message, ~params={"err": exn->Internal.prettifyExn}),
179
178
  }
@@ -335,7 +335,7 @@ module IndexingMaxConcurrency = {
335
335
  module IndexingConcurrency = {
336
336
  let gauge = SafeGauge.makeOrThrow(
337
337
  ~name="envio_indexing_concurrency",
338
- ~help="The current number of concurrent queries to the chain data-source.",
338
+ ~help="The number of executing concurrent queries to the chain data-source.",
339
339
  ~labelSchema=chainIdLabelsSchema,
340
340
  )
341
341
 
@@ -344,6 +344,18 @@ module IndexingConcurrency = {
344
344
  }
345
345
  }
346
346
 
347
+ module IndexingPartitions = {
348
+ let gauge = SafeGauge.makeOrThrow(
349
+ ~name="envio_indexing_partitions",
350
+ ~help="The number of partitions used to split fetching logic by addresses and block ranges.",
351
+ ~labelSchema=chainIdLabelsSchema,
352
+ )
353
+
354
+ let set = (~partitionsCount, ~chainId) => {
355
+ gauge->SafeGauge.handleInt(~labels=chainId, ~value=partitionsCount)
356
+ }
357
+ }
358
+
347
359
  module IndexingBufferSize = {
348
360
  let gauge = SafeGauge.makeOrThrow(
349
361
  ~name="envio_indexing_buffer_size",
package/src/Types.ts CHANGED
@@ -45,3 +45,7 @@ export type EffectContext = {
45
45
  */
46
46
  readonly effect: EffectCaller;
47
47
  };
48
+
49
+ export type GenericContractRegister<Args> = (
50
+ args: Args
51
+ ) => void | Promise<void>;
package/src/Utils.res CHANGED
@@ -328,6 +328,8 @@ let unwrapResultExn = res =>
328
328
  external queueMicrotask: (unit => unit) => unit = "queueMicrotask"
329
329
 
330
330
  module Schema = {
331
+ let variantTag = S.union([S.string, S.object(s => s.field("TAG", S.string))])
332
+
331
333
  let getNonOptionalFieldNames = schema => {
332
334
  let acc = []
333
335
  switch schema->S.classify {
@@ -385,6 +387,10 @@ module Schema = {
385
387
  }
386
388
  }
387
389
 
390
+ let getVariantsTags = variants => {
391
+ variants->Js.Array2.map(variant => variant->S.parseOrThrow(Schema.variantTag))
392
+ }
393
+
388
394
  module Set = {
389
395
  type t<'value>
390
396
 
@@ -50,3 +50,5 @@ external done: promise<'a> => unit = "%ignore"
50
50
 
51
51
  external unsafe_async: 'a => promise<'a> = "%identity"
52
52
  external unsafe_await: promise<'a> => 'a = "?await"
53
+
54
+ let isCatchable: 'any => bool = %raw(`value => value && typeof value.catch === 'function'`)
@@ -0,0 +1,19 @@
1
+ /* TypeScript file generated from HyperSyncClient.res by genType. */
2
+
3
+ /* eslint-disable */
4
+ /* tslint:disable */
5
+
6
+ import type {t as Address_t} from '../../src/Address.gen';
7
+
8
+ export type ResponseTypes_accessList = { readonly address?: Address_t; readonly storageKeys?: string[] };
9
+
10
+ export type ResponseTypes_authorizationList = {
11
+ readonly chainId: bigint;
12
+ readonly address: Address_t;
13
+ readonly nonce: number;
14
+ readonly yParity:
15
+ 1
16
+ | 0;
17
+ readonly r: string;
18
+ readonly s: string
19
+ };
@@ -75,6 +75,7 @@ module QueryTypes = {
75
75
  | L1GasUsed
76
76
  | L1FeeScalar
77
77
  | GasUsedForL1
78
+ | AuthorizationList
78
79
 
79
80
  type logField =
80
81
  | Removed
@@ -302,11 +303,36 @@ module ResponseTypes = {
302
303
  mixHash?: string,
303
304
  }
304
305
 
306
+ @genType
305
307
  type accessList = {
306
308
  address?: Address.t,
307
309
  storageKeys?: array<string>,
308
310
  }
309
311
 
312
+ let accessListSchema = S.object(s => {
313
+ address: ?s.field("address", S.option(Address.schema)),
314
+ storageKeys: ?s.field("storageKeys", S.option(S.array(S.string))),
315
+ })
316
+
317
+ @genType
318
+ type authorizationList = {
319
+ chainId: bigint,
320
+ address: Address.t,
321
+ nonce: int,
322
+ yParity: [#0 | #1],
323
+ r: string,
324
+ s: string,
325
+ }
326
+
327
+ let authorizationListSchema = S.object(s => {
328
+ chainId: s.field("chainId", S.bigint),
329
+ address: s.field("address", Address.schema),
330
+ nonce: s.field("nonce", S.int),
331
+ yParity: s.field("yParity", S.enum([#0, #1])),
332
+ r: s.field("r", S.string),
333
+ s: s.field("s", S.string),
334
+ })
335
+
310
336
  type transaction = {
311
337
  blockHash?: string,
312
338
  blockNumber?: int,
@@ -342,6 +368,7 @@ module ResponseTypes = {
342
368
  l1GasUsed?: bigint,
343
369
  l1FeeScalar?: int,
344
370
  gasUsedForL1?: bigint,
371
+ authorizationList?: array<authorizationList>,
345
372
  }
346
373
 
347
374
  type log = {
@@ -0,0 +1,59 @@
1
+ /**
2
+ A set of stats for logging about the block range fetch
3
+ */
4
+ type blockRangeFetchStats = {
5
+ @as("total time elapsed (ms)") totalTimeElapsed: int,
6
+ @as("parsing time (ms)") parsingTimeElapsed?: int,
7
+ @as("page fetch time (ms)") pageFetchTime?: int,
8
+ }
9
+
10
+ /**
11
+ Thes response returned from a block range fetch
12
+ */
13
+ type blockRangeFetchResponse = {
14
+ currentBlockHeight: int,
15
+ reorgGuard: ReorgDetection.reorgGuard,
16
+ parsedQueueItems: array<Internal.eventItem>,
17
+ fromBlockQueried: int,
18
+ latestFetchedBlockNumber: int,
19
+ latestFetchedBlockTimestamp: int,
20
+ stats: blockRangeFetchStats,
21
+ }
22
+
23
+ type getItemsRetry =
24
+ | WithSuggestedToBlock({toBlock: int})
25
+ | WithBackoff({message: string, backoffMillis: int})
26
+
27
+ type getItemsError =
28
+ | UnsupportedSelection({message: string})
29
+ | FailedGettingFieldSelection({exn: exn, blockNumber: int, logIndex: int, message: string})
30
+ | FailedParsingItems({exn: exn, blockNumber: int, logIndex: int, message: string})
31
+ | FailedGettingItems({exn: exn, attemptedToBlock: int, retry: getItemsRetry})
32
+
33
+ exception GetItemsError(getItemsError)
34
+
35
+ type sourceFor = Sync | Fallback
36
+ type t = {
37
+ name: string,
38
+ sourceFor: sourceFor,
39
+ chain: ChainMap.Chain.t,
40
+ poweredByHyperSync: bool,
41
+ /* Frequency (in ms) used when polling for new events on this network. */
42
+ pollingInterval: int,
43
+ getBlockHashes: (
44
+ ~blockNumbers: array<int>,
45
+ ~logger: Pino.t,
46
+ ) => promise<result<array<ReorgDetection.blockDataWithTimestamp>, exn>>,
47
+ getHeightOrThrow: unit => promise<int>,
48
+ getItemsOrThrow: (
49
+ ~fromBlock: int,
50
+ ~toBlock: option<int>,
51
+ ~addressesByContractName: dict<array<Address.t>>,
52
+ ~indexingContracts: dict<FetchState.indexingContract>,
53
+ ~currentBlockHeight: int,
54
+ ~partitionId: string,
55
+ ~selection: FetchState.selection,
56
+ ~retry: int,
57
+ ~logger: Pino.t,
58
+ ) => promise<blockRangeFetchResponse>,
59
+ }