envio 3.0.0-alpha.2 → 3.0.0-alpha.20

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 (175) hide show
  1. package/README.md +164 -30
  2. package/bin.mjs +49 -0
  3. package/evm.schema.json +79 -169
  4. package/fuel.schema.json +50 -21
  5. package/index.d.ts +497 -1
  6. package/index.js +4 -0
  7. package/package.json +42 -31
  8. package/rescript.json +4 -1
  9. package/src/Batch.res +11 -8
  10. package/src/Batch.res.mjs +11 -9
  11. package/src/ChainFetcher.res +531 -0
  12. package/src/ChainFetcher.res.mjs +339 -0
  13. package/src/ChainManager.res +190 -0
  14. package/src/ChainManager.res.mjs +166 -0
  15. package/src/Change.res +3 -3
  16. package/src/Config.gen.ts +19 -0
  17. package/src/Config.res +737 -22
  18. package/src/Config.res.mjs +703 -26
  19. package/src/{Indexer.res → Ctx.res} +1 -1
  20. package/src/Ecosystem.res +9 -124
  21. package/src/Ecosystem.res.mjs +19 -160
  22. package/src/Env.res +30 -74
  23. package/src/Env.res.mjs +25 -87
  24. package/src/Envio.gen.ts +3 -1
  25. package/src/Envio.res +20 -9
  26. package/src/EventProcessing.res +469 -0
  27. package/src/EventProcessing.res.mjs +337 -0
  28. package/src/EvmTypes.gen.ts +6 -0
  29. package/src/EvmTypes.res +1 -0
  30. package/src/FetchState.res +1256 -639
  31. package/src/FetchState.res.mjs +1135 -612
  32. package/src/GlobalState.res +1190 -0
  33. package/src/GlobalState.res.mjs +1183 -0
  34. package/src/GlobalStateManager.res +68 -0
  35. package/src/GlobalStateManager.res.mjs +75 -0
  36. package/src/GlobalStateManager.resi +7 -0
  37. package/src/HandlerLoader.res +89 -0
  38. package/src/HandlerLoader.res.mjs +79 -0
  39. package/src/HandlerRegister.res +357 -0
  40. package/src/HandlerRegister.res.mjs +299 -0
  41. package/src/{EventRegister.resi → HandlerRegister.resi} +13 -13
  42. package/src/Hasura.res +111 -175
  43. package/src/Hasura.res.mjs +88 -150
  44. package/src/InMemoryStore.res +1 -1
  45. package/src/InMemoryStore.res.mjs +3 -3
  46. package/src/InMemoryTable.res +1 -1
  47. package/src/InMemoryTable.res.mjs +1 -1
  48. package/src/Internal.gen.ts +4 -0
  49. package/src/Internal.res +230 -12
  50. package/src/Internal.res.mjs +115 -1
  51. package/src/LoadLayer.res +444 -0
  52. package/src/LoadLayer.res.mjs +296 -0
  53. package/src/LoadLayer.resi +32 -0
  54. package/src/LogSelection.res +33 -27
  55. package/src/LogSelection.res.mjs +6 -0
  56. package/src/Logging.res +21 -7
  57. package/src/Logging.res.mjs +16 -8
  58. package/src/Main.res +377 -0
  59. package/src/Main.res.mjs +339 -0
  60. package/src/Persistence.res +7 -21
  61. package/src/Persistence.res.mjs +3 -3
  62. package/src/PgStorage.gen.ts +10 -0
  63. package/src/PgStorage.res +116 -69
  64. package/src/PgStorage.res.d.mts +5 -0
  65. package/src/PgStorage.res.mjs +93 -50
  66. package/src/Prometheus.res +294 -224
  67. package/src/Prometheus.res.mjs +353 -340
  68. package/src/ReorgDetection.res +6 -10
  69. package/src/ReorgDetection.res.mjs +6 -6
  70. package/src/SafeCheckpointTracking.res +4 -4
  71. package/src/SafeCheckpointTracking.res.mjs +2 -2
  72. package/src/Sink.res +4 -2
  73. package/src/Sink.res.mjs +2 -1
  74. package/src/TableIndices.res +0 -1
  75. package/src/TestIndexer.res +692 -0
  76. package/src/TestIndexer.res.mjs +527 -0
  77. package/src/TestIndexerProxyStorage.res +205 -0
  78. package/src/TestIndexerProxyStorage.res.mjs +151 -0
  79. package/src/TopicFilter.res +1 -1
  80. package/src/Types.ts +1 -1
  81. package/src/UserContext.res +424 -0
  82. package/src/UserContext.res.mjs +279 -0
  83. package/src/Utils.res +97 -26
  84. package/src/Utils.res.mjs +91 -44
  85. package/src/bindings/BigInt.res +10 -0
  86. package/src/bindings/BigInt.res.mjs +15 -0
  87. package/src/bindings/ClickHouse.res +120 -23
  88. package/src/bindings/ClickHouse.res.mjs +118 -28
  89. package/src/bindings/DateFns.res +74 -0
  90. package/src/bindings/DateFns.res.mjs +22 -0
  91. package/src/bindings/EventSource.res +8 -1
  92. package/src/bindings/EventSource.res.mjs +8 -1
  93. package/src/bindings/Express.res +1 -0
  94. package/src/bindings/Hrtime.res +14 -1
  95. package/src/bindings/Hrtime.res.mjs +22 -2
  96. package/src/bindings/Hrtime.resi +4 -0
  97. package/src/bindings/Lodash.res +0 -1
  98. package/src/bindings/NodeJs.res +49 -3
  99. package/src/bindings/NodeJs.res.mjs +11 -3
  100. package/src/bindings/Pino.res +24 -10
  101. package/src/bindings/Pino.res.mjs +14 -8
  102. package/src/bindings/Postgres.gen.ts +8 -0
  103. package/src/bindings/Postgres.res +5 -1
  104. package/src/bindings/Postgres.res.d.mts +5 -0
  105. package/src/bindings/PromClient.res +0 -10
  106. package/src/bindings/PromClient.res.mjs +0 -3
  107. package/src/bindings/Vitest.res +142 -0
  108. package/src/bindings/Vitest.res.mjs +9 -0
  109. package/src/bindings/WebSocket.res +27 -0
  110. package/src/bindings/WebSocket.res.mjs +2 -0
  111. package/src/bindings/Yargs.res +8 -0
  112. package/src/bindings/Yargs.res.mjs +2 -0
  113. package/src/db/EntityHistory.res +7 -7
  114. package/src/db/EntityHistory.res.mjs +9 -9
  115. package/src/db/InternalTable.res +59 -111
  116. package/src/db/InternalTable.res.mjs +73 -104
  117. package/src/db/Table.res +27 -8
  118. package/src/db/Table.res.mjs +25 -14
  119. package/src/sources/Evm.res +84 -0
  120. package/src/sources/Evm.res.mjs +105 -0
  121. package/src/sources/EvmChain.res +94 -0
  122. package/src/sources/EvmChain.res.mjs +60 -0
  123. package/src/sources/Fuel.res +19 -34
  124. package/src/sources/Fuel.res.mjs +34 -16
  125. package/src/sources/FuelSDK.res +38 -0
  126. package/src/sources/FuelSDK.res.mjs +29 -0
  127. package/src/sources/HyperFuel.res +2 -2
  128. package/src/sources/HyperFuel.resi +1 -1
  129. package/src/sources/HyperFuelClient.res +2 -2
  130. package/src/sources/HyperFuelSource.res +33 -13
  131. package/src/sources/HyperFuelSource.res.mjs +24 -16
  132. package/src/sources/HyperSync.res +36 -6
  133. package/src/sources/HyperSync.res.mjs +9 -7
  134. package/src/sources/HyperSync.resi +4 -0
  135. package/src/sources/HyperSyncClient.res +1 -1
  136. package/src/sources/HyperSyncHeightStream.res +47 -116
  137. package/src/sources/HyperSyncHeightStream.res.mjs +46 -73
  138. package/src/sources/HyperSyncSource.res +118 -139
  139. package/src/sources/HyperSyncSource.res.mjs +104 -121
  140. package/src/sources/Rpc.res +86 -14
  141. package/src/sources/Rpc.res.mjs +101 -9
  142. package/src/sources/RpcSource.res +621 -364
  143. package/src/sources/RpcSource.res.mjs +843 -410
  144. package/src/sources/RpcWebSocketHeightStream.res +181 -0
  145. package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
  146. package/src/sources/Source.res +7 -5
  147. package/src/sources/SourceManager.res +325 -225
  148. package/src/sources/SourceManager.res.mjs +314 -171
  149. package/src/sources/SourceManager.resi +17 -6
  150. package/src/sources/Svm.res +81 -0
  151. package/src/sources/Svm.res.mjs +90 -0
  152. package/src/tui/Tui.res +247 -0
  153. package/src/tui/Tui.res.mjs +337 -0
  154. package/src/tui/bindings/Ink.res +371 -0
  155. package/src/tui/bindings/Ink.res.mjs +72 -0
  156. package/src/tui/bindings/Style.res +123 -0
  157. package/src/tui/bindings/Style.res.mjs +2 -0
  158. package/src/tui/components/BufferedProgressBar.res +40 -0
  159. package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
  160. package/src/tui/components/CustomHooks.res +122 -0
  161. package/src/tui/components/CustomHooks.res.mjs +179 -0
  162. package/src/tui/components/Messages.res +41 -0
  163. package/src/tui/components/Messages.res.mjs +75 -0
  164. package/src/tui/components/SyncETA.res +174 -0
  165. package/src/tui/components/SyncETA.res.mjs +263 -0
  166. package/src/tui/components/TuiData.res +47 -0
  167. package/src/tui/components/TuiData.res.mjs +34 -0
  168. package/svm.schema.json +112 -0
  169. package/bin.js +0 -48
  170. package/src/EventRegister.res +0 -241
  171. package/src/EventRegister.res.mjs +0 -240
  172. package/src/bindings/Ethers.gen.ts +0 -14
  173. package/src/bindings/Ethers.res +0 -204
  174. package/src/bindings/Ethers.res.mjs +0 -130
  175. /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
