envio 3.0.0-alpha.2 → 3.0.0-alpha.21

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 (184) 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 +578 -1
  6. package/index.js +4 -0
  7. package/package.json +47 -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 +725 -25
  18. package/src/Config.res.mjs +692 -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 +33 -73
  23. package/src/Env.res.mjs +29 -85
  24. package/src/Envio.gen.ts +3 -1
  25. package/src/Envio.res +77 -9
  26. package/src/Envio.res.mjs +39 -1
  27. package/src/EventConfigBuilder.res +408 -0
  28. package/src/EventConfigBuilder.res.mjs +376 -0
  29. package/src/EventProcessing.res +469 -0
  30. package/src/EventProcessing.res.mjs +337 -0
  31. package/src/EvmTypes.gen.ts +6 -0
  32. package/src/EvmTypes.res +1 -0
  33. package/src/FetchState.res +1256 -639
  34. package/src/FetchState.res.mjs +1135 -612
  35. package/src/GlobalState.res +1224 -0
  36. package/src/GlobalState.res.mjs +1291 -0
  37. package/src/GlobalStateManager.res +68 -0
  38. package/src/GlobalStateManager.res.mjs +75 -0
  39. package/src/GlobalStateManager.resi +7 -0
  40. package/src/HandlerLoader.res +89 -0
  41. package/src/HandlerLoader.res.mjs +79 -0
  42. package/src/HandlerRegister.res +357 -0
  43. package/src/HandlerRegister.res.mjs +299 -0
  44. package/src/HandlerRegister.resi +30 -0
  45. package/src/Hasura.res +111 -175
  46. package/src/Hasura.res.mjs +88 -150
  47. package/src/InMemoryStore.res +1 -1
  48. package/src/InMemoryStore.res.mjs +3 -3
  49. package/src/InMemoryTable.res +1 -1
  50. package/src/InMemoryTable.res.mjs +1 -1
  51. package/src/Internal.gen.ts +6 -0
  52. package/src/Internal.res +265 -12
  53. package/src/Internal.res.mjs +115 -1
  54. package/src/LoadLayer.res +444 -0
  55. package/src/LoadLayer.res.mjs +296 -0
  56. package/src/LoadLayer.resi +32 -0
  57. package/src/LogSelection.res +33 -27
  58. package/src/LogSelection.res.mjs +6 -0
  59. package/src/Logging.res +21 -7
  60. package/src/Logging.res.mjs +16 -8
  61. package/src/Main.res +390 -0
  62. package/src/Main.res.mjs +341 -0
  63. package/src/Persistence.res +7 -21
  64. package/src/Persistence.res.mjs +3 -3
  65. package/src/PgStorage.gen.ts +10 -0
  66. package/src/PgStorage.res +116 -69
  67. package/src/PgStorage.res.d.mts +5 -0
  68. package/src/PgStorage.res.mjs +93 -50
  69. package/src/Prometheus.res +294 -224
  70. package/src/Prometheus.res.mjs +353 -340
  71. package/src/ReorgDetection.res +6 -10
  72. package/src/ReorgDetection.res.mjs +6 -6
  73. package/src/SafeCheckpointTracking.res +4 -4
  74. package/src/SafeCheckpointTracking.res.mjs +2 -2
  75. package/src/SimulateItems.res +353 -0
  76. package/src/SimulateItems.res.mjs +335 -0
  77. package/src/Sink.res +4 -2
  78. package/src/Sink.res.mjs +2 -1
  79. package/src/TableIndices.res +0 -1
  80. package/src/TestIndexer.res +913 -0
  81. package/src/TestIndexer.res.mjs +698 -0
  82. package/src/TestIndexerProxyStorage.res +205 -0
  83. package/src/TestIndexerProxyStorage.res.mjs +151 -0
  84. package/src/TopicFilter.res +1 -1
  85. package/src/Types.ts +1 -1
  86. package/src/UserContext.res +424 -0
  87. package/src/UserContext.res.mjs +279 -0
  88. package/src/Utils.res +97 -26
  89. package/src/Utils.res.mjs +91 -44
  90. package/src/bindings/BigInt.res +10 -0
  91. package/src/bindings/BigInt.res.mjs +15 -0
  92. package/src/bindings/ClickHouse.res +120 -23
  93. package/src/bindings/ClickHouse.res.mjs +118 -28
  94. package/src/bindings/DateFns.res +74 -0
  95. package/src/bindings/DateFns.res.mjs +22 -0
  96. package/src/bindings/EventSource.res +11 -2
  97. package/src/bindings/EventSource.res.mjs +8 -1
  98. package/src/bindings/Express.res +1 -0
  99. package/src/bindings/Hrtime.res +14 -1
  100. package/src/bindings/Hrtime.res.mjs +22 -2
  101. package/src/bindings/Hrtime.resi +4 -0
  102. package/src/bindings/Lodash.res +0 -1
  103. package/src/bindings/NodeJs.res +49 -3
  104. package/src/bindings/NodeJs.res.mjs +11 -3
  105. package/src/bindings/Pino.res +24 -10
  106. package/src/bindings/Pino.res.mjs +14 -8
  107. package/src/bindings/Postgres.gen.ts +8 -0
  108. package/src/bindings/Postgres.res +5 -1
  109. package/src/bindings/Postgres.res.d.mts +5 -0
  110. package/src/bindings/PromClient.res +0 -10
  111. package/src/bindings/PromClient.res.mjs +0 -3
  112. package/src/bindings/Vitest.res +144 -0
  113. package/src/bindings/Vitest.res.mjs +9 -0
  114. package/src/bindings/WebSocket.res +27 -0
  115. package/src/bindings/WebSocket.res.mjs +2 -0
  116. package/src/bindings/Yargs.res +8 -0
  117. package/src/bindings/Yargs.res.mjs +2 -0
  118. package/src/db/EntityHistory.res +7 -7
  119. package/src/db/EntityHistory.res.mjs +9 -9
  120. package/src/db/InternalTable.res +59 -111
  121. package/src/db/InternalTable.res.mjs +73 -104
  122. package/src/db/Table.res +27 -8
  123. package/src/db/Table.res.mjs +25 -14
  124. package/src/sources/Evm.res +84 -0
  125. package/src/sources/Evm.res.mjs +105 -0
  126. package/src/sources/EvmChain.res +94 -0
  127. package/src/sources/EvmChain.res.mjs +60 -0
  128. package/src/sources/Fuel.res +19 -34
  129. package/src/sources/Fuel.res.mjs +34 -16
  130. package/src/sources/FuelSDK.res +38 -0
  131. package/src/sources/FuelSDK.res.mjs +29 -0
  132. package/src/sources/HyperFuel.res +2 -2
  133. package/src/sources/HyperFuel.resi +1 -1
  134. package/src/sources/HyperFuelClient.res +2 -2
  135. package/src/sources/HyperFuelSource.res +35 -13
  136. package/src/sources/HyperFuelSource.res.mjs +26 -16
  137. package/src/sources/HyperSync.res +61 -60
  138. package/src/sources/HyperSync.res.mjs +53 -67
  139. package/src/sources/HyperSync.resi +6 -4
  140. package/src/sources/HyperSyncClient.res +29 -2
  141. package/src/sources/HyperSyncClient.res.mjs +9 -0
  142. package/src/sources/HyperSyncHeightStream.res +76 -118
  143. package/src/sources/HyperSyncHeightStream.res.mjs +68 -75
  144. package/src/sources/HyperSyncSource.res +122 -143
  145. package/src/sources/HyperSyncSource.res.mjs +106 -121
  146. package/src/sources/Rpc.res +86 -14
  147. package/src/sources/Rpc.res.mjs +101 -9
  148. package/src/sources/RpcSource.res +731 -364
  149. package/src/sources/RpcSource.res.mjs +845 -410
  150. package/src/sources/RpcWebSocketHeightStream.res +181 -0
  151. package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
  152. package/src/sources/SimulateSource.res +59 -0
  153. package/src/sources/SimulateSource.res.mjs +50 -0
  154. package/src/sources/Source.res +7 -5
  155. package/src/sources/SourceManager.res +358 -221
  156. package/src/sources/SourceManager.res.mjs +346 -171
  157. package/src/sources/SourceManager.resi +17 -6
  158. package/src/sources/Svm.res +81 -0
  159. package/src/sources/Svm.res.mjs +90 -0
  160. package/src/tui/Tui.res +247 -0
  161. package/src/tui/Tui.res.mjs +337 -0
  162. package/src/tui/bindings/Ink.res +371 -0
  163. package/src/tui/bindings/Ink.res.mjs +72 -0
  164. package/src/tui/bindings/Style.res +123 -0
  165. package/src/tui/bindings/Style.res.mjs +2 -0
  166. package/src/tui/components/BufferedProgressBar.res +40 -0
  167. package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
  168. package/src/tui/components/CustomHooks.res +122 -0
  169. package/src/tui/components/CustomHooks.res.mjs +179 -0
  170. package/src/tui/components/Messages.res +41 -0
  171. package/src/tui/components/Messages.res.mjs +75 -0
  172. package/src/tui/components/SyncETA.res +174 -0
  173. package/src/tui/components/SyncETA.res.mjs +263 -0
  174. package/src/tui/components/TuiData.res +47 -0
  175. package/src/tui/components/TuiData.res.mjs +34 -0
  176. package/svm.schema.json +112 -0
  177. package/bin.js +0 -48
  178. package/src/EventRegister.res +0 -241
  179. package/src/EventRegister.res.mjs +0 -240
  180. package/src/EventRegister.resi +0 -30
  181. package/src/bindings/Ethers.gen.ts +0 -14
  182. package/src/bindings/Ethers.res +0 -204
  183. package/src/bindings/Ethers.res.mjs +0 -130
  184. /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
