envio 3.0.0-alpha.21 → 3.0.0-alpha.22

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 (219) hide show
  1. package/bin.mjs +2 -48
  2. package/evm.schema.json +67 -0
  3. package/fuel.schema.json +67 -0
  4. package/index.d.ts +822 -38
  5. package/index.js +5 -3
  6. package/package.json +10 -8
  7. package/rescript.json +5 -9
  8. package/src/Address.res +4 -5
  9. package/src/Address.res.mjs +9 -12
  10. package/src/Api.res +15 -0
  11. package/src/Api.res.mjs +20 -0
  12. package/src/Batch.res +32 -34
  13. package/src/Batch.res.mjs +172 -187
  14. package/src/Bin.res +89 -0
  15. package/src/Bin.res.mjs +97 -0
  16. package/src/ChainFetcher.res +33 -57
  17. package/src/ChainFetcher.res.mjs +197 -227
  18. package/src/ChainManager.res +6 -14
  19. package/src/ChainManager.res.mjs +74 -85
  20. package/src/ChainMap.res +14 -16
  21. package/src/ChainMap.res.mjs +38 -38
  22. package/src/Config.res +193 -135
  23. package/src/Config.res.mjs +566 -592
  24. package/src/Core.res +182 -0
  25. package/src/Core.res.mjs +207 -0
  26. package/src/Ecosystem.res +25 -4
  27. package/src/Ecosystem.res.mjs +12 -13
  28. package/src/Env.res +20 -13
  29. package/src/Env.res.mjs +124 -113
  30. package/src/EnvSafe.res +269 -0
  31. package/src/EnvSafe.res.mjs +296 -0
  32. package/src/EnvSafe.resi +18 -0
  33. package/src/Envio.res +37 -26
  34. package/src/Envio.res.mjs +59 -60
  35. package/src/ErrorHandling.res +2 -2
  36. package/src/ErrorHandling.res.mjs +15 -15
  37. package/src/EventConfigBuilder.res +219 -81
  38. package/src/EventConfigBuilder.res.mjs +259 -202
  39. package/src/EventProcessing.res +27 -38
  40. package/src/EventProcessing.res.mjs +165 -183
  41. package/src/EventUtils.res +11 -11
  42. package/src/EventUtils.res.mjs +21 -22
  43. package/src/EvmTypes.res +0 -1
  44. package/src/EvmTypes.res.mjs +5 -5
  45. package/src/FetchState.res +360 -256
  46. package/src/FetchState.res.mjs +958 -914
  47. package/src/GlobalState.res +365 -351
  48. package/src/GlobalState.res.mjs +958 -992
  49. package/src/GlobalStateManager.res +1 -2
  50. package/src/GlobalStateManager.res.mjs +36 -44
  51. package/src/HandlerLoader.res +107 -23
  52. package/src/HandlerLoader.res.mjs +128 -38
  53. package/src/HandlerRegister.res +127 -103
  54. package/src/HandlerRegister.res.mjs +164 -164
  55. package/src/HandlerRegister.resi +12 -4
  56. package/src/Hasura.res +35 -22
  57. package/src/Hasura.res.mjs +158 -167
  58. package/src/InMemoryStore.res +20 -27
  59. package/src/InMemoryStore.res.mjs +64 -80
  60. package/src/InMemoryTable.res +34 -39
  61. package/src/InMemoryTable.res.mjs +165 -170
  62. package/src/Internal.res +52 -33
  63. package/src/Internal.res.mjs +84 -81
  64. package/src/LazyLoader.res.mjs +55 -61
  65. package/src/LoadLayer.res +77 -78
  66. package/src/LoadLayer.res.mjs +160 -189
  67. package/src/LoadManager.res +16 -21
  68. package/src/LoadManager.res.mjs +79 -84
  69. package/src/LogSelection.res +236 -68
  70. package/src/LogSelection.res.mjs +211 -141
  71. package/src/Logging.res +13 -9
  72. package/src/Logging.res.mjs +130 -143
  73. package/src/Main.res +428 -51
  74. package/src/Main.res.mjs +528 -271
  75. package/src/Persistence.res +77 -84
  76. package/src/Persistence.res.mjs +131 -132
  77. package/src/PgStorage.res +291 -167
  78. package/src/PgStorage.res.mjs +797 -817
  79. package/src/Prometheus.res +50 -58
  80. package/src/Prometheus.res.mjs +345 -373
  81. package/src/ReorgDetection.res +22 -24
  82. package/src/ReorgDetection.res.mjs +100 -106
  83. package/src/SafeCheckpointTracking.res +7 -7
  84. package/src/SafeCheckpointTracking.res.mjs +40 -43
  85. package/src/SimulateItems.res +41 -49
  86. package/src/SimulateItems.res.mjs +257 -272
  87. package/src/Sink.res +2 -2
  88. package/src/Sink.res.mjs +22 -26
  89. package/src/TableIndices.res +1 -2
  90. package/src/TableIndices.res.mjs +42 -48
  91. package/src/TestIndexer.res +196 -189
  92. package/src/TestIndexer.res.mjs +536 -536
  93. package/src/TestIndexerProxyStorage.res +15 -16
  94. package/src/TestIndexerProxyStorage.res.mjs +98 -122
  95. package/src/TestIndexerWorker.res +4 -0
  96. package/src/TestIndexerWorker.res.mjs +7 -0
  97. package/src/Throttler.res +3 -3
  98. package/src/Throttler.res.mjs +23 -24
  99. package/src/Time.res +1 -1
  100. package/src/Time.res.mjs +18 -21
  101. package/src/TopicFilter.res +3 -3
  102. package/src/TopicFilter.res.mjs +29 -30
  103. package/src/UserContext.res +93 -54
  104. package/src/UserContext.res.mjs +197 -182
  105. package/src/Utils.res +141 -86
  106. package/src/Utils.res.mjs +334 -295
  107. package/src/bindings/BigDecimal.res +0 -2
  108. package/src/bindings/BigDecimal.res.mjs +19 -23
  109. package/src/bindings/ClickHouse.res +28 -27
  110. package/src/bindings/ClickHouse.res.mjs +243 -240
  111. package/src/bindings/DateFns.res +11 -11
  112. package/src/bindings/DateFns.res.mjs +7 -7
  113. package/src/bindings/EventSource.res.mjs +2 -2
  114. package/src/bindings/Express.res +2 -5
  115. package/src/bindings/Hrtime.res +2 -2
  116. package/src/bindings/Hrtime.res.mjs +30 -32
  117. package/src/bindings/Lodash.res.mjs +1 -1
  118. package/src/bindings/NodeJs.res +14 -9
  119. package/src/bindings/NodeJs.res.mjs +20 -20
  120. package/src/bindings/Pino.res +8 -10
  121. package/src/bindings/Pino.res.mjs +40 -43
  122. package/src/bindings/Postgres.res +2 -5
  123. package/src/bindings/Postgres.res.mjs +9 -9
  124. package/src/bindings/PromClient.res +17 -2
  125. package/src/bindings/PromClient.res.mjs +30 -7
  126. package/src/bindings/SDSL.res.mjs +2 -2
  127. package/src/bindings/Viem.res +4 -4
  128. package/src/bindings/Viem.res.mjs +20 -22
  129. package/src/bindings/Vitest.res +1 -1
  130. package/src/bindings/Vitest.res.mjs +2 -2
  131. package/src/bindings/WebSocket.res +1 -1
  132. package/src/db/EntityHistory.res +9 -3
  133. package/src/db/EntityHistory.res.mjs +84 -59
  134. package/src/db/InternalTable.res +62 -60
  135. package/src/db/InternalTable.res.mjs +271 -203
  136. package/src/db/Schema.res +1 -2
  137. package/src/db/Schema.res.mjs +28 -32
  138. package/src/db/Table.res +28 -27
  139. package/src/db/Table.res.mjs +276 -292
  140. package/src/sources/EventRouter.res +21 -16
  141. package/src/sources/EventRouter.res.mjs +55 -57
  142. package/src/sources/Evm.res +17 -1
  143. package/src/sources/Evm.res.mjs +16 -8
  144. package/src/sources/EvmChain.res +15 -17
  145. package/src/sources/EvmChain.res.mjs +40 -42
  146. package/src/sources/Fuel.res +14 -1
  147. package/src/sources/Fuel.res.mjs +16 -8
  148. package/src/sources/FuelSDK.res +1 -1
  149. package/src/sources/FuelSDK.res.mjs +6 -8
  150. package/src/sources/HyperFuel.res +8 -10
  151. package/src/sources/HyperFuel.res.mjs +113 -123
  152. package/src/sources/HyperFuelClient.res.mjs +6 -7
  153. package/src/sources/HyperFuelSource.res +19 -20
  154. package/src/sources/HyperFuelSource.res.mjs +339 -356
  155. package/src/sources/HyperSync.res +11 -13
  156. package/src/sources/HyperSync.res.mjs +206 -220
  157. package/src/sources/HyperSyncClient.res +5 -7
  158. package/src/sources/HyperSyncClient.res.mjs +70 -75
  159. package/src/sources/HyperSyncHeightStream.res +8 -9
  160. package/src/sources/HyperSyncHeightStream.res.mjs +78 -86
  161. package/src/sources/HyperSyncJsonApi.res +18 -15
  162. package/src/sources/HyperSyncJsonApi.res.mjs +201 -231
  163. package/src/sources/HyperSyncSource.res +17 -21
  164. package/src/sources/HyperSyncSource.res.mjs +268 -290
  165. package/src/sources/Rpc.res +5 -5
  166. package/src/sources/Rpc.res.mjs +168 -192
  167. package/src/sources/RpcSource.res +166 -167
  168. package/src/sources/RpcSource.res.mjs +972 -1046
  169. package/src/sources/RpcWebSocketHeightStream.res +10 -11
  170. package/src/sources/RpcWebSocketHeightStream.res.mjs +131 -145
  171. package/src/sources/SimulateSource.res +1 -1
  172. package/src/sources/SimulateSource.res.mjs +35 -38
  173. package/src/sources/Source.res +1 -1
  174. package/src/sources/Source.res.mjs +3 -3
  175. package/src/sources/SourceManager.res +39 -20
  176. package/src/sources/SourceManager.res.mjs +340 -371
  177. package/src/sources/SourceManager.resi +2 -1
  178. package/src/sources/Svm.res +12 -5
  179. package/src/sources/Svm.res.mjs +44 -41
  180. package/src/tui/Tui.res +23 -12
  181. package/src/tui/Tui.res.mjs +292 -290
  182. package/src/tui/bindings/Ink.res +2 -4
  183. package/src/tui/bindings/Ink.res.mjs +35 -41
  184. package/src/tui/components/BufferedProgressBar.res +7 -7
  185. package/src/tui/components/BufferedProgressBar.res.mjs +46 -46
  186. package/src/tui/components/CustomHooks.res +1 -2
  187. package/src/tui/components/CustomHooks.res.mjs +102 -122
  188. package/src/tui/components/Messages.res +1 -2
  189. package/src/tui/components/Messages.res.mjs +38 -42
  190. package/src/tui/components/SyncETA.res +10 -11
  191. package/src/tui/components/SyncETA.res.mjs +178 -196
  192. package/src/tui/components/TuiData.res +1 -1
  193. package/src/tui/components/TuiData.res.mjs +7 -6
  194. package/src/vendored/Rest.res +52 -66
  195. package/src/vendored/Rest.res.mjs +324 -364
  196. package/svm.schema.json +67 -0
  197. package/src/Address.gen.ts +0 -8
  198. package/src/Config.gen.ts +0 -19
  199. package/src/Envio.gen.ts +0 -55
  200. package/src/EvmTypes.gen.ts +0 -6
  201. package/src/InMemoryStore.gen.ts +0 -6
  202. package/src/Internal.gen.ts +0 -64
  203. package/src/PgStorage.gen.ts +0 -10
  204. package/src/PgStorage.res.d.mts +0 -5
  205. package/src/Types.ts +0 -56
  206. package/src/bindings/BigDecimal.gen.ts +0 -14
  207. package/src/bindings/BigDecimal.res.d.mts +0 -5
  208. package/src/bindings/BigInt.gen.ts +0 -10
  209. package/src/bindings/BigInt.res +0 -70
  210. package/src/bindings/BigInt.res.d.mts +0 -5
  211. package/src/bindings/BigInt.res.mjs +0 -154
  212. package/src/bindings/Ethers.res.d.mts +0 -5
  213. package/src/bindings/Pino.gen.ts +0 -17
  214. package/src/bindings/Postgres.gen.ts +0 -8
  215. package/src/bindings/Postgres.res.d.mts +0 -5
  216. package/src/bindings/Promise.res +0 -67
  217. package/src/bindings/Promise.res.mjs +0 -26
  218. package/src/db/InternalTable.gen.ts +0 -36
  219. package/src/sources/HyperSyncClient.gen.ts +0 -19