@@ -1,241 +0,0 @@
1
- type registrations = {
2
- onBlockByChainId: dict<array<Internal.onBlockConfig>>,
3
- mutable hasEvents: bool,
4
- }
5
-
6
- type activeRegistration = {
7
- ecosystem: Ecosystem.t,
8
- multichain: Config.multichain,
9
- registrations: registrations,
10
- mutable finished: bool,
11
- }
12
-
13
- let activeRegistration = ref(None)
14
-
15
- // Might happen for tests when the handler file
16
- // is imported by a non-envio process (eg mocha)
17
- // and initialized before we started registration.
18
- // So we track them here to register when the startRegistration is called.
19
- // Theoretically we could keep preRegistration without an explicit start
20
- // but I want it to be this way, so for the actual indexer run
21
- // an error is thrown with the exact stack trace where the handler was registered.
22
- let preRegistered = []
23
-
24
- let withRegistration = (fn: activeRegistration => unit) => {
25
- switch activeRegistration.contents {
26
- | None => preRegistered->Belt.Array.push(fn)
27
- | Some(r) =>
28
- if r.finished {
29
- Js.Exn.raiseError(
30
- "The indexer finished initializing, so no more handlers can be registered. Make sure the handlers are registered on the top level of the file.",
31
- )
32
- } else {
33
- fn(r)
34
- }
35
- }
36
- }
37
-
38
- let startRegistration = (~ecosystem, ~multichain) => {
39
- let r = {
40
- ecosystem,
41
- multichain,
42
- registrations: {
43
- onBlockByChainId: Js.Dict.empty(),
44
- hasEvents: false,
45
- },
46
- finished: false,
47
- }
48
- activeRegistration.contents = Some(r)
49
- while preRegistered->Js.Array2.length > 0 {
50
- // Loop + cleanup in one go
51
- switch preRegistered->Js.Array2.pop {
52
- | Some(fn) => fn(r)
53
- | None => ()
54
- }
55
- }
56
- }
57
-
58
- let finishRegistration = () => {
59
- switch activeRegistration.contents {
60
- | Some(r) => {
61
- r.finished = true
62
- r.registrations
63
- }
64
- | None =>
65
- Js.Exn.raiseError("The indexer has not started registering handlers, so can't finish it.")
66
- }
67
- }
68
-
69
- let isPendingRegistration = () => {
70
- switch activeRegistration.contents {
71
- | Some(r) => !r.finished
72
- | None => false
73
- }
74
- }
75
-
76
- let onBlockOptionsSchema = S.schema(s =>
77
- {
78
- "name": s.matches(S.string),
79
- "chain": s.matches(S.int),
80
- "interval": s.matches(S.option(S.int->S.intMin(1))->S.Option.getOr(1)),
81
- "startBlock": s.matches(S.option(S.int)),
82
- "endBlock": s.matches(S.option(S.int)),
83
- }
84
- )
85
-
86
- let onBlock = (rawOptions: unknown, handler: Internal.onBlockArgs => promise<unit>) => {
87
- withRegistration(registration => {
88
- // We need to get timestamp for ordered multichain mode
89
- switch registration.multichain {
90
- | Unordered => ()
91
- | Ordered =>
92
- Js.Exn.raiseError(
93
- "Block Handlers are not supported for ordered multichain mode. Please reach out to the Envio team if you need this feature. Or enable unordered multichain mode by removing `multichain: ordered` from the config.yaml file.",
94
- )
95
- }
96
-
97
- let options = rawOptions->S.parseOrThrow(onBlockOptionsSchema)
98
- let chainId = switch options["chain"] {
99
- | chainId => chainId
100
- // Dmitry: I want to add names for chains in the future
101
- // and to be able to use them as a lookup.
102
- // To do so, we'll need to pass a config during reigstration
103
- // instead of isInitialized check.
104
- }
105
-
106
- let onBlockByChainId = registration.registrations.onBlockByChainId
107
-
108
- switch onBlockByChainId->Utils.Dict.dangerouslyGetNonOption(chainId->Belt.Int.toString) {
109
- | None =>
110
- onBlockByChainId->Utils.Dict.setByInt(
111
- chainId,
112
- [
113
- (
114
- {
115
- index: 0,
116
- name: options["name"],
117
- startBlock: options["startBlock"],
118
- endBlock: options["endBlock"],
119
- interval: options["interval"],
120
- chainId,
121
- handler,
122
- }: Internal.onBlockConfig
123
- ),
124
- ],
125
- )
126
- | Some(onBlockConfigs) =>
127
- onBlockConfigs->Belt.Array.push(
128
- (
129
- {
130
- index: onBlockConfigs->Belt.Array.length,
131
- name: options["name"],
132
- startBlock: options["startBlock"],
133
- endBlock: options["endBlock"],
134
- interval: options["interval"],
135
- chainId,
136
- handler,
137
- }: Internal.onBlockConfig
138
- ),
139
- )
140
- }
141
- })
142
- }
143
-
144
- type t = {
145
- contractName: string,
146
- eventName: string,
147
- mutable handler: option<Internal.handler>,
148
- mutable contractRegister: option<Internal.contractRegister>,
149
- mutable eventOptions: option<Internal.eventOptions<Js.Json.t>>,
150
- }
151
-
152
- let getHandler = (t: t) => t.handler
153
-
154
- let getContractRegister = (t: t) => t.contractRegister
155
-
156
- let getEventFilters = (t: t) => t.eventOptions->Belt.Option.flatMap(value => value.eventFilters)
157
-
158
- let isWildcard = (t: t) =>
159
- t.eventOptions->Belt.Option.flatMap(value => value.wildcard)->Belt.Option.getWithDefault(false)
160
-
161
- let hasRegistration = ({handler, contractRegister}) =>
162
- handler->Belt.Option.isSome || contractRegister->Belt.Option.isSome
163
-
164
- let make = (~contractName, ~eventName) => {
165
- contractName,
166
- eventName,
167
- handler: None,
168
- contractRegister: None,
169
- eventOptions: None,
170
- }
171
-
172
- type eventNamespace = {contractName: string, eventName: string}
173
- exception DuplicateEventRegistration(eventNamespace)
174
-
175
- let setEventOptions = (t: t, ~eventOptions, ~logger=Logging.getLogger()) => {
176
- switch eventOptions {
177
- | Some(value) =>
178
- let value =
179
- value->(Utils.magic: Internal.eventOptions<'eventFilters> => Internal.eventOptions<Js.Json.t>)
180
- switch t.eventOptions {
181
- | None => t.eventOptions = Some(value)
182
- | Some(existingValue) =>
183
- if (
184
- existingValue.wildcard !== value.wildcard ||
185
- // TODO: Can improve the check by using deepEqual
186
- existingValue.eventFilters !== value.eventFilters
187
- ) {
188
- let eventNamespace = {contractName: t.contractName, eventName: t.eventName}
189
- DuplicateEventRegistration(eventNamespace)->ErrorHandling.mkLogAndRaise(
190
- ~logger=Logging.createChildFrom(~logger, ~params=eventNamespace),
191
- ~msg="Duplicate eventOptions in handlers not allowed",
192
- )
193
- }
194
- }
195
- | None => ()
196
- }
197
- }
198
-
199
- let setHandler = (t: t, handler, ~eventOptions, ~logger=Logging.getLogger()) => {
200
- withRegistration(registration => {
201
- registration.registrations.hasEvents = true
202
- switch t.handler {
203
- | None =>
204
- t.handler =
205
- handler
206
- ->(Utils.magic: Internal.genericHandler<'args> => Internal.handler)
207
- ->Some
208
- | Some(_) =>
209
- let eventNamespace = {contractName: t.contractName, eventName: t.eventName}
210
- DuplicateEventRegistration(eventNamespace)->ErrorHandling.mkLogAndRaise(
211
- ~logger=Logging.createChildFrom(~logger, ~params=eventNamespace),
212
- ~msg="Duplicate registration of event handlers not allowed",
213
- )
214
- }
215
-
216
- t->setEventOptions(~eventOptions, ~logger)
217
- })
218
- }
219
-
220
- let setContractRegister = (t: t, contractRegister, ~eventOptions, ~logger=Logging.getLogger()) => {
221
- withRegistration(registration => {
222
- registration.registrations.hasEvents = true
223
- switch t.contractRegister {
224
- | None =>
225
- t.contractRegister = Some(
226
- contractRegister->(
227
- Utils.magic: Internal.genericContractRegister<
228
- Internal.genericContractRegisterArgs<'event, 'context>,
229
- > => Internal.contractRegister
230
- ),
231
- )
232
- | Some(_) =>
233
- let eventNamespace = {contractName: t.contractName, eventName: t.eventName}
234
- DuplicateEventRegistration(eventNamespace)->ErrorHandling.mkLogAndRaise(
235
- ~logger=Logging.createChildFrom(~logger, ~params=eventNamespace),
236
- ~msg="Duplicate contractRegister handlers not allowed",
237
- )
238
- }
239
- t->setEventOptions(~eventOptions, ~logger)
240
- })
241
- }
@@ -1,240 +0,0 @@
1
- // Generated by ReScript, PLEASE EDIT WITH CARE
2
-
3
- import * as Js_exn from "rescript/lib/es6/js_exn.js";
4
- import * as Logging from "./Logging.res.mjs";
5
- import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
6
- import * as ErrorHandling from "./ErrorHandling.res.mjs";
7
- import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
8
- import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
9
-
10
- var activeRegistration = {
11
- contents: undefined
12
- };
13
-
14
- var preRegistered = [];
15
-
16
- function withRegistration(fn) {
17
- var r = activeRegistration.contents;
18
- if (r !== undefined) {
19
- if (r.finished) {
20
- return Js_exn.raiseError("The indexer finished initializing, so no more handlers can be registered. Make sure the handlers are registered on the top level of the file.");
21
- } else {
22
- return fn(r);
23
- }
24
- } else {
25
- preRegistered.push(fn);
26
- return ;
27
- }
28
- }
29
-
30
- function startRegistration(ecosystem, multichain) {
31
- var r = {
32
- ecosystem: ecosystem,
33
- multichain: multichain,
34
- registrations: {
35
- onBlockByChainId: {},
36
- hasEvents: false
37
- },
38
- finished: false
39
- };
40
- activeRegistration.contents = r;
41
- while(preRegistered.length > 0) {
42
- var fn = preRegistered.pop();
43
- if (fn !== undefined) {
44
- fn(r);
45
- }
46
-
47
- };
48
- }
49
-
50
- function finishRegistration() {
51
- var r = activeRegistration.contents;
52
- if (r !== undefined) {
53
- r.finished = true;
54
- return r.registrations;
55
- } else {
56
- return Js_exn.raiseError("The indexer has not started registering handlers, so can't finish it.");
57
- }
58
- }
59
-
60
- function isPendingRegistration() {
61
- var r = activeRegistration.contents;
62
- if (r !== undefined) {
63
- return !r.finished;
64
- } else {
65
- return false;
66
- }
67
- }
68
-
69
- var onBlockOptionsSchema = S$RescriptSchema.schema(function (s) {
70
- return {
71
- name: s.m(S$RescriptSchema.string),
72
- chain: s.m(S$RescriptSchema.$$int),
73
- interval: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.option(S$RescriptSchema.intMin(S$RescriptSchema.$$int, 1, undefined)), 1)),
74
- startBlock: s.m(S$RescriptSchema.option(S$RescriptSchema.$$int)),
75
- endBlock: s.m(S$RescriptSchema.option(S$RescriptSchema.$$int))
76
- };
77
- });
78
-
79
- function onBlock(rawOptions, handler) {
80
- withRegistration(function (registration) {
81
- var match = registration.multichain;
82
- if (match === "ordered") {
83
- Js_exn.raiseError("Block Handlers are not supported for ordered multichain mode. Please reach out to the Envio team if you need this feature. Or enable unordered multichain mode by removing `multichain: ordered` from the config.yaml file.");
84
- }
85
- var options = S$RescriptSchema.parseOrThrow(rawOptions, onBlockOptionsSchema);
86
- var chainId = options.chain;
87
- var onBlockByChainId = registration.registrations.onBlockByChainId;
88
- var onBlockConfigs = onBlockByChainId[String(chainId)];
89
- if (onBlockConfigs !== undefined) {
90
- onBlockConfigs.push({
91
- index: onBlockConfigs.length,
92
- name: options.name,
93
- chainId: chainId,
94
- startBlock: options.startBlock,
95
- endBlock: options.endBlock,
96
- interval: options.interval,
97
- handler: handler
98
- });
99
- } else {
100
- onBlockByChainId[chainId] = [{
101
- index: 0,
102
- name: options.name,
103
- chainId: chainId,
104
- startBlock: options.startBlock,
105
- endBlock: options.endBlock,
106
- interval: options.interval,
107
- handler: handler
108
- }];
109
- }
110
- });
111
- }
112
-
113
- function getHandler(t) {
114
- return t.handler;
115
- }
116
-
117
- function getContractRegister(t) {
118
- return t.contractRegister;
119
- }
120
-
121
- function getEventFilters(t) {
122
- return Belt_Option.flatMap(t.eventOptions, (function (value) {
123
- return value.eventFilters;
124
- }));
125
- }
126
-
127
- function isWildcard(t) {
128
- return Belt_Option.getWithDefault(Belt_Option.flatMap(t.eventOptions, (function (value) {
129
- return value.wildcard;
130
- })), false);
131
- }
132
-
133
- function hasRegistration(param) {
134
- var handler = param.handler;
135
- var contractRegister = param.contractRegister;
136
- if (Belt_Option.isSome(handler)) {
137
- return true;
138
- } else {
139
- return Belt_Option.isSome(contractRegister);
140
- }
141
- }
142
-
143
- function make(contractName, eventName) {
144
- return {
145
- contractName: contractName,
146
- eventName: eventName,
147
- handler: undefined,
148
- contractRegister: undefined,
149
- eventOptions: undefined
150
- };
151
- }
152
-
153
- var DuplicateEventRegistration = /* @__PURE__ */Caml_exceptions.create("EventRegister.DuplicateEventRegistration");
154
-
155
- function setEventOptions(t, eventOptions, loggerOpt) {
156
- var logger = loggerOpt !== undefined ? loggerOpt : Logging.getLogger();
157
- if (eventOptions === undefined) {
158
- return ;
159
- }
160
- var existingValue = t.eventOptions;
161
- if (existingValue === undefined) {
162
- t.eventOptions = eventOptions;
163
- return ;
164
- }
165
- if (!(existingValue.wildcard !== eventOptions.wildcard || existingValue.eventFilters !== eventOptions.eventFilters)) {
166
- return ;
167
- }
168
- var eventNamespace_contractName = t.contractName;
169
- var eventNamespace_eventName = t.eventName;
170
- var eventNamespace = {
171
- contractName: eventNamespace_contractName,
172
- eventName: eventNamespace_eventName
173
- };
174
- ErrorHandling.mkLogAndRaise(Logging.createChildFrom(logger, eventNamespace), "Duplicate eventOptions in handlers not allowed", {
175
- RE_EXN_ID: DuplicateEventRegistration,
176
- _1: eventNamespace
177
- });
178
- }
179
-
180
- function setHandler(t, handler, eventOptions, loggerOpt) {
181
- var logger = loggerOpt !== undefined ? loggerOpt : Logging.getLogger();
182
- withRegistration(function (registration) {
183
- registration.registrations.hasEvents = true;
184
- var match = t.handler;
185
- if (match !== undefined) {
186
- var eventNamespace_contractName = t.contractName;
187
- var eventNamespace_eventName = t.eventName;
188
- var eventNamespace = {
189
- contractName: eventNamespace_contractName,
190
- eventName: eventNamespace_eventName
191
- };
192
- ErrorHandling.mkLogAndRaise(Logging.createChildFrom(logger, eventNamespace), "Duplicate registration of event handlers not allowed", {
193
- RE_EXN_ID: DuplicateEventRegistration,
194
- _1: eventNamespace
195
- });
196
- } else {
197
- t.handler = handler;
198
- }
199
- setEventOptions(t, eventOptions, logger);
200
- });
201
- }
202
-
203
- function setContractRegister(t, contractRegister, eventOptions, loggerOpt) {
204
- var logger = loggerOpt !== undefined ? loggerOpt : Logging.getLogger();
205
- withRegistration(function (registration) {
206
- registration.registrations.hasEvents = true;
207
- var match = t.contractRegister;
208
- if (match !== undefined) {
209
- var eventNamespace_contractName = t.contractName;
210
- var eventNamespace_eventName = t.eventName;
211
- var eventNamespace = {
212
- contractName: eventNamespace_contractName,
213
- eventName: eventNamespace_eventName
214
- };
215
- ErrorHandling.mkLogAndRaise(Logging.createChildFrom(logger, eventNamespace), "Duplicate contractRegister handlers not allowed", {
216
- RE_EXN_ID: DuplicateEventRegistration,
217
- _1: eventNamespace
218
- });
219
- } else {
220
- t.contractRegister = contractRegister;
221
- }
222
- setEventOptions(t, eventOptions, logger);
223
- });
224
- }
225
-
226
- export {
227
- startRegistration ,
228
- isPendingRegistration ,
229
- finishRegistration ,
230
- make ,
231
- setHandler ,
232
- setContractRegister ,
233
- getHandler ,
234
- getContractRegister ,
235
- getEventFilters ,
236
- isWildcard ,
237
- hasRegistration ,
238
- onBlock ,
239
- }
240
- /* onBlockOptionsSchema Not a pure module */
@@ -1,14 +0,0 @@
1
- /* TypeScript file generated from Ethers.res by genType. */
2
-
3
- /* eslint-disable */
4
- /* tslint:disable */
5
-
6
- import * as EthersJS from './Ethers.res.mjs';
7
-
8
- import type {t as Address_t} from '../../src/Address.gen.js';
9
-
10
- export const Addresses_mockAddresses: Address_t[] = EthersJS.Addresses.mockAddresses as any;
11
-
12
- export const Addresses_defaultAddress: Address_t = EthersJS.Addresses.defaultAddress as any;
13
-
14
- export const Addresses: { mockAddresses: Address_t[]; defaultAddress: Address_t } = EthersJS.Addresses as any;
@@ -1,204 +0,0 @@
1
- type abi = EvmTypes.Abi.t
2
-
3
- let makeAbi = (abi: Js.Json.t): abi => abi->Utils.magic
4
-
5
- @deprecated("Use Address.t instead. The type will be removed in v3")
6
- type ethAddress = Address.t
7
- @deprecated("Use Address.Evm.fromStringOrThrow instead. The function will be removed in v3")
8
- let getAddressFromStringUnsafe = Address.Evm.fromStringOrThrow
9
- @deprecated("Use Address.toString instead. The function will be removed in v3")
10
- let ethAddressToString = Address.toString
11
- @deprecated("Use Address.schema instead. The function will be removed in v3")
12
- let ethAddressSchema = Address.schema
13
-
14
- type txHash = string
15
-
16
- module Constants = {
17
- @module("ethers") @scope("ethers") external zeroHash: string = "ZeroHash"
18
- @module("ethers") @scope("ethers") external zeroAddress: Address.t = "ZeroAddress"
19
- }
20
-
21
- module Addresses = {
22
- @genType
23
- let mockAddresses = [
24
- "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
25
- "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
26
- "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
27
- "0x90F79bf6EB2c4f870365E785982E1f101E93b906",
28
- "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65",
29
- "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
30
- "0x976EA74026E726554dB657fA54763abd0C3a0aa9",
31
- "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955",
32
- "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f",
33
- "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720",
34
- "0xBcd4042DE499D14e55001CcbB24a551F3b954096",
35
- "0x71bE63f3384f5fb98995898A86B02Fb2426c5788",
36
- "0xFABB0ac9d68B0B445fB7357272Ff202C5651694a",
37
- "0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec",
38
- "0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097",
39
- "0xcd3B766CCDd6AE721141F452C550Ca635964ce71",
40
- "0x2546BcD3c84621e976D8185a91A922aE77ECEc30",
41
- "0xbDA5747bFD65F08deb54cb465eB87D40e51B197E",
42
- "0xdD2FD4581271e230360230F9337D5c0430Bf44C0",
43
- "0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199",
44
- ]->Belt.Array.map(getAddressFromStringUnsafe)
45
- @genType
46
- let defaultAddress =
47
- mockAddresses[0]
48
- }
49
-
50
- module Filter = {
51
- type t
52
- }
53
-
54
- module CombinedFilter = {
55
- type combinedFilterRecord = {
56
- address?: array<Address.t>,
57
- //The second element of the tuple is the
58
- topics: Rpc.GetLogs.topicQuery,
59
- fromBlock: int,
60
- toBlock: int,
61
- }
62
-
63
- let toFilter = (combinedFilter: combinedFilterRecord): Filter.t => combinedFilter->Utils.magic
64
- }
65
-
66
- type log = {
67
- blockNumber: int,
68
- blockHash: string,
69
- removed: option<bool>,
70
- //Note: this is the index of the log in the transaction and should be used whenever we use "logIndex"
71
- address: Address.t,
72
- data: string,
73
- topics: array<EvmTypes.Hex.t>,
74
- transactionHash: txHash,
75
- transactionIndex: int,
76
- //Note: this logIndex is the index of the log in the block, not the transaction
77
- @as("index") logIndex: int,
78
- }
79
-
80
- type transaction
81
-
82
- type minimumParseableLogData = {topics: array<EvmTypes.Hex.t>, data: string}
83
-
84
- //Can safely convert from log to minimumParseableLogData since it contains
85
- //both data points required
86
- let logToMinimumParseableLogData: log => minimumParseableLogData = Utils.magic
87
-
88
- type logDescription<'a> = {
89
- args: 'a,
90
- name: string,
91
- signature: string,
92
- topic: string,
93
- }
94
-
95
- module Network = {
96
- type t
97
-
98
- @module("ethers") @new
99
- external make: (~name: string, ~chainId: int) => t = "Network"
100
-
101
- @module("ethers") @scope("Network")
102
- external fromChainId: (~chainId: int) => t = "from"
103
- }
104
-
105
- module JsonRpcProvider = {
106
- type t
107
-
108
- type rpcOptions = {
109
- staticNetwork?: Network.t,
110
- // Options for FallbackProvider
111
- /**
112
- * The amount of time to wait before kicking off the next provider.
113
- *
114
- * Any providers that have not responded can still respond and be
115
- * counted, but this ensures new providers start.
116
- * Default: 400ms
117
- */
118
- stallTimeout?: int,
119
- /**
120
- * The priority. Lower priority providers are dispatched first.
121
- * Default: 1
122
- */
123
- priority?: int,
124
- /**
125
- * The amount of weight a provider is given against the quorum.
126
- * Default: 1
127
- */
128
- weight?: int,
129
- }
130
-
131
- @module("ethers") @scope("ethers") @new
132
- external makeWithOptions: (~rpcUrl: string, ~network: Network.t, ~options: rpcOptions) => t =
133
- "JsonRpcProvider"
134
-
135
- let makeStatic = (~rpcUrl: string, ~network: Network.t, ~priority=?, ~stallTimeout=?): t => {
136
- makeWithOptions(~rpcUrl, ~network, ~options={staticNetwork: network, ?priority, ?stallTimeout})
137
- }
138
-
139
- let make = (~rpcUrl: string, ~chainId: int): t => {
140
- let network = Network.fromChainId(~chainId)
141
- makeStatic(~rpcUrl, ~network)
142
- }
143
-
144
- @send
145
- external getLogs: (t, ~filter: Filter.t) => promise<array<log>> = "getLogs"
146
-
147
- @send
148
- external getTransaction: (t, ~transactionHash: string) => promise<transaction> = "getTransaction"
149
-
150
- let makeGetTransactionFields = (~getTransactionByHash, ~lowercaseAddresses: bool) => async (
151
- log: log,
152
- ): promise<unknown> => {
153
- let transaction = await getTransactionByHash(log.transactionHash)
154
- // Mutating should be fine, since the transaction isn't used anywhere else outside the function
155
- let fields: {..} = transaction->Obj.magic
156
-
157
- // Make it compatible with HyperSync transaction fields
158
- fields["transactionIndex"] = log.transactionIndex
159
- fields["input"] = fields["data"]
160
-
161
- // NOTE: this is wasteful if these fields are not selected in the users config.
162
- // There might be a better way to do this in the `makeThrowingGetEventTransaction` function rather based on the schema.
163
- // However this is not extremely expensive and good enough for now (only on rpc sync also).
164
- if lowercaseAddresses {
165
- open Js.Nullable
166
- switch fields["from"] {
167
- | Value(from) => fields["from"] = from->Js.String2.toLowerCase
168
- | Undefined => ()
169
- | Null => ()
170
- }
171
- switch fields["to"] {
172
- | Value(to) => fields["to"] = to->Js.String2.toLowerCase
173
- | Undefined => ()
174
- | Null => ()
175
- }
176
- switch fields["contractAddress"] {
177
- | Value(contractAddress) =>
178
- fields["contractAddress"] = contractAddress->Js.String2.toLowerCase
179
- | Undefined => ()
180
- | Null => ()
181
- }
182
- }
183
-
184
- fields->Obj.magic
185
- }
186
-
187
- type block = {
188
- _difficulty: bigint,
189
- difficulty: int,
190
- extraData: Address.t,
191
- gasLimit: bigint,
192
- gasUsed: bigint,
193
- hash: string,
194
- miner: Address.t,
195
- nonce: int,
196
- number: int,
197
- parentHash: Address.t,
198
- timestamp: int,
199
- transactions: array<Address.t>,
200
- }
201
-
202
- @send
203
- external getBlock: (t, int) => promise<Js.nullable<block>> = "getBlock"
204
- }