@@ -0,0 +1,335 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Js_exn from "rescript/lib/es6/js_exn.js";
4
+ import * as Address from "./Address.res.mjs";
5
+ import * as Js_dict from "rescript/lib/es6/js_dict.js";
6
+ import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
7
+ import * as ChainMap from "./ChainMap.res.mjs";
8
+ import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
9
+ import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
10
+ import * as Caml_option from "rescript/lib/es6/caml_option.js";
11
+ import * as SimulateSource from "./sources/SimulateSource.res.mjs";
12
+ import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
13
+
14
+ var evmSimulateBlockSchema = S$RescriptSchema.schema(function (s) {
15
+ return {
16
+ number: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.$$int), 0)),
17
+ timestamp: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.$$int), 0)),
18
+ hash: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
19
+ parentHash: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
20
+ sha3Uncles: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
21
+ logsBloom: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
22
+ transactionsRoot: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
23
+ stateRoot: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
24
+ receiptsRoot: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
25
+ miner: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(Address.schema), "0x0000000000000000000000000000000000000000")),
26
+ extraData: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
27
+ size: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.bigint), 0n)),
28
+ gasLimit: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.bigint), 0n)),
29
+ gasUsed: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.bigint), 0n)),
30
+ nonce: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
31
+ difficulty: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
32
+ totalDifficulty: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
33
+ uncles: s.m(S$RescriptSchema.$$null(S$RescriptSchema.array(S$RescriptSchema.string))),
34
+ baseFeePerGas: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
35
+ blobGasUsed: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
36
+ excessBlobGas: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
37
+ parentBeaconBlockRoot: s.m(S$RescriptSchema.$$null(S$RescriptSchema.string)),
38
+ withdrawalsRoot: s.m(S$RescriptSchema.$$null(S$RescriptSchema.string)),
39
+ l1BlockNumber: s.m(S$RescriptSchema.$$null(S$RescriptSchema.$$int)),
40
+ sendCount: s.m(S$RescriptSchema.$$null(S$RescriptSchema.string)),
41
+ sendRoot: s.m(S$RescriptSchema.$$null(S$RescriptSchema.string)),
42
+ mixHash: s.m(S$RescriptSchema.$$null(S$RescriptSchema.string))
43
+ };
44
+ });
45
+
46
+ function parseEvmSimulateBlock(defaultBlockNumber, blockJson) {
47
+ var block = blockJson !== undefined ? S$RescriptSchema.convertOrThrow(blockJson, evmSimulateBlockSchema) : S$RescriptSchema.convertOrThrow({}, evmSimulateBlockSchema);
48
+ if (Belt_Option.isNone(blockJson) || block.number === 0) {
49
+ block["number"] = defaultBlockNumber;
50
+ }
51
+ return block;
52
+ }
53
+
54
+ var evmSimulateTransactionSchema = S$RescriptSchema.schema(function (s) {
55
+ return {
56
+ transactionIndex: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.$$int), 0)),
57
+ hash: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
58
+ gas: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.bigint), 0n)),
59
+ input: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
60
+ nonce: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.bigint), 0n)),
61
+ value: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.bigint), 0n)),
62
+ cumulativeGasUsed: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.bigint), 0n)),
63
+ effectiveGasPrice: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.bigint), 0n)),
64
+ gasUsed: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.bigint), 0n)),
65
+ logsBloom: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
66
+ accessList: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.json(false)), null)),
67
+ v: s.m(S$RescriptSchema.$$null(S$RescriptSchema.string)),
68
+ r: s.m(S$RescriptSchema.$$null(S$RescriptSchema.string)),
69
+ s: s.m(S$RescriptSchema.$$null(S$RescriptSchema.string)),
70
+ yParity: s.m(S$RescriptSchema.$$null(S$RescriptSchema.string)),
71
+ from: s.m(S$RescriptSchema.$$null(Address.schema)),
72
+ to: s.m(S$RescriptSchema.$$null(Address.schema)),
73
+ contractAddress: s.m(S$RescriptSchema.$$null(S$RescriptSchema.string)),
74
+ gasPrice: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
75
+ maxPriorityFeePerGas: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
76
+ maxFeePerGas: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
77
+ maxFeePerBlobGas: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
78
+ blobVersionedHashes: s.m(S$RescriptSchema.$$null(S$RescriptSchema.array(S$RescriptSchema.string))),
79
+ root: s.m(S$RescriptSchema.$$null(S$RescriptSchema.string)),
80
+ status: s.m(S$RescriptSchema.$$null(S$RescriptSchema.$$int)),
81
+ type: s.m(S$RescriptSchema.$$null(S$RescriptSchema.$$int)),
82
+ l1Fee: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
83
+ l1GasPrice: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
84
+ l1GasUsed: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
85
+ l1FeeScalar: s.m(S$RescriptSchema.$$null(S$RescriptSchema.$$float)),
86
+ gasUsedForL1: s.m(S$RescriptSchema.$$null(S$RescriptSchema.bigint)),
87
+ authorizationList: s.m(S$RescriptSchema.$$null(S$RescriptSchema.json(false)))
88
+ };
89
+ });
90
+
91
+ function parseEvmSimulateTransaction(transactionJson) {
92
+ if (transactionJson !== undefined) {
93
+ return S$RescriptSchema.convertOrThrow(transactionJson, evmSimulateTransactionSchema);
94
+ } else {
95
+ return S$RescriptSchema.convertOrThrow({}, evmSimulateTransactionSchema);
96
+ }
97
+ }
98
+
99
+ var fuelSimulateBlockSchema = S$RescriptSchema.schema(function (s) {
100
+ return {
101
+ id: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), "")),
102
+ height: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.$$int), 0)),
103
+ time: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.$$int), 0))
104
+ };
105
+ });
106
+
107
+ function parseFuelSimulateBlock(defaultBlockNumber, blockJson) {
108
+ var block = blockJson !== undefined ? S$RescriptSchema.convertOrThrow(blockJson, fuelSimulateBlockSchema) : S$RescriptSchema.convertOrThrow({}, fuelSimulateBlockSchema);
109
+ if (Belt_Option.isNone(blockJson) || block.height === 0) {
110
+ block["height"] = defaultBlockNumber;
111
+ }
112
+ return block;
113
+ }
114
+
115
+ var fuelSimulateTransactionSchema = S$RescriptSchema.schema(function (s) {
116
+ return {
117
+ id: s.m(S$RescriptSchema.$$Option.getOr(S$RescriptSchema.$$null(S$RescriptSchema.string), ""))
118
+ };
119
+ });
120
+
121
+ function parseFuelSimulateTransaction(transactionJson) {
122
+ if (transactionJson !== undefined) {
123
+ return S$RescriptSchema.convertOrThrow(transactionJson, fuelSimulateTransactionSchema);
124
+ } else {
125
+ return S$RescriptSchema.convertOrThrow({}, fuelSimulateTransactionSchema);
126
+ }
127
+ }
128
+
129
+ function findEventConfig(config, contractName, eventName) {
130
+ var found = {
131
+ contents: undefined
132
+ };
133
+ Belt_Array.forEach(ChainMap.values(config.chainMap), (function (chainConfig) {
134
+ Belt_Array.forEach(chainConfig.contracts, (function (contract) {
135
+ if (contract.name === contractName) {
136
+ return Belt_Array.forEach(contract.events, (function (eventConfig) {
137
+ if (eventConfig.name === eventName) {
138
+ found.contents = eventConfig;
139
+ return ;
140
+ }
141
+
142
+ }));
143
+ }
144
+
145
+ }));
146
+ }));
147
+ return found.contents;
148
+ }
149
+
150
+ function parse(simulateItems, config, chainConfig) {
151
+ var chain = ChainMap.Chain.makeUnsafe(chainConfig.id);
152
+ var chainId = chainConfig.id;
153
+ var startBlock = chainConfig.startBlock;
154
+ var currentBlock = {
155
+ contents: startBlock
156
+ };
157
+ var currentLogIndex = {
158
+ contents: 0
159
+ };
160
+ var items = [];
161
+ Belt_Array.forEach(simulateItems, (function (rawJson) {
162
+ var match = rawJson.contract;
163
+ var match$1 = rawJson.event;
164
+ if (match === undefined) {
165
+ return Js_exn.raiseError("simulate: Invalid item. Each item must have \"contract\" and \"event\" fields.");
166
+ }
167
+ if (match$1 === undefined) {
168
+ return Js_exn.raiseError("simulate: Invalid item. Each item must have \"contract\" and \"event\" fields.");
169
+ }
170
+ var ec = findEventConfig(config, match, match$1);
171
+ var eventConfig = ec !== undefined ? ec : Js_exn.raiseError("simulate: Event \"" + match$1 + "\" not found on contract \"" + match + "\". Check that the contract and event names match your config.yaml.");
172
+ var json = rawJson.params;
173
+ var paramsJson = json !== undefined ? json : ({});
174
+ var params = S$RescriptSchema.convertOrThrow(paramsJson, eventConfig.simulateParamsSchema);
175
+ var li = rawJson.logIndex;
176
+ var logIndex;
177
+ if (li !== undefined) {
178
+ logIndex = li;
179
+ } else {
180
+ var li$1 = currentLogIndex.contents;
181
+ currentLogIndex.contents = li$1 + 1 | 0;
182
+ logIndex = li$1;
183
+ }
184
+ var addr = rawJson.srcAddress;
185
+ var srcAddress;
186
+ if (addr !== undefined) {
187
+ srcAddress = Caml_option.valFromOption(addr);
188
+ } else {
189
+ var addr$1 = {
190
+ contents: "0x0000000000000000000000000000000000000000"
191
+ };
192
+ Belt_Array.forEach(chainConfig.contracts, (function (contract) {
193
+ if (contract.name !== match) {
194
+ return ;
195
+ }
196
+ var a = Belt_Array.get(contract.addresses, 0);
197
+ if (a !== undefined) {
198
+ addr$1.contents = Caml_option.valFromOption(a);
199
+ return ;
200
+ }
201
+
202
+ }));
203
+ srcAddress = addr$1.contents;
204
+ }
205
+ var blockJson = rawJson.block;
206
+ var blockJson$1 = (blockJson == null) ? undefined : Caml_option.some(blockJson);
207
+ var transactionJson = rawJson.transaction;
208
+ var transactionJson$1 = (transactionJson == null) ? undefined : Caml_option.some(transactionJson);
209
+ var match$2 = config.ecosystem.name;
210
+ var match$3;
211
+ switch (match$2) {
212
+ case "evm" :
213
+ var block = parseEvmSimulateBlock(currentBlock.contents, blockJson$1);
214
+ match$3 = [
215
+ block,
216
+ block.number,
217
+ block.timestamp
218
+ ];
219
+ break;
220
+ case "fuel" :
221
+ var block$1 = parseFuelSimulateBlock(currentBlock.contents, blockJson$1);
222
+ match$3 = [
223
+ block$1,
224
+ block$1.height,
225
+ block$1.time
226
+ ];
227
+ break;
228
+ case "svm" :
229
+ match$3 = Js_exn.raiseError("simulate is not supported for SVM ecosystem");
230
+ break;
231
+
232
+ }
233
+ var blockNumber = match$3[1];
234
+ var match$4 = config.ecosystem.name;
235
+ var transaction;
236
+ switch (match$4) {
237
+ case "evm" :
238
+ transaction = parseEvmSimulateTransaction(transactionJson$1);
239
+ break;
240
+ case "fuel" :
241
+ transaction = parseFuelSimulateTransaction(transactionJson$1);
242
+ break;
243
+ case "svm" :
244
+ transaction = Js_exn.raiseError("simulate is not supported for SVM ecosystem");
245
+ break;
246
+
247
+ }
248
+ currentBlock.contents = blockNumber;
249
+ items.push({
250
+ kind: 0,
251
+ eventConfig: eventConfig,
252
+ timestamp: match$3[2],
253
+ chain: chain,
254
+ blockNumber: blockNumber,
255
+ logIndex: logIndex,
256
+ event: {
257
+ contractName: eventConfig.contractName,
258
+ eventName: eventConfig.name,
259
+ params: params,
260
+ chainId: chainId,
261
+ srcAddress: srcAddress,
262
+ logIndex: logIndex,
263
+ transaction: transaction,
264
+ block: match$3[0]
265
+ }
266
+ });
267
+ }));
268
+ return items;
269
+ }
270
+
271
+ function patchConfig(config, processConfig) {
272
+ var processChains = processConfig.chains;
273
+ if (processChains == null) {
274
+ return config;
275
+ }
276
+ var newChainMap = ChainMap.mapWithKey(config.chainMap, (function (chain, chainConfig) {
277
+ var chainIdStr = String(chain);
278
+ var processChainJson = Js_dict.get(processChains, chainIdStr);
279
+ if (processChainJson === undefined) {
280
+ return chainConfig;
281
+ }
282
+ var simulateRaw = processChainJson.simulate;
283
+ if (simulateRaw == null) {
284
+ return chainConfig;
285
+ }
286
+ var items = parse(simulateRaw, config, chainConfig);
287
+ var startBlock = processChainJson.startBlock;
288
+ var endBlock = processChainJson.endBlock;
289
+ var source = SimulateSource.make(items, endBlock, chain);
290
+ var newrecord = Caml_obj.obj_dup(chainConfig);
291
+ newrecord.sourceConfig = {
292
+ TAG: "CustomSources",
293
+ _0: [source]
294
+ };
295
+ newrecord.endBlock = endBlock;
296
+ newrecord.startBlock = startBlock;
297
+ return newrecord;
298
+ }));
299
+ return {
300
+ name: config.name,
301
+ description: config.description,
302
+ handlers: config.handlers,
303
+ contractHandlers: config.contractHandlers,
304
+ shouldRollbackOnReorg: config.shouldRollbackOnReorg,
305
+ shouldSaveFullHistory: config.shouldSaveFullHistory,
306
+ multichain: config.multichain,
307
+ chainMap: newChainMap,
308
+ defaultChain: config.defaultChain,
309
+ ecosystem: config.ecosystem,
310
+ enableRawEvents: config.enableRawEvents,
311
+ maxAddrInPartition: config.maxAddrInPartition,
312
+ batchSize: config.batchSize,
313
+ lowercaseAddresses: config.lowercaseAddresses,
314
+ addContractNameToContractNameMapping: config.addContractNameToContractNameMapping,
315
+ userEntitiesByName: config.userEntitiesByName,
316
+ userEntities: config.userEntities,
317
+ allEntities: config.allEntities,
318
+ allEnums: config.allEnums
319
+ };
320
+ }
321
+
322
+ export {
323
+ evmSimulateBlockSchema ,
324
+ parseEvmSimulateBlock ,
325
+ evmSimulateTransactionSchema ,
326
+ parseEvmSimulateTransaction ,
327
+ fuelSimulateBlockSchema ,
328
+ parseFuelSimulateBlock ,
329
+ fuelSimulateTransactionSchema ,
330
+ parseFuelSimulateTransaction ,
331
+ findEventConfig ,
332
+ parse ,
333
+ patchConfig ,
334
+ }
335
+ /* evmSimulateBlockSchema Not a pure module */
package/src/Sink.res CHANGED
@@ -5,7 +5,7 @@ type t = {
5
5
  ~entities: array<Internal.entityConfig>=?,
6
6
  ~enums: array<Table.enumConfig<Table.enum>>=?,
7
7
  ) => promise<unit>,
