envio 3.2.1 → 3.3.0-alpha.0

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 (106) hide show
  1. package/package.json +6 -7
  2. package/src/Batch.res +12 -15
  3. package/src/Batch.res.mjs +4 -5
  4. package/src/BatchProcessing.res +199 -0
  5. package/src/BatchProcessing.res.mjs +125 -0
  6. package/src/ChainFetching.res +375 -0
  7. package/src/ChainFetching.res.mjs +206 -0
  8. package/src/ChainMetadata.res +27 -0
  9. package/src/ChainMetadata.res.mjs +27 -0
  10. package/src/ChainState.res +618 -0
  11. package/src/ChainState.res.mjs +461 -0
  12. package/src/ChainState.resi +85 -0
  13. package/src/Config.res +13 -4
  14. package/src/Config.res.mjs +8 -3
  15. package/src/ContractRegisterContext.res +106 -0
  16. package/src/ContractRegisterContext.res.mjs +76 -0
  17. package/src/Core.res +3 -0
  18. package/src/CrossChainState.res +269 -0
  19. package/src/CrossChainState.res.mjs +197 -0
  20. package/src/CrossChainState.resi +47 -0
  21. package/src/Ecosystem.res +58 -0
  22. package/src/Ecosystem.res.mjs +43 -1
  23. package/src/Env.res +7 -2
  24. package/src/Env.res.mjs +5 -2
  25. package/src/EventConfigBuilder.res +2 -2
  26. package/src/EventProcessing.res +60 -46
  27. package/src/EventProcessing.res.mjs +33 -32
  28. package/src/EventUtils.res +0 -4
  29. package/src/EventUtils.res.mjs +0 -4
  30. package/src/ExitOnCaughtUp.res +10 -0
  31. package/src/ExitOnCaughtUp.res.mjs +22 -0
  32. package/src/FetchState.res +124 -62
  33. package/src/FetchState.res.mjs +159 -93
  34. package/src/InMemoryStore.res +36 -451
  35. package/src/InMemoryStore.res.mjs +20 -369
  36. package/src/IndexerLoop.res +44 -0
  37. package/src/IndexerLoop.res.mjs +46 -0
  38. package/src/IndexerState.res +544 -0
  39. package/src/IndexerState.res.mjs +547 -0
  40. package/src/IndexerState.resi +132 -0
  41. package/src/Internal.res +29 -8
  42. package/src/LoadLayer.res +20 -18
  43. package/src/LoadLayer.res.mjs +14 -12
  44. package/src/LoadLayer.resi +6 -3
  45. package/src/Logging.res +11 -44
  46. package/src/Logging.res.mjs +10 -42
  47. package/src/Main.res +54 -79
  48. package/src/Main.res.mjs +44 -56
  49. package/src/PgStorage.res +8 -71
  50. package/src/PgStorage.res.mjs +3 -47
  51. package/src/Prometheus.res +7 -8
  52. package/src/Prometheus.res.mjs +7 -4
  53. package/src/PruneStaleHistory.res +45 -0
  54. package/src/PruneStaleHistory.res.mjs +46 -0
  55. package/src/RawEvent.res +73 -0
  56. package/src/RawEvent.res.mjs +51 -0
  57. package/src/Rollback.res +204 -0
  58. package/src/Rollback.res.mjs +118 -0
  59. package/src/SimulateItems.res +12 -10
  60. package/src/SimulateItems.res.mjs +1 -1
  61. package/src/UserContext.res +26 -114
  62. package/src/UserContext.res.mjs +15 -78
  63. package/src/Writing.res +242 -0
  64. package/src/Writing.res.mjs +215 -0
  65. package/src/db/InternalTable.res +14 -27
  66. package/src/sources/Evm.res +40 -1
  67. package/src/sources/Evm.res.mjs +94 -84
  68. package/src/sources/Fuel.res +40 -1
  69. package/src/sources/Fuel.res.mjs +36 -26
  70. package/src/sources/HyperFuel.res +41 -120
  71. package/src/sources/HyperFuel.res.mjs +42 -80
  72. package/src/sources/HyperFuel.resi +1 -24
  73. package/src/sources/HyperFuelClient.res +16 -297
  74. package/src/sources/HyperFuelClient.res.mjs +5 -4
  75. package/src/sources/HyperFuelSource.res +33 -8
  76. package/src/sources/HyperFuelSource.res.mjs +56 -10
  77. package/src/sources/HyperSyncSource.res +5 -3
  78. package/src/sources/HyperSyncSource.res.mjs +1 -1
  79. package/src/sources/RpcSource.res +2 -2
  80. package/src/sources/RpcSource.res.mjs +1 -1
  81. package/src/sources/SourceManager.res +8 -18
  82. package/src/sources/SourceManager.res.mjs +8 -5
  83. package/src/sources/SourceManager.resi +4 -1
  84. package/src/sources/Svm.res +18 -1
  85. package/src/sources/Svm.res.mjs +30 -22
  86. package/src/sources/SvmHyperSyncSource.res +1 -1
  87. package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
  88. package/src/tui/Tui.res +38 -36
  89. package/src/tui/Tui.res.mjs +51 -51
  90. package/src/ChainFetcher.res +0 -519
  91. package/src/ChainFetcher.res.mjs +0 -314
  92. package/src/ChainManager.res +0 -358
  93. package/src/ChainManager.res.mjs +0 -291
  94. package/src/Ctx.res +0 -6
  95. package/src/Ctx.res.mjs +0 -2
  96. package/src/GlobalState.res +0 -1056
  97. package/src/GlobalState.res.mjs +0 -1086
  98. package/src/GlobalStateManager.res +0 -57
  99. package/src/GlobalStateManager.res.mjs +0 -68
  100. package/src/GlobalStateManager.resi +0 -7
  101. package/src/Ports.res +0 -5
  102. package/src/Ports.res.mjs +0 -9
  103. package/src/adapters/MarkBatchProcessedAdapter.res +0 -5
  104. package/src/adapters/MarkBatchProcessedAdapter.res.mjs +0 -14
  105. package/src/sources/EnvioApiClient.res +0 -15
  106. package/src/sources/EnvioApiClient.res.mjs +0 -24