@@ -1,18 +1,16 @@
1
- open Belt
2
-
3
1
  //Manage clients in cache so we don't need to reinstantiate each time
4
2
  //Ideally client should be passed in as a param to the functions but
5
3
  //we are still sharing the same signature with eth archive query builder
6
4
 
7
5
  module CachedClients = {
8
- let cache: Js.Dict.t<HyperFuelClient.t> = Js.Dict.empty()
6
+ let cache: dict<HyperFuelClient.t> = Dict.make()
9
7
 
10
8
  let getClient = url => {
11
9
  switch cache->Utils.Dict.dangerouslyGetNonOption(url) {
12
10
  | Some(client) => client
13
11
  | None =>
14
12
  let newClient = HyperFuelClient.make({url: url})
15
- cache->Js.Dict.set(url, newClient)
13
+ cache->Dict.set(url, newClient)
16
14
  newClient
17
15
  }
18
16
  }
@@ -55,7 +53,7 @@ let queryErrorToMsq = (e: queryError): string => {
55
53
  switch e {
56
54
  | UnexpectedMissingParams({queryName, missingParams}) =>
57
55
  `${queryName} query failed due to unexpected missing params on response:
58
- ${missingParams->Js.Array2.joinWith(", ")}`
56
+ ${missingParams->Array.joinUnsafe(", ")}`
59
57
  }
60
58
  }
61
59
 
@@ -106,7 +104,7 @@ module GetLogs = {
106
104
  switch param {
107
105
  | Some(v) => v
108
106
  | None =>
109
- raise(
107
+ throw(
110
108
  Error(
111
109
  UnexpectedMissingParams({
112
110
  missingParams: [name],
@@ -122,11 +120,11 @@ module GetLogs = {
122
120
  > => {
123
121
  let {receipts, blocks} = response_data
124
122
 
125
- let blocksDict = Js.Dict.empty()
123
+ let blocksDict = Dict.make()
126
124
  blocks
127
125
  ->(Utils.magic: option<'a> => 'a)
128
126
  ->Array.forEach(block => {
129
- blocksDict->Js.Dict.set(block.height->(Utils.magic: int => string), block)
127
+ blocksDict->Dict.set(block.height->(Utils.magic: int => string), block)
130
128
  })
131
129
 
132
130
  let items = []
@@ -163,7 +161,7 @@ module GetLogs = {
163
161
  let page: logsQueryPage = {
164
162
  items: res.data->decodeLogQueryPageItems,
165
163
  nextBlock,
166
- archiveHeight: archiveHeight->Option.getWithDefault(0), // TODO: FIXME: Shouldn't have a default here
164
+ archiveHeight: archiveHeight->Option.getOr(0), // TODO: FIXME: Shouldn't have a default here
167
165
  }
168
166
  page
169
167
  }
@@ -180,7 +178,7 @@ module GetLogs = {
180
178
  let res = await hyperFuelClient->HyperFuelClient.getSelectedData(query)
181
179
  if res.nextBlock <= fromBlock {
182
180
  // Might happen when /height response was from another instance of HyperSync
183
- raise(Error(WrongInstance))
181
+ throw(Error(WrongInstance))
184
182
  }
185
183
  res->convertResponse
186
184
  }
@@ -2,136 +2,136 @@
2
2
 
3
3
  import * as Time from "../Time.res.mjs";
4
4
  import * as Logging from "../Logging.res.mjs";
5
- import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
6
- import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
7
- import * as Caml_option from "rescript/lib/es6/caml_option.js";
8
- import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
5
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
9
6
  import * as HyperFuelClient from "./HyperFuelClient.res.mjs";
7
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
10
8
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
9
+ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
11
10
 
12
- var cache = {};
11
+ let cache = {};
13
12
 
14
13
  function getClient(url) {
15
- var client = cache[url];
14
+ let client = cache[url];
16
15
  if (client !== undefined) {
17
- return Caml_option.valFromOption(client);
16
+ return Primitive_option.valFromOption(client);
18
17
  }
19
- var newClient = HyperFuelClient.make({
20
- url: url
21
- });
18
+ let newClient = HyperFuelClient.make({
19
+ url: url
20
+ });
22
21
  cache[url] = newClient;
23
22
  return newClient;
24
23
  }
25
24
 
26
25
  function queryErrorToMsq(e) {
27
- var match = e._0;
28
- return match.queryName + " query failed due to unexpected missing params on response:\n " + match.missingParams.join(", ");
26
+ let match = e._0;
27
+ return match.queryName + ` query failed due to unexpected missing params on response:
28
+ ` + match.missingParams.join(", ");
29
29
  }
30
30
 
31
- var $$Error = /* @__PURE__ */Caml_exceptions.create("HyperFuel.GetLogs.Error");
31
+ let $$Error = /* @__PURE__ */Primitive_exceptions.create("HyperFuel.GetLogs.Error");
32
32
 
33
33
  function makeRequestBody(fromBlock, toBlockInclusive, recieptsSelection) {
34
34
  return {
35
- fromBlock: fromBlock,
36
- toBlock: toBlockInclusive !== undefined ? toBlockInclusive + 1 | 0 : undefined,
37
- receipts: recieptsSelection,
38
- fieldSelection: {
39
- block: [
40
- "id",
41
- "height",
42
- "time"
43
- ],
44
- receipt: [
45
- "tx_id",
46
- "block_height",
47
- "root_contract_id",
48
- "data",
49
- "receipt_index",
50
- "receipt_type",
51
- "rb",
52
- "sub_id",
53
- "val",
54
- "amount",
55
- "to_address",
56
- "asset_id",
57
- "to"
58
- ]
59
- }
60
- };
35
+ fromBlock: fromBlock,
36
+ toBlock: toBlockInclusive !== undefined ? toBlockInclusive + 1 | 0 : undefined,
37
+ receipts: recieptsSelection,
38
+ fieldSelection: {
39
+ block: [
40
+ "id",
41
+ "height",
42
+ "time"
43
+ ],
44
+ receipt: [
45
+ "tx_id",
46
+ "block_height",
47
+ "root_contract_id",
48
+ "data",
49
+ "receipt_index",
50
+ "receipt_type",
51
+ "rb",
52
+ "sub_id",
53
+ "val",
54
+ "amount",
55
+ "to_address",
56
+ "asset_id",
57
+ "to"
58
+ ]
59
+ }
60
+ };
61
61
  }
62
62
 
63
63
  function getParam(param, name) {
64
64
  if (param !== undefined) {
65
- return Caml_option.valFromOption(param);
65
+ return Primitive_option.valFromOption(param);
66
66
  }
67
67
  throw {
68
- RE_EXN_ID: $$Error,
69
- _1: {
70
- TAG: "UnexpectedMissingParams",
71
- missingParams: [name]
72
- },
73
- Error: new Error()
74
- };
68
+ RE_EXN_ID: $$Error,
69
+ _1: {
70
+ TAG: "UnexpectedMissingParams",
71
+ missingParams: [name]
72
+ },
73
+ Error: new Error()
74
+ };
75
75
  }
76
76
 
77
77
  function decodeLogQueryPageItems(response_data) {
78
- var blocksDict = {};
79
- Belt_Array.forEach(response_data.blocks, (function (block) {
80
- blocksDict[block.height] = block;
81
- }));
82
- var items = [];
83
- Belt_Array.forEach(response_data.receipts, (function (receipt) {
84
- var contractId = receipt.rootContractId;
85
- if (contractId === undefined) {
86
- return ;
87
- }
88
- var block = getParam(blocksDict[receipt.blockHeight], "Failed to find block associated to receipt");
89
- items.push({
90
- transactionId: receipt.txId,
91
- contractId: Caml_option.valFromOption(contractId),
92
- receipt: receipt,
93
- receiptIndex: receipt.receiptIndex,
94
- block: {
95
- id: block.id,
96
- time: block.time,
97
- height: block.height
98
- }
99
- });
100
- }));
78
+ let blocksDict = {};
79
+ response_data.blocks.forEach(block => {
80
+ blocksDict[block.height] = block;
81
+ });
82
+ let items = [];
83
+ response_data.receipts.forEach(receipt => {
84
+ let contractId = receipt.rootContractId;
85
+ if (contractId === undefined) {
86
+ return;
87
+ }
88
+ let block = getParam(blocksDict[receipt.blockHeight], "Failed to find block associated to receipt");
89
+ items.push({
90
+ transactionId: receipt.txId,
91
+ contractId: Primitive_option.valFromOption(contractId),
92
+ receipt: receipt,
93
+ receiptIndex: receipt.receiptIndex,
94
+ block: {
95
+ id: block.id,
96
+ time: block.time,
97
+ height: block.height
98
+ }
99
+ });
100
+ });
101
101
  return items;
102
102
  }
103
103
 
104
104
  async function query(serverUrl, fromBlock, toBlock, recieptsSelection) {
105
- var query$1 = makeRequestBody(fromBlock, toBlock, recieptsSelection);
106
- var hyperFuelClient = getClient(serverUrl);
107
- var res = await hyperFuelClient.getSelectedData(query$1);
105
+ let query$1 = makeRequestBody(fromBlock, toBlock, recieptsSelection);
106
+ let hyperFuelClient = getClient(serverUrl);
107
+ let res = await hyperFuelClient.getSelectedData(query$1);
108
108
  if (res.nextBlock <= fromBlock) {
109
109
  throw {
110
- RE_EXN_ID: $$Error,
111
- _1: "WrongInstance",
112
- Error: new Error()
113
- };
110
+ RE_EXN_ID: $$Error,
111
+ _1: "WrongInstance",
112
+ Error: new Error()
113
+ };
114
114
  }
115
115
  return {
116
- items: decodeLogQueryPageItems(res.data),
117
- nextBlock: res.nextBlock,
118
- archiveHeight: Belt_Option.getWithDefault(res.archiveHeight, 0)
119
- };
116
+ items: decodeLogQueryPageItems(res.data),
117
+ nextBlock: res.nextBlock,
118
+ archiveHeight: Stdlib_Option.getOr(res.archiveHeight, 0)
119
+ };
120
120
  }
121
121
 
122
122
  async function queryBlockData(serverUrl, blockNumber, logger) {
123
- var query_toBlock = blockNumber + 1 | 0;
124
- var query_inputs = [{}];
125
- var query_outputs = [{}];
126
- var query_includeAllBlocks = true;
127
- var query_fieldSelection = {
123
+ let query_toBlock = blockNumber + 1 | 0;
124
+ let query_inputs = [{}];
125
+ let query_outputs = [{}];
126
+ let query_includeAllBlocks = true;
127
+ let query_fieldSelection = {
128
128
  block: [
129
129
  "height",
130
130
  "id",
131
131
  "time"
132
132
  ]
133
133
  };
134
- var query = {
134
+ let query = {
135
135
  fromBlock: blockNumber,
136
136
  toBlock: query_toBlock,
137
137
  inputs: query_inputs,
@@ -139,56 +139,46 @@ async function queryBlockData(serverUrl, blockNumber, logger) {
139
139
  includeAllBlocks: query_includeAllBlocks,
140
140
  fieldSelection: query_fieldSelection
141
141
  };
142
- var hyperFuelClient = getClient(serverUrl);
143
- var logger$1 = Logging.createChildFrom(logger, {
144
- logType: "hypersync get blockhash query",
145
- blockNumber: blockNumber
146
- });
147
- var executeQuery = function () {
148
- return hyperFuelClient.getSelectedData(query);
149
- };
150
- var res = await Time.retryAsyncWithExponentialBackOff(undefined, undefined, undefined, undefined, logger$1, executeQuery);
142
+ let hyperFuelClient = getClient(serverUrl);
143
+ let logger$1 = Logging.createChildFrom(logger, {
144
+ logType: "hypersync get blockhash query",
145
+ blockNumber: blockNumber
146
+ });
147
+ let executeQuery = () => hyperFuelClient.getSelectedData(query);
148
+ let res = await Time.retryAsyncWithExponentialBackOff(undefined, undefined, undefined, undefined, logger$1, executeQuery);
151
149
  if (res.nextBlock > blockNumber) {
152
- return Belt_Option.flatMap(res.data.blocks, (function (blocks) {
153
- return Belt_Option.map(Belt_Array.get(blocks, 0), (function (block) {
154
- return {
155
- blockHash: block.id,
156
- blockNumber: block.height,
157
- blockTimestamp: block.time
158
- };
159
- }));
160
- }));
150
+ return Stdlib_Option.flatMap(res.data.blocks, blocks => Stdlib_Option.map(blocks[0], block => ({
151
+ blockHash: block.id,
152
+ blockNumber: block.height,
153
+ blockTimestamp: block.time
154
+ })));
161
155
  }
162
- var logger$2 = Logging.createChild({
163
- url: serverUrl
164
- });
165
- Logging.childInfo(logger$2, "Block #" + String(blockNumber) + " not found in HyperFuel. HyperFuel has multiple instances and it's possible that they drift independently slightly from the head. Indexing should continue correctly after retrying the query in " + String(100) + "ms.");
156
+ let logger$2 = Logging.createChild({
157
+ url: serverUrl
158
+ });
159
+ Logging.childInfo(logger$2, `Block #` + blockNumber.toString() + ` not found in HyperFuel. HyperFuel has multiple instances and it's possible that they drift independently slightly from the head. Indexing should continue correctly after retrying the query in ` + (100).toString() + `ms.`);
166
160
  await Time.resolvePromiseAfterDelay(100);
167
161
  return await queryBlockData(serverUrl, blockNumber, logger$2);
168
162
  }
169
163
 
170
164
  function heightRoute() {
171
165
  return {
172
- method: "GET",
173
- path: "/height",
174
- input: (function (param) {
175
-
176
- }),
177
- responses: [(function (s) {
178
- return s.field("height", S$RescriptSchema.$$int);
179
- })]
180
- };
166
+ method: "GET",
167
+ path: "/height",
168
+ input: param => {},
169
+ responses: [s => s.field("height", S$RescriptSchema.int)]
170
+ };
181
171
  }
182
172
 
183
- var GetLogs = {
173
+ let GetLogs = {
184
174
  $$Error: $$Error,
185
175
  query: query
186
176
  };
187
177
 
188
178
  export {
189
- queryErrorToMsq ,
190
- GetLogs ,
191
- queryBlockData ,
192
- heightRoute ,
179
+ queryErrorToMsq,
180
+ GetLogs,
181
+ queryBlockData,
182
+ heightRoute,
193
183
  }
194
184
  /* Time Not a pure module */
@@ -1,20 +1,19 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
4
3
  import * as HyperfuelClient from "@envio-dev/hyperfuel-client";
5
4
 
6
- var QueryTypes = {};
5
+ let QueryTypes = {};
7
6
 
8
- var FuelTypes = {};
7
+ let FuelTypes = {};
9
8
 
10
9
  function make(cfg) {
11
- var newrecord = Caml_obj.obj_dup(cfg);
10
+ let newrecord = {...cfg};
12
11
  return HyperfuelClient.HyperfuelClient.new((newrecord.bearerToken = "3dc856dd-b0ea-494f-b27e-017b8b6b7e07", newrecord));
13
12
  }
14
13
 
15
14
  export {
16
- QueryTypes ,
17
- FuelTypes ,
18
- make ,
15
+ QueryTypes,
16
+ FuelTypes,
17
+ make,
19
18
  }
20
19
  /* @envio-dev/hyperfuel-client Not a pure module */
@@ -1,5 +1,4 @@
1
1
  open Source
2
- open Belt
3
2
 
4
3
  exception EventRoutingFailed
5
4
 
@@ -39,7 +38,7 @@ let makeGetNormalRecieptsSelection = (
39
38
  ) {
40
39
  | Some(receiptTypes) =>
41
40
  selection
42
- ->Js.Array2.push({
41
+ ->Array.push({
43
42
  rootContractId: addresses,
44
43
  receiptType: receiptTypes,
45
44
  txStatus: txStatusSelection,
@@ -52,7 +51,7 @@ let makeGetNormalRecieptsSelection = (
52
51
  | Some([]) => ()
53
52
  | Some(nonWildcardLogDataRbs) =>
54
53
  selection
55
- ->Js.Array2.push({
54
+ ->Array.push({
56
55
  rootContractId: addresses,
57
56
  receiptType: logDataReceiptTypeSelection,
58
57
  txStatus: txStatusSelection,
@@ -75,7 +74,7 @@ let makeWildcardRecieptsSelection = (~wildcardLogDataRbs, ~nonLogDataWildcardRec
75
74
  | [] => ()
76
75
  | nonLogDataWildcardReceiptTypes =>
77
76
  selection
78
- ->Js.Array2.push(
77
+ ->Array.push(
79
78
  (
80
79
  {
81
80
  receiptType: nonLogDataWildcardReceiptTypes,
@@ -90,7 +89,7 @@ let makeWildcardRecieptsSelection = (~wildcardLogDataRbs, ~nonLogDataWildcardRec
90
89
  | [] => ()
91
90
  | wildcardLogDataRbs =>
92
91
  selection
93
- ->Js.Array2.push(
92
+ ->Array.push(
94
93
  (
95
94
  {
96
95
  receiptType: logDataReceiptTypeSelection,
@@ -107,11 +106,11 @@ let makeWildcardRecieptsSelection = (~wildcardLogDataRbs, ~nonLogDataWildcardRec
107
106
 
108
107
  let getSelectionConfig = (selection: FetchState.selection, ~chain) => {
109
108
  let eventRouter = EventRouter.empty()
110
- let nonWildcardLogDataRbsByContract = Js.Dict.empty()
109
+ let nonWildcardLogDataRbsByContract = Dict.make()
111
110
  let wildcardLogDataRbs = []
112
111
 
113
112
  // This is for non-LogData events, since they don't have rb filter and can be grouped
114
- let nonLogDataReceiptTypesByContract = Js.Dict.empty()
113
+ let nonLogDataReceiptTypesByContract = Dict.make()
115
114
  let nonLogDataWildcardReceiptTypes = []
116
115
 
117
116
  let addNonLogDataWildcardReceiptTypes = (receiptType: FuelSDK.receiptType) => {
@@ -119,7 +118,7 @@ let getSelectionConfig = (selection: FetchState.selection, ~chain) => {
119
118
  }
120
119
  let addNonLogDataReceiptType = (contractName, receiptType: FuelSDK.receiptType) => {
121
120
  switch nonLogDataReceiptTypesByContract->Utils.Dict.dangerouslyGetNonOption(contractName) {
122
- | None => nonLogDataReceiptTypesByContract->Js.Dict.set(contractName, [receiptType])
121
+ | None => nonLogDataReceiptTypesByContract->Dict.set(contractName, [receiptType])
123
122
  | Some(receiptTypes) => receiptTypes->Array.push(receiptType)->ignore // Duplication prevented by EventRouter
124
123
  }
125
124
  }
@@ -157,15 +156,15 @@ let getSelectionConfig = (selection: FetchState.selection, ~chain) => {
157
156
  }
158
157
  | {kind: Call, isWildcard: true} => addNonLogDataWildcardReceiptTypes(Call)
159
158
  | {kind: Call} =>
160
- Js.Exn.raiseError("Call receipt indexing currently supported only in wildcard mode")
159
+ JsError.throwWithMessage("Call receipt indexing currently supported only in wildcard mode")
161
160
  | {kind: LogData({logId}), isWildcard} => {
162
- let rb = logId->BigInt.fromStringUnsafe
161
+ let rb = logId->BigInt.fromStringOrThrow
163
162
  if isWildcard {
164
163
  wildcardLogDataRbs->Array.push(rb)->ignore
165
164
  } else {
166
165
  switch nonWildcardLogDataRbsByContract->Utils.Dict.dangerouslyGetNonOption(contractName) {
167
166
  | Some(arr) => arr->Belt.Array.push(rb)
168
- | None => nonWildcardLogDataRbsByContract->Js.Dict.set(contractName, [rb])
167
+ | None => nonWildcardLogDataRbsByContract->Dict.set(contractName, [rb])
169
168
  }
170
169
  }
171
170
  }
@@ -219,7 +218,7 @@ let make = ({chain, endpointUrl}: options): t => {
219
218
  ~fromBlock,
220
219
  ~toBlock,
221
220
  ~addressesByContractName,
222
- ~indexingContracts,
221
+ ~indexingAddresses,
223
222
  ~knownHeight,
224
223
  ~partitionId as _,
225
224
  ~selection: FetchState.selection,
@@ -247,11 +246,11 @@ let make = ({chain, endpointUrl}: options): t => {
247
246
  ~recieptsSelection,
248
247
  ) catch {
249
248
  | HyperSync.GetLogs.Error(error) =>
250
- raise(
249
+ throw(
251
250
  Source.GetItemsError(
252
251
  Source.FailedGettingItems({
253
252
  exn: %raw(`null`),
254
- attemptedToBlock: toBlock->Option.getWithDefault(knownHeight),
253
+ attemptedToBlock: toBlock->Option.getOr(knownHeight),
255
254
  retry: switch error {
256
255
  | WrongInstance =>
257
256
  let backoffMillis = switch retry {
@@ -264,7 +263,7 @@ let make = ({chain, endpointUrl}: options): t => {
264
263
  })
265
264
  | UnexpectedMissingParams({missingParams}) =>
266
265
  ImpossibleForTheQuery({
267
- message: `Source returned invalid data with missing required fields: ${missingParams->Js.Array2.joinWith(
266
+ message: `Source returned invalid data with missing required fields: ${missingParams->Array.joinUnsafe(
268
267
  ", ",
269
268
  )}`,
270
269
  })
@@ -273,11 +272,11 @@ let make = ({chain, endpointUrl}: options): t => {
273
272
  ),
274
273
  )
275
274
  | exn =>
276
- raise(
275
+ throw(
277
276
  Source.GetItemsError(
278
277
  Source.FailedGettingItems({
279
278
  exn,
280
- attemptedToBlock: toBlock->Option.getWithDefault(knownHeight),
279
+ attemptedToBlock: toBlock->Option.getOr(knownHeight),
281
280
  retry: WithBackoff({
282
281
  message: `Unexpected issue while fetching events from HyperFuel client. Attempt a retry.`,
283
282
  backoffMillis: switch retry {
@@ -366,7 +365,7 @@ let make = ({chain, endpointUrl}: options): t => {
366
365
 
367
366
  let eventConfig = switch selectionConfig.eventRouter->EventRouter.get(
368
367
  ~tag=eventId,
369
- ~indexingContracts,
368
+ ~indexingAddresses,
370
369
  ~contractAddress,
371
370
  ~blockNumber=block.height,
372
371
  ) {
@@ -438,7 +437,7 @@ let make = ({chain, endpointUrl}: options): t => {
438
437
  }: Internal.fuelTransferParams
439
438
  )->Obj.magic
440
439
  // This should never happen unless there's a bug in the routing logic
441
- | _ => Js.Exn.raiseError("Unexpected bug in the event routing logic")
440
+ | _ => JsError.throwWithMessage("Unexpected bug in the event routing logic")
442
441
  }
443
442
 
444
443
  Internal.Event({
@@ -491,7 +490,7 @@ let make = ({chain, endpointUrl}: options): t => {
491
490
  }
492
491
 
493
492
  let getBlockHashes = (~blockNumbers as _, ~logger as _) =>
494
- Js.Exn.raiseError("HyperFuel does not support getting block hashes")
493
+ JsError.throwWithMessage("HyperFuel does not support getting block hashes")
495
494
 
496
495
  let jsonApiClient = Rest.client(endpointUrl)
497
496