8
- resume: (~checkpointId: float) => promise<unit>,
8
+ resume: (~checkpointId: Internal.checkpointId) => promise<unit>,
9
9
  writeBatch: (
10
10
  ~batch: Batch.t,
11
11
  ~updatedEntities: array<Persistence.updatedEntity>,
@@ -27,6 +27,8 @@ let makeClickHouse = (~host, ~database, ~username, ~password): t => {
27
27
  | None => "envio_sink"
28
28
  }
29
29
 
30
+ let cache = Utils.WeakMap.make()
31
+
30
32
  {
31
33
  name: "ClickHouse",
32
34
  initialize: (~chainConfigs as _=[], ~entities=[], ~enums=[]) => {
@@ -38,7 +40,7 @@ let makeClickHouse = (~host, ~database, ~username, ~password): t => {
38
40
  writeBatch: async (~batch, ~updatedEntities) => {
39
41
  await Promise.all(
40
42
  updatedEntities->Belt.Array.map(({entityConfig, updates}) => {
41
- ClickHouse.setUpdatesOrThrow(client, ~updates, ~entityConfig, ~database)
43
+ ClickHouse.setUpdatesOrThrow(client, ~cache, ~updates, ~entityConfig, ~database)
42
44
  }),
43
45
  )->Promise.ignoreValue
44
46
  await ClickHouse.setCheckpointsOrThrow(client, ~batch, ~database)
package/src/Sink.res.mjs CHANGED
@@ -11,6 +11,7 @@ function makeClickHouse(host, database, username, password) {
11
11
  password: password
12
12
  });
13
13
  var database$1 = database !== undefined ? database : "envio_sink";
14
+ var cache = new WeakMap();
14
15
  return {
15
16
  name: "ClickHouse",
16
17
  initialize: (function ($staropt$star, $staropt$star$1, $staropt$star$2) {
@@ -24,7 +25,7 @@ function makeClickHouse(host, database, username, password) {
24
25
  }),
25
26
  writeBatch: (async function (batch, updatedEntities) {
26
27
  await Promise.all(Belt_Array.map(updatedEntities, (function (param) {
27
- return ClickHouse.setUpdatesOrThrow(client, param.updates, param.entityConfig, database$1);
28
+ return ClickHouse.setUpdatesOrThrow(client, cache, param.updates, param.entityConfig, database$1);
28
29
  })));
29
30
  return await ClickHouse.setCheckpointsOrThrow(client, batch, database$1);
30
31
  })
@@ -107,4 +107,3 @@ module Index = {
107
107
  | Single(index) => SingleIndex.evaluate(index, ~fieldName, ~fieldValue)
108
108
  }
109
109
  }
110
-