@@ -1,119 +1,43 @@
1
- type unchecksummedEthAddress = string
2
-
3
1
  type t
4
2
 
5
3
  type cfg = {
6
4
  url: string,
7
- bearerToken?: string,
8
- http_req_timeout_millis?: int,
5
+ apiToken: string,
9
6
  }
10
7
  module QueryTypes = {
11
8
  type blockFieldOptions =
12
9
  | @as("id") Id
13
- | @as("da_height") DaHeight
14
- | @as("transactions_count") TransactionsCount
15
- | @as("message_receipt_count") MessageReceiptCount
16
- | @as("transactions_root") TransactionsRoot
17
- | @as("message_receipt_root") MessageReceiptRoot
18
10
  | @as("height") Height
19
- | @as("prev_root") PrevRoot
20
11
  | @as("time") Time
21
- | @as("application_hash") ApplicationHash
22
12
 
23
13
  type blockFieldSelection = array<blockFieldOptions>
24
14
 
25
- type transactionFieldOptions =
26
- | @as("id") Id
27
- | @as("block_height") BlockHeight
28
- | @as("input_asset_ids") InputAssetIds
29
- | @as("input_contracts") InputContracts
30
- | @as("input_contract_utxo_id") InputContractUtxoId
31
- | @as("input_contract_balance_root") InputContractBalanceRoot
32
- | @as("input_contract_state_root") InputContractStateRoot
33
- | @as("input_contract_tx_pointer_block_height") InputContractTxPointerBlockHeight
34
- | @as("input_contract_tx_pointer_tx_index") InputContractTxPointerTxIndex
35
- | @as("input_contract") InputContract
36
- | @as("gas_price") GasPrice
37
- | @as("gas_limit") GasLimit
38
- | @as("maturity") Maturity
39
- | @as("mint_amount") MintAmount
40
- | @as("mint_asset_id") MintAssetId
41
- | @as("tx_pointer_block_height") TxPointerBlockHeight
42
- | @as("tx_pointer_tx_index") TxPointerTxIndex
43
- | @as("tx_type") TxType
44
- | @as("output_contract_input_index") OutputContractInputIndex
45
- | @as("output_contract_balance_root") OutputContractBalanceRoot
46
- | @as("output_contract_state_root") OutputContractStateRoot
47
- | @as("witnesses") Witnesses
48
- | @as("receipts_root") ReceiptsRoot
49
- | @as("status") Status
50
- | @as("time") Time
51
- | @as("reason") Reason
52
- | @as("script") Script
53
- | @as("script_data") ScriptData
54
- | @as("bytecode_witness_index") BytecodeWitnessIndex
55
- | @as("bytecode_length") BytecodeLength
56
- | @as("salt") Salt
57
-
58
- type transactionFieldSelection = array<transactionFieldOptions>
59
-
60
15
  type receiptFieldOptions =
61
16
  | @as("tx_id") TxId
62
- | @as("tx_status") TxStatus
63
17
  | @as("block_height") BlockHeight
64
- | @as("pc") Pc
65
- | @as("is") Is
66
- | @as("to") To
67
18
  | @as("to_address") ToAddress
68
19
  | @as("amount") Amount
69
20
  | @as("asset_id") AssetId
70
- | @as("gas") Gas
71
- | @as("param1") Param1
72
- | @as("param2") Param2
73
21
  | @as("val") Val
74
- | @as("ptr") Ptr
75
- | @as("digest") Digest
76
- | @as("reason") Reason
77
- | @as("ra") Ra
78
22
  | @as("rb") Rb
79
- | @as("rc") Rc
80
- | @as("rd") Rd
81
- | @as("len") Len
82
23
  | @as("receipt_type") ReceiptType
83
24
  | @as("receipt_index") ReceiptIndex
84
- | @as("result") Result
85
- | @as("gas_used") GasUsed
86
25
  | @as("data") Data
87
- | @as("sender") Sender
88
- | @as("recipient") Recipient
89
- | @as("nonce") Nonce
90
- | @as("contract_id") ContractId
91
26
  | @as("root_contract_id") RootContractId
92
27
  | @as("sub_id") SubId
28
+ | @as("to") To
93
29
 
94
30
  type receiptFieldSelection = array<receiptFieldOptions>
95
31
 
96
32
  type fieldSelection = {
97
33
  block?: blockFieldSelection,
98
- transaction?: transactionFieldSelection,
99
34
  receipt?: receiptFieldSelection,
100
35
  }
101
36
 
102
- type inputSelection
103
- type outputSelection
104
-
105
37
  type receiptSelection = {
106
38
  rootContractId?: array<Address.t>,
107
- toAddress?: array<string>,
108
- assetId?: array<string>,
109
39
  receiptType?: array<FuelSDK.receiptType>,
110
- sender?: array<string>,
111
- recipient?: array<string>,
112
- contractId?: array<Address.t>,
113
- ra?: array<bigint>,
114
40
  rb?: array<bigint>,
115
- rc?: array<bigint>,
116
- rd?: array<bigint>,
117
41
  txStatus?: array<int>,
118
42
  }
119
43
 
@@ -137,254 +61,44 @@ module QueryTypes = {
137
61
  */
138
62
  receipts?: array<receiptSelection>,
139
63
  /**
140
- * List of input selections, the query will return inputs that match any of these selections and
141
- * it will return inputs that are related to the returned objects.
142
- */
143
- inputs?: array<inputSelection>,
144
- /**
145
- * List of output selections, the query will return outputs that match any of these selections and
146
- * it will return outputs that are related to the returned objects.
147
- */
148
- outputs?: array<outputSelection>,
149
- /**
150
- * Whether to include all blocks regardless of if they are related to a returned transaction or log. Normally
151
- * the server will return only the blocks that are related to the transaction or logs in the response. But if this
152
- * is set to true, the server will return data for all blocks in the requested range [from_block, to_block).
153
- */
154
- includeAllBlocks?: bool,
155
- /**
156
64
  * Field selection. The user can select which fields they are interested in, requesting less fields will improve
157
65
  * query execution time and reduce the payload size so the user should always use a minimal number of fields.
158
66
  */
159
67
  fieldSelection: fieldSelection,
160
- /**
161
- * Maximum number of blocks that should be returned, the server might return more blocks than this number but
162
- * it won't overshoot by too much.
163
- */
164
- maxNumBlocks?: int,
165
- /**
166
- * Maximum number of transactions that should be returned, the server might return more transactions than this number but
167
- * it won't overshoot by too much.
168
- */
169
- maxNumTransactions?: int,
170
68
  }
171
69
  }
172
70
 
173
71
  module FuelTypes = {
174
- /** An object containing information about a transaction. */
175
- type transaction = {
176
- /** block the transaction is in. */
177
- blockHeight: int,
178
- /** A unique transaction id. */
179
- id: string,
180
- /** An array of asset ids used for the transaction inputs. */
181
- inputAssetIds?: array<string>,
182
- /** An array of contracts used for the transaction inputs. */
183
- inputContracts?: array<string>,
184
- /**
185
- * A contract used for the transaction input.
186
- * A unique 32 byte identifier for the UTXO for a contract used for the transaction input.
187
- */
188
- inputContractUtxoId?: string,
189
- /** The root of amount of coins owned by contract before transaction execution for a contract used for the transaction input. */
190
- inputContractBalanceRoot?: string,
191
- /** The state root of contract before transaction execution for a contract used for the transaction input. */
192
- inputContractStateRoot?: string,
193
- /** A pointer to the TX whose output is being spent for a contract used for the transaction input. */
194
- inputContractTxPointerBlockHeight?: int,
195
- /** A pointer to the TX whose output is being spent for a contract used for the transaction input. */
196
- inputContractTxPointerTxIndex?: int,
197
- /** The contract id for a contract used for the transaction input. */
198
- inputContract?: string,
199
- /** The gas price for the transaction. */
200
- gasPrice?: bigint,
201
- /** The gas limit for the transaction. */
202
- gasLimit?: bigint,
203
- /** The minimum block height that the transaction can be included at. */
204
- maturity?: int,
205
- /** The amount minted in the transaction. */
206
- mintAmount?: bigint,
207
- /** The asset ID for coins minted in the transaction. */
208
- mintAssetId?: string,
209
- /** The location of the transaction in the block. */
210
- txPointerBlockHeight?: int,
211
- txPointerTxIndex?: int,
212
- /** Script, creating a new contract, or minting new coins */
213
- txType: int,
214
- /** The index of the input from a transaction that changed the state of a contract. */
215
- outputContractInputIndex?: int,
216
- /** The root of amount of coins owned by contract after transaction execution from a transaction that changed the state of a contract. */
217
- outputContractBalanceRoot?: string,
218
- /** The state root of contract after transaction execution from a transaction that changed the state of a contract. */
219
- outputContractStateRoot?: string,
220
- /** An array of witnesses. */
221
- witnesses?: string,
222
- /** The root of the receipts. */
223
- receiptsRoot?: string,
224
- /** The status type of the transaction. */
225
- status: int,
226
- /** for SubmittedStatus, SuccessStatus, and FailureStatus, the time a transaction was submitted, successful, or failed */
227
- time: int,
228
- /**
229
- * for SuccessStatus, the state of the program execution
230
- * for SqueezedOutStatus & FailureStatus, the reason the transaction was squeezed out or failed
231
- */
232
- reason?: string,
233
- /** The script to execute. */
234
- script?: string,
235
- /** The script input parameters. */
236
- scriptData?: string,
237
- /** The witness index of contract bytecode. */
238
- bytecodeWitnessIndex?: int,
239
- /** The length of the transaction bytecode. */
240
- bytecodeLength?: int,
241
- /** The salt value for the transaction. */
242
- salt?: string,
243
- }
244
- /** An object representing all possible types of receipts. */
245
72
  type receipt = {
246
- /** Index of the receipt in the block */
247
73
  receiptIndex: int,
248
- /** Contract that produced the receipt */
249
74
  rootContractId?: Address.t,
250
- /** transaction that this receipt originated from */
251
75
  txId: string,
252
- /** The status type of the transaction this receipt originated from */
253
- txStatus: int,
254
- /** block that the receipt originated in */
255
76
  blockHeight: int,
256
- /** The value of the program counter register $pc, which is the memory address of the current instruction. */
257
- pc?: int,
258
- /** The value of register $is, which is the pointer to the start of the currently-executing code. */
259
- is?: int,
260
- /** The recipient contract */
261
- to?: string,
262
- /** The recipient address */
263
- toAddress?: string,
264
- /** The amount of coins transferred. */
265
- amount?: bigint,
266
- /** The asset id of the coins transferred. */
267
- assetId?: string,
268
- /** The gas used for the transaction. */
269
- gas?: int,
270
- /** The first parameter for a CALL receipt type, holds the function selector. */
271
- param1?: bigint,
272
- /** The second parameter for a CALL receipt type, typically used for the user-specified input to the ABI function being selected. */
273
- param2?: bigint,
274
- /** The value of registers at the end of execution, used for debugging. */
275
- val?: bigint,
276
- /** The value of the pointer register, used for debugging. */
277
- ptr?: bigint,
278
- /** A 32-byte String of MEM[$rC, $rD]. The syntax MEM[x, y] means the memory range starting at byte x, of length y bytes. */
279
- digest?: string,
280
- /** The decimal string representation of an 8-bit unsigned integer for the panic reason. Only returned if the receipt type is PANIC. */
281
- reason?: int,
282
- /** The value of register $rA. */
283
- ra?: bigint,
284
- /** The value of register $rB. */
285
- rb?: bigint,
286
- /** The value of register $rC. */
287
- rc?: bigint,
288
- /** The value of register $rD. */
289
- rd?: bigint,
290
- /** The length of the receipt. */
291
- len?: bigint,
292
- /** The type of receipt. */
293
77
  receiptType: FuelSDK.receiptType,
294
- /** 0 if script exited successfully, any otherwise. */
295
- result?: int,
296
- /** The amount of gas consumed by the script. */
297
- gasUsed?: int,
298
- /** The receipt data. */
299
78
  data?: string,
300
- /** The address of the message sender. */
301
- sender?: string,
302
- /** The address of the message recipient. */
303
- recipient?: string,
304
- /** The nonce value for a message. */
305
- nonce?: string,
306
- /** Current context if in an internal context. null otherwise */
307
- contractId?: Address.t,
308
- /** The sub id. */
79
+ rb?: bigint,
80
+ val?: bigint,
309
81
  subId?: string,
310
- }
311
-
312
- // Unused - in indexer currently
313
- type input = {
314
- txId: string,
315
- blockHeight: int,
316
- inputType: int,
317
- utxoId?: string,
318
- owner?: string,
319
82
  amount?: bigint,
320
83
  assetId?: string,
321
- txPointerBlockHeight?: int,
322
- txPointerTxIndex?: int,
323
- witnessIndex?: int,
324
- predicateGasUsed?: int,
325
- predicate?: string,
326
- predicateData?: string,
327
- balanceRoot?: string,
328
- stateRoot?: string,
329
- contract?: string,
330
- sender?: string,
331
- recipient?: string,
332
- nonce?: string,
333
- data?: string,
334
- }
335
-
336
- // Unused in indexer currently
337
- type output = {
338
- txId: string,
339
- blockHeight: int,
340
- outputType: int,
341
84
  to?: string,
342
- amount?: bigint,
343
- assetId?: string,
344
- inputIndex?: int,
345
- balanceRoot?: string,
346
- stateRoot?: string,
347
- contract?: string,
85
+ toAddress?: string,
348
86
  }
349
87
 
350
- // Unused in indexer currently
351
- /** The block header contains metadata about a certain block. */
352
88
  type block = {
353
- /** String of the header */
354
89
  id: string,
355
- /** The block height for the data availability layer up to which (inclusive) input messages are processed. */
356
- daHeight: int,
357
- consensusParametersVersion: int,
358
- stateTransitionBytecodeVersion: int,
359
- /** The number of transactions in the block. */
360
- transactionsCount: string,
361
- /** The number of receipt messages in the block. */
362
- messageReceiptCount: string,
363
- /** The merkle root of the transactions in the block. */
364
- transactionsRoot: string,
365
- messageOutboxRoot: string,
366
- eventInboxRoot: string,
367
- /** The block height. */
368
90
  height: int,
369
- /** The merkle root of all previous consensus header Stringes (not including this block). */
370
- prevRoot: string,
371
- /** The timestamp for the block. */
372
91
  time: int,
373
- /** The String of the serialized application header for this block. */
374
- applicationHash: string,
375
92
  }
376
93
  }
377
94
 
378
95
  type queryResponseDataTyped = {
379
- transactions: array<FuelTypes.transaction>,
380
96
  receipts: array<FuelTypes.receipt>,
381
- blocks: option<array<FuelTypes.block>>,
382
- inputs: array<FuelTypes.input>,
383
- outputs: array<FuelTypes.output>,
97
+ blocks: array<FuelTypes.block>,
384
98
  }
385
99
 
386
100
  type queryResponseTyped = {
387
- /** Current height of the source hypersync instance */
101
+ /** Current height of the source HyperFuel instance */
388
102
  archiveHeight?: int,
389
103
  /**
390
104
  * Next block to query for, the responses are paginated so
@@ -392,17 +106,22 @@ type queryResponseTyped = {
392
106
  * didn't get responses up to the to_block they specified in the Query.
393
107
  */
394
108
  nextBlock: int,
395
- /** Total time it took the hypersync instance to execute the query. */
109
+ /** Total time it took the HyperFuel instance to execute the query. */
396
110
  totalExecutionTime: int,
397
111
  /** Response data */
398
112
  data: queryResponseDataTyped,
399
113
  }
400
114
 
401
- @module("@envio-dev/hyperfuel-client") @scope("HyperfuelClient")
402
- external make: cfg => t = "new"
115
+ @send
116
+ external classNew: (Core.hyperfuelClientCtor, cfg, ~userAgent: string) => t = "new"
117
+
403
118
  let make = (cfg: cfg) => {
404
- make({...cfg, bearerToken: "3dc856dd-b0ea-494f-b27e-017b8b6b7e07"})
119
+ let envioVersion = Utils.EnvioPackage.value.version
120
+ Core.getAddon().hyperfuelClient->classNew(cfg, ~userAgent=`hyperindex/${envioVersion}`)
405
121
  }
406
122
 
407
123
  @send
408
124
  external getSelectedData: (t, QueryTypes.query) => promise<queryResponseTyped> = "getSelectedData"
125
+
126
+ @send
127
+ external getHeight: t => promise<int> = "getHeight"
@@ -1,14 +1,15 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as HyperfuelClient from "@envio-dev/hyperfuel-client";
3
+ import * as Core from "../Core.res.mjs";
4
+ import * as Utils from "../Utils.res.mjs";
4
5
 
5
6
  let QueryTypes = {};
6
7
 
7
8
  let FuelTypes = {};
8
9
 
9
10
  function make(cfg) {
10
- let newrecord = {...cfg};
11
- return HyperfuelClient.HyperfuelClient.new((newrecord.bearerToken = "3dc856dd-b0ea-494f-b27e-017b8b6b7e07", newrecord));
11
+ let envioVersion = Utils.EnvioPackage.value.version;
12
+ return Core.getAddon().HyperfuelClient.new(cfg, `hyperindex/` + envioVersion);
12
13
  }
13
14
 
14
15
  export {
@@ -16,4 +17,4 @@ export {
16
17
  FuelTypes,
17
18
  make,
18
19
  }
19
- /* @envio-dev/hyperfuel-client Not a pure module */
20
+ /* Core Not a pure module */
@@ -2,6 +2,8 @@ open Source
2
2
 
3
3
  exception EventRoutingFailed
4
4
 
5
+ let isUnauthorizedError = (message: string) => message->String.includes("401 Unauthorized")
6
+
5
7
  let mintEventTag = "mint"
6
8
  let burnEventTag = "burn"
7
9
  let transferEventTag = "transfer"
@@ -207,11 +209,26 @@ let memoGetSelectionConfig = (~chain) => {
207
209
  type options = {
208
210
  chain: ChainMap.Chain.t,
209
211
  endpointUrl: string,
212
+ apiToken: option<string>,
210
213
  }
211
214
 
212
- let make = ({chain, endpointUrl}: options): t => {
215
+ let make = ({chain, endpointUrl, apiToken}: options): t => {
213
216
  let name = "HyperFuel"
214
217
 
218
+ let apiToken = switch apiToken {
219
+ | Some(token) => token
220
+ | None =>
221
+ JsError.throwWithMessage(`An Envio API token is required for using HyperFuel as a data-source.
222
+ Set the ENVIO_API_TOKEN environment variable in your .env file.
223
+ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
224
+ }
225
+
226
+ let client = switch HyperFuelClient.make({url: endpointUrl, apiToken}) {
227
+ | client => client
228
+ | exception exn =>
229
+ exn->ErrorHandling.mkLogAndRaise(~msg="Failed to instantiate the HyperFuel client")
230
+ }
231
+
215
232
  let getSelectionConfig = memoGetSelectionConfig(~chain)
216
233
 
217
234
  let getItemsOrThrow = async (
@@ -239,12 +256,12 @@ let make = ({chain, endpointUrl}: options): t => {
239
256
  ~method="getLogs",
240
257
  )
241
258
  let pageUnsafe = try await HyperFuel.GetLogs.query(
242
- ~serverUrl=endpointUrl,
259
+ ~client,
243
260
  ~fromBlock,
244
261
  ~toBlock,
245
262
  ~recieptsSelection,
246
263
  ) catch {
247
- | HyperSync.GetLogs.Error(error) =>
264
+ | HyperFuel.GetLogs.Error(error) =>
248
265
  throw(
249
266
  Source.GetItemsError(
250
267
  Source.FailedGettingItems({
@@ -397,7 +414,7 @@ let make = ({chain, endpointUrl}: options): t => {
397
414
  blockNumber: block.height,
398
415
  blockHash: block.id,
399
416
  logIndex: receiptIndex,
400
- event: {
417
+ payload: {
401
418
  contractName: eventConfig.contractName,
402
419
  eventName: eventConfig.name,
403
420
  chainId,
@@ -408,7 +425,7 @@ let make = ({chain, endpointUrl}: options): t => {
408
425
  block: block->Obj.magic,
409
426
  srcAddress: contractAddress,
410
427
  logIndex: receiptIndex,
411
- }->Internal.fromGenericEvent,
428
+ }->Fuel.fromPayload,
412
429
  })
413
430
  })
414
431
 
@@ -450,8 +467,6 @@ let make = ({chain, endpointUrl}: options): t => {
450
467
  let getBlockHashes = (~blockNumbers as _, ~logger as _) =>
451
468
  JsError.throwWithMessage("HyperFuel does not support getting block hashes")
452
469
 
453
- let jsonApiClient = EnvioApiClient.make(endpointUrl)
454
-
455
470
  {
456
471
  name,
457
472
  sourceFor: Sync,
@@ -461,7 +476,17 @@ let make = ({chain, endpointUrl}: options): t => {
461
476
  poweredByHyperSync: true,
462
477
  getHeightOrThrow: async () => {
463
478
  let timerRef = Hrtime.makeTimer()
464
- let height = await HyperFuel.heightRoute->Rest.fetch((), ~client=jsonApiClient)
479
+ let height = try await client->HyperFuelClient.getHeight catch {
480
+ | JsExn(e) =>
481
+ switch e->JsExn.message {
482
+ | Some(message) if message->isUnauthorizedError =>
483
+ Logging.error(`Your ENVIO_API_TOKEN was rejected by HyperFuel (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`)
484
+ // Retrying an unauthorized request can never succeed, so block forever
485
+ let _ = await Promise.make((_, _) => ())
486
+ 0
487
+ | _ => throw(JsExn(e))
488
+ }
489
+ }
465
490
  let seconds = timerRef->Hrtime.timeSince->Hrtime.toSecondsFloat
466
491
  Prometheus.SourceRequestCount.increment(
467
492
  ~sourceName=name,
@@ -1,21 +1,24 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as Rest from "../vendored/Rest.res.mjs";
4
3
  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 HyperFuel from "./HyperFuel.res.mjs";
8
- import * as HyperSync from "./HyperSync.res.mjs";
9
7
  import * as Prometheus from "../Prometheus.res.mjs";
10
8
  import * as EventRouter from "./EventRouter.res.mjs";
9
+ import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
11
10
  import * as ErrorHandling from "../ErrorHandling.res.mjs";
12
11
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
13
- import * as EnvioApiClient from "./EnvioApiClient.res.mjs";
14
12
  import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
13
+ import * as HyperFuelClient from "./HyperFuelClient.res.mjs";
15
14
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
16
15
 
17
16
  let EventRoutingFailed = /* @__PURE__ */Primitive_exceptions.create("HyperFuelSource.EventRoutingFailed");
18
17
 
18
+ function isUnauthorizedError(message) {
19
+ return message.includes("401 Unauthorized");
20
+ }
21
+
19
22
  let mintEventTag = "mint";
20
23
 
21
24
  let burnEventTag = "burn";
@@ -176,9 +179,22 @@ function memoGetSelectionConfig(chain) {
176
179
  }
177
180
 
178
181
  function make(param) {
179
- let endpointUrl = param.endpointUrl;
182
+ let apiToken = param.apiToken;
180
183
  let chain = param.chain;
181
184
  let name = "HyperFuel";
185
+ let apiToken$1 = apiToken !== undefined ? apiToken : Stdlib_JsError.throwWithMessage(`An Envio API token is required for using HyperFuel as a data-source.
186
+ Set the ENVIO_API_TOKEN environment variable in your .env file.
187
+ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
188
+ let client;
189
+ try {
190
+ client = HyperFuelClient.make({
191
+ url: param.endpointUrl,
192
+ apiToken: apiToken$1
193
+ });
194
+ } catch (raw_exn) {
195
+ let exn = Primitive_exceptions.internalToException(raw_exn);
196
+ client = ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate the HyperFuel client", exn);
197
+ }
182
198
  let getSelectionConfig = memoGetSelectionConfig(chain);
183
199
  let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, indexingAddresses, knownHeight, param, selection, retry, logger) => {
184
200
  let totalTimeRef = Hrtime.makeTimer();
@@ -188,10 +204,10 @@ function make(param) {
188
204
  Prometheus.SourceRequestCount.increment(name, chain, "getLogs");
189
205
  let pageUnsafe;
190
206
  try {
191
- pageUnsafe = await HyperFuel.GetLogs.query(endpointUrl, fromBlock, toBlock, recieptsSelection);
207
+ pageUnsafe = await HyperFuel.GetLogs.query(client, fromBlock, toBlock, recieptsSelection);
192
208
  } catch (raw_error) {
193
209
  let error = Primitive_exceptions.internalToException(raw_error);
194
- if (error.RE_EXN_ID === HyperSync.GetLogs.$$Error) {
210
+ if (error.RE_EXN_ID === HyperFuel.GetLogs.$$Error) {
195
211
  let error$1 = error._1;
196
212
  let tmp;
197
213
  if (typeof error$1 !== "object") {
@@ -339,7 +355,7 @@ function make(param) {
339
355
  blockNumber: block.height,
340
356
  blockHash: block.id,
341
357
  logIndex: receiptIndex,
342
- event: {
358
+ payload: {
343
359
  contractName: eventConfig$1.contractName,
344
360
  eventName: eventConfig$1.name,
345
361
  params: params,
@@ -388,7 +404,6 @@ function make(param) {
388
404
  };
389
405
  };
390
406
  let getBlockHashes = (param, param$1) => Stdlib_JsError.throwWithMessage("HyperFuel does not support getting block hashes");
391
- let jsonApiClient = EnvioApiClient.make(endpointUrl);
392
407
  return {
393
408
  name: name,
394
409
  sourceFor: "Sync",
@@ -398,7 +413,37 @@ function make(param) {
398
413
  getBlockHashes: getBlockHashes,
399
414
  getHeightOrThrow: async () => {
400
415
  let timerRef = Hrtime.makeTimer();
401
- let height = await Rest.fetch(HyperFuel.heightRoute, undefined, jsonApiClient);
416
+ let height;
417
+ try {
418
+ height = await client.getHeight();
419
+ } catch (raw_e) {
420
+ let e = Primitive_exceptions.internalToException(raw_e);
421
+ if (e.RE_EXN_ID === "JsExn") {
422
+ let e$1 = e._1;
423
+ let message = Stdlib_JsExn.message(e$1);
424
+ if (message !== undefined) {
425
+ if (message.includes("401 Unauthorized")) {
426
+ Logging.error(`Your ENVIO_API_TOKEN was rejected by HyperFuel (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`);
427
+ await new Promise((param, param$1) => {});
428
+ height = 0;
429
+ } else {
430
+ throw {
431
+ RE_EXN_ID: "JsExn",
432
+ _1: e$1,
433
+ Error: new Error()
434
+ };
435
+ }
436
+ } else {
437
+ throw {
438
+ RE_EXN_ID: "JsExn",
439
+ _1: e$1,
440
+ Error: new Error()
441
+ };
442
+ }
443
+ } else {
444
+ throw e;
445
+ }
446
+ }
402
447
  let seconds = Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef));
403
448
  Prometheus.SourceRequestCount.increment(name, chain, "getHeight");
404
449
  Prometheus.SourceRequestCount.addSeconds(name, chain, "getHeight", seconds);
@@ -410,6 +455,7 @@ function make(param) {
410
455
 
411
456
  export {
412
457
  EventRoutingFailed,
458
+ isUnauthorizedError,
413
459
  mintEventTag,
414
460
  burnEventTag,
415
461
  transferEventTag,
@@ -422,4 +468,4 @@ export {
422
468
  memoGetSelectionConfig,
423
469
  make,
424
470
  }
425
- /* Rest Not a pure module */
471
+ /* Logging Not a pure module */
@@ -206,16 +206,18 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
206
206
  blockNumber: block.number->Option.getUnsafe,
207
207
  blockHash: block.hash->Option.getUnsafe,
208
208
  logIndex,
209
- event: {
209
+ payload: {
210
210
  contractName: eventConfig.contractName,
211
211
  eventName: eventConfig.name,
212
212
  chainId,
213
213
  params,
214
- transaction,
214
+ transaction: transaction->(
215
+ Utils.magic: HyperSyncClient.ResponseTypes.transaction => Internal.eventTransaction
216
+ ),
215
217
  block: block->(Utils.magic: HyperSyncClient.ResponseTypes.block => Internal.eventBlock),
216
218
  srcAddress,
217
219
  logIndex,
218
- }->Internal.fromGenericEvent,
220
+ }->Evm.fromPayload,
219
221
  })
220
222
  }
221
223