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
@@ -0,0 +1,215 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Env from "./Env.res.mjs";
4
+ import * as Utils from "./Utils.res.mjs";
5
+ import * as Throttler from "./Throttler.res.mjs";
6
+ import * as Prometheus from "./Prometheus.res.mjs";
7
+ import * as IndexerState from "./IndexerState.res.mjs";
8
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
9
+ import * as InMemoryStore from "./InMemoryStore.res.mjs";
10
+ import * as InMemoryTable from "./InMemoryTable.res.mjs";
11
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
12
+ import * as RollbackCommit from "./RollbackCommit.res.mjs";
13
+ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
14
+ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
15
+
16
+ function getChangesCount(state) {
17
+ let total = {
18
+ contents: 0
19
+ };
20
+ IndexerState.allEntities(state).forEach(entityConfig => {
21
+ total.contents = total.contents + InMemoryStore.getInMemTable(state, entityConfig).changesCount;
22
+ });
23
+ Utils.Dict.forEach(IndexerState.effects(state), inMemTable => {
24
+ total.contents = total.contents + inMemTable.changesCount;
25
+ });
26
+ IndexerState.processedBatches(state).forEach(batch => {
27
+ total.contents = total.contents + batch.totalBatchSize;
28
+ });
29
+ return total.contents;
30
+ }
31
+
32
+ function waitForCommit(state) {
33
+ return new Promise((resolve, param) => IndexerState.addCommitWaiter(state, resolve));
34
+ }
35
+
36
+ function snapshotEffects(state, cache) {
37
+ let acc = [];
38
+ Utils.Dict.forEach(IndexerState.effects(state), inMemTable => {
39
+ let idsToStore = inMemTable.idsToStore;
40
+ let invalidationsCount = inMemTable.invalidationsCount;
41
+ let dict = inMemTable.dict;
42
+ let effect = inMemTable.effect;
43
+ if (idsToStore.length !== 0) {
44
+ let items = Stdlib_Array.filterMap(idsToStore, id => {
45
+ let match = dict[id];
46
+ if (match.type === "SET") {
47
+ return {
48
+ id: id,
49
+ output: match.entity
50
+ };
51
+ }
52
+ });
53
+ let effectName = effect.name;
54
+ let c = cache[effectName];
55
+ let effectCacheRecord;
56
+ if (c !== undefined) {
57
+ effectCacheRecord = c;
58
+ } else {
59
+ let c$1 = {
60
+ effectName: effectName,
61
+ count: 0
62
+ };
63
+ cache[effectName] = c$1;
64
+ effectCacheRecord = c$1;
65
+ }
66
+ let shouldInitialize = effectCacheRecord.count === 0;
67
+ effectCacheRecord.count = (effectCacheRecord.count + items.length | 0) - invalidationsCount | 0;
68
+ Prometheus.EffectCacheCount.set(effectCacheRecord.count, effectName);
69
+ acc.push({
70
+ effect: effect,
71
+ items: items,
72
+ shouldInitialize: shouldInitialize
73
+ });
74
+ }
75
+ inMemTable.idsToStore = [];
76
+ inMemTable.invalidationsCount = 0;
77
+ });
78
+ return acc;
79
+ }
80
+
81
+ async function runOneWrite(state) {
82
+ let persistence = IndexerState.persistence(state);
83
+ let config = IndexerState.config(state);
84
+ let match = persistence.storageStatus;
85
+ let cache;
86
+ cache = typeof match !== "object" || match.TAG === "Initializing" ? Stdlib_JsError.throwWithMessage(`Failed to access the indexer storage. The Persistence layer is not initialized.`) : match._0.cache;
87
+ let chainMetaData = IndexerState.takeChainMetaSnapshot(state);
88
+ let match$1 = IndexerState.processedBatches(state);
89
+ if (match$1.length === 0) {
90
+ if (chainMetaData !== undefined) {
91
+ return await persistence.storage.setChainMeta(chainMetaData);
92
+ } else {
93
+ return;
94
+ }
95
+ }
96
+ let committedCheckpointId = IndexerState.committedCheckpointId(state);
97
+ let batch = IndexerState.drainBatchRun(state);
98
+ let checkpointId = Utils.$$Array.last(batch.checkpointIds);
99
+ let upToCheckpointId = checkpointId !== undefined ? checkpointId : committedCheckpointId;
100
+ let rollback = IndexerState.takeRollback(state);
101
+ let updatedEntities = Stdlib_Array.filterMap(persistence.allEntities, entityConfig => {
102
+ let table = InMemoryStore.getInMemTable(state, entityConfig);
103
+ let changes = InMemoryTable.Entity.snapshotChanges(table, committedCheckpointId, upToCheckpointId);
104
+ if (Utils.$$Array.isEmpty(changes)) {
105
+ return;
106
+ } else {
107
+ return {
108
+ entityConfig: entityConfig,
109
+ changes: changes
110
+ };
111
+ }
112
+ });
113
+ let updatedEffectsCache = snapshotEffects(state, cache);
114
+ await persistence.storage.writeBatch(batch, rollback, batch.isInReorgThreshold, config, persistence.allEntities, updatedEffectsCache, updatedEntities, chainMetaData);
115
+ IndexerState.markCommitted(state, upToCheckpointId);
116
+ if (rollback !== undefined && Utils.$$Array.notEmpty(RollbackCommit.callbacks)) {
117
+ return await RollbackCommit.fire(rollback.progressBlockNumberByChainId);
118
+ }
119
+ }
120
+
121
+ function hasPendingWrite(state) {
122
+ if (Utils.$$Array.notEmpty(IndexerState.processedBatches(state))) {
123
+ return true;
124
+ } else {
125
+ return IndexerState.chainMetaDirty(state);
126
+ }
127
+ }
128
+
129
+ async function runWriteLoop(state) {
130
+ while (hasPendingWrite(state) && !IndexerState.hasFailedWrite(state)) {
131
+ try {
132
+ await runOneWrite(state);
133
+ IndexerState.wakeCommitWaiters(state);
134
+ } catch (raw_exn) {
135
+ let exn = Primitive_exceptions.internalToException(raw_exn);
136
+ IndexerState.recordWriteFailure(state, exn);
137
+ }
138
+ };
139
+ IndexerState.endWriteFiber(state);
140
+ return IndexerState.wakeCommitWaiters(state);
141
+ }
142
+
143
+ function schedule(state) {
144
+ if (Stdlib_Option.isNone(IndexerState.writeFiber(state)) && !IndexerState.hasFailedWrite(state) && hasPendingWrite(state)) {
145
+ return IndexerState.beginWriteFiber(state, runWriteLoop(state));
146
+ }
147
+ }
148
+
149
+ function setChainMeta(state, chainsData) {
150
+ IndexerState.stageChainMeta(state, chainsData);
151
+ if (IndexerState.chainMetaDirty(state)) {
152
+ return Throttler.schedule(IndexerState.chainMetaThrottler(state), () => {
153
+ schedule(state);
154
+ return Promise.resolve();
155
+ });
156
+ }
157
+ }
158
+
159
+ function commitBatch(state, batch) {
160
+ IndexerState.queueProcessedBatch(state, batch);
161
+ schedule(state);
162
+ }
163
+
164
+ function dropCommitted(state, keepLoadedFromDb) {
165
+ let committedCheckpointId = IndexerState.committedCheckpointId(state);
166
+ IndexerState.allEntities(state).forEach(entityConfig => InMemoryTable.Entity.dropCommittedChanges(InMemoryStore.getInMemTable(state, entityConfig), committedCheckpointId, keepLoadedFromDb));
167
+ Utils.Dict.forEach(IndexerState.effects(state), inMemTable => InMemoryStore.dropCommittedEffects(inMemTable, committedCheckpointId, keepLoadedFromDb));
168
+ }
169
+
170
+ async function awaitCapacity(state) {
171
+ if (!IndexerState.hasFailedWrite(state) && getChangesCount(state) >= Env.inMemoryObjectsTarget) {
172
+ dropCommitted(state, true);
173
+ if (getChangesCount(state) >= Env.inMemoryObjectsTarget) {
174
+ dropCommitted(state, false);
175
+ }
176
+ if (getChangesCount(state) >= Env.inMemoryObjectsTarget && Utils.$$Array.notEmpty(IndexerState.processedBatches(state))) {
177
+ schedule(state);
178
+ await new Promise((resolve, param) => IndexerState.addCommitWaiter(state, resolve));
179
+ return await awaitCapacity(state);
180
+ } else {
181
+ return;
182
+ }
183
+ }
184
+ }
185
+
186
+ async function flush(state) {
187
+ if (IndexerState.hasFailedWrite(state)) {
188
+ return;
189
+ }
190
+ schedule(state);
191
+ let fiber = IndexerState.writeFiber(state);
192
+ if (fiber !== undefined) {
193
+ await fiber;
194
+ return await flush(state);
195
+ }
196
+ }
197
+
198
+ let keepLatestChangesLimit = Env.inMemoryObjectsTarget;
199
+
200
+ export {
201
+ keepLatestChangesLimit,
202
+ getChangesCount,
203
+ waitForCommit,
204
+ snapshotEffects,
205
+ runOneWrite,
206
+ hasPendingWrite,
207
+ runWriteLoop,
208
+ schedule,
209
+ setChainMeta,
210
+ commitBatch,
211
+ dropCommitted,
212
+ awaitCapacity,
213
+ flush,
214
+ }
215
+ /* Env Not a pure module */
@@ -571,33 +571,20 @@ GROUP BY "${(#chain_id: field :> string)}";`
571
571
  }
572
572
 
573
573
  module RawEvents = {
574
- type t = {
575
- @as("chain_id") chainId: int,
576
- @as("event_id") eventId: bigint,
577
- @as("event_name") eventName: string,
578
- @as("contract_name") contractName: string,
579
- @as("block_number") blockNumber: int,
580
- @as("log_index") logIndex: int,
581
- @as("src_address") srcAddress: Address.t,
582
- @as("block_hash") blockHash: string,
583
- @as("block_timestamp") blockTimestamp: int,
584
- @as("block_fields") blockFields: JSON.t,
585
- @as("transaction_fields") transactionFields: JSON.t,
586
- params: JSON.t,
587
- }
588
-
589
- let schema = S.schema(s => {
590
- chainId: s.matches(S.int),
591
- eventId: s.matches(S.bigint),
592
- eventName: s.matches(S.string),
593
- contractName: s.matches(S.string),
594
- blockNumber: s.matches(S.int),
595
- logIndex: s.matches(S.int),
596
- srcAddress: s.matches(Address.schema),
597
- blockHash: s.matches(S.string),
598
- blockTimestamp: s.matches(S.int),
599
- blockFields: s.matches(S.json(~validate=false)),
600
- transactionFields: s.matches(S.json(~validate=false)),
574
+ type t = Internal.rawEvent
575
+
576
+ let schema = S.schema((s): t => {
577
+ chain_id: s.matches(S.int),
578
+ event_id: s.matches(S.bigint),
579
+ event_name: s.matches(S.string),
580
+ contract_name: s.matches(S.string),
581
+ block_number: s.matches(S.int),
582
+ log_index: s.matches(S.int),
583
+ src_address: s.matches(Address.schema),
584
+ block_hash: s.matches(S.string),
585
+ block_timestamp: s.matches(S.int),
586
+ block_fields: s.matches(S.json(~validate=false)),
587
+ transaction_fields: s.matches(S.json(~validate=false)),
601
588
  params: s.matches(S.json(~validate=false)),
602
589
  })
603
590
 
@@ -1,10 +1,25 @@
1
+ // EVM's concrete item payload. Erased to `Internal.eventPayload` on the item
2
+ // and recovered here via `toPayload`.
3
+ type payload = {
4
+ contractName: string,
5
+ eventName: string,
6
+ params: Internal.eventParams,
7
+ chainId: int,
8
+ srcAddress: Address.t,
9
+ logIndex: int,
10
+ transaction: Internal.eventTransaction,
11
+ block: Internal.eventBlock,
12
+ }
13
+ external fromPayload: payload => Internal.eventPayload = "%identity"
14
+ external toPayload: Internal.eventPayload => payload = "%identity"
15
+
1
16
  let cleanUpRawEventFieldsInPlace: JSON.t => unit = %raw(`fields => {
2
17
  delete fields.hash
3
18
  delete fields.number
4
19
  delete fields.timestamp
5
20
  }`)
6
21
 
7
- let ecosystem: Ecosystem.t = {
22
+ let make = (~logger: Pino.t): Ecosystem.t => {
8
23
  name: Evm,
9
24
  blockFields: [
10
25
  "number",
@@ -90,4 +105,28 @@ let ecosystem: Ecosystem.t = {
90
105
  onEventBlockFilterSchema: S.object(s =>
91
106
  s.field("block", S.option(S.object(s2 => s2.field("number", S.unknown))))
92
107
  ),
108
+ logger,
109
+ toEvent: eventItem => eventItem.payload->Internal.payloadToEvent,
110
+ toEventLogger: eventItem =>
111
+ Logging.createChildFrom(
112
+ ~logger,
113
+ ~params={
114
+ "contract": eventItem.eventConfig.contractName,
115
+ "event": eventItem.eventConfig.name,
116
+ "chainId": eventItem.chain->ChainMap.Chain.toChainId,
117
+ "block": eventItem.blockNumber,
118
+ "logIndex": eventItem.logIndex,
119
+ "address": (eventItem.payload->toPayload).srcAddress,
120
+ },
121
+ ),
122
+ toRawEvent: eventItem => {
123
+ let payload = eventItem.payload->toPayload
124
+ eventItem->RawEvent.make(
125
+ ~block=payload.block,
126
+ ~transaction=payload.transaction,
127
+ ~params=payload.params,
128
+ ~srcAddress=payload.srcAddress,
129
+ ~cleanUpRawEventFieldsInPlace,
130
+ )
131
+ },
93
132
  }
@@ -1,5 +1,7 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
+ import * as Logging from "../Logging.res.mjs";
4
+ import * as RawEvent from "../RawEvent.res.mjs";
3
5
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
4
6
 
5
7
  let cleanUpRawEventFieldsInPlace = (fields => {
@@ -8,91 +10,99 @@ let cleanUpRawEventFieldsInPlace = (fields => {
8
10
  delete fields.timestamp
9
11
  });
10
12
 
11
- let ecosystem_blockFields = [
12
- "number",
13
- "timestamp",
14
- "hash",
15
- "parentHash",
16
- "nonce",
17
- "sha3Uncles",
18
- "logsBloom",
19
- "transactionsRoot",
20
- "stateRoot",
21
- "receiptsRoot",
22
- "miner",
23
- "difficulty",
24
- "totalDifficulty",
25
- "extraData",
26
- "size",
27
- "gasLimit",
28
- "gasUsed",
29
- "uncles",
30
- "baseFeePerGas",
31
- "blobGasUsed",
32
- "excessBlobGas",
33
- "parentBeaconBlockRoot",
34
- "withdrawalsRoot",
35
- "l1BlockNumber",
36
- "sendCount",
37
- "sendRoot",
38
- "mixHash"
39
- ];
40
-
41
- let ecosystem_transactionFields = [
42
- "transactionIndex",
43
- "hash",
44
- "from",
45
- "to",
46
- "gas",
47
- "gasPrice",
48
- "maxPriorityFeePerGas",
49
- "maxFeePerGas",
50
- "cumulativeGasUsed",
51
- "effectiveGasPrice",
52
- "gasUsed",
53
- "input",
54
- "nonce",
55
- "value",
56
- "v",
57
- "r",
58
- "s",
59
- "contractAddress",
60
- "logsBloom",
61
- "root",
62
- "status",
63
- "yParity",
64
- "chainId",
65
- "maxFeePerBlobGas",
66
- "blobVersionedHashes",
67
- "type",
68
- "l1Fee",
69
- "l1GasPrice",
70
- "l1GasUsed",
71
- "l1FeeScalar",
72
- "gasUsedForL1",
73
- "accessList",
74
- "authorizationList"
75
- ];
76
-
77
- let ecosystem_onBlockFilterSchema = S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("number", S$RescriptSchema.unknown)))));
78
-
79
- let ecosystem_onEventBlockFilterSchema = S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("number", S$RescriptSchema.unknown)))));
80
-
81
- let ecosystem = {
82
- name: "evm",
83
- blockFields: ecosystem_blockFields,
84
- transactionFields: ecosystem_transactionFields,
85
- blockNumberName: "number",
86
- blockTimestampName: "timestamp",
87
- blockHashName: "hash",
88
- cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace,
89
- onBlockMethodName: "onBlock",
90
- onBlockFilterSchema: ecosystem_onBlockFilterSchema,
91
- onEventBlockFilterSchema: ecosystem_onEventBlockFilterSchema
92
- };
13
+ function make(logger) {
14
+ return {
15
+ name: "evm",
16
+ blockFields: [
17
+ "number",
18
+ "timestamp",
19
+ "hash",
20
+ "parentHash",
21
+ "nonce",
22
+ "sha3Uncles",
23
+ "logsBloom",
24
+ "transactionsRoot",
25
+ "stateRoot",
26
+ "receiptsRoot",
27
+ "miner",
28
+ "difficulty",
29
+ "totalDifficulty",
30
+ "extraData",
31
+ "size",
32
+ "gasLimit",
33
+ "gasUsed",
34
+ "uncles",
35
+ "baseFeePerGas",
36
+ "blobGasUsed",
37
+ "excessBlobGas",
38
+ "parentBeaconBlockRoot",
39
+ "withdrawalsRoot",
40
+ "l1BlockNumber",
41
+ "sendCount",
42
+ "sendRoot",
43
+ "mixHash"
44
+ ],
45
+ transactionFields: [
46
+ "transactionIndex",
47
+ "hash",
48
+ "from",
49
+ "to",
50
+ "gas",
51
+ "gasPrice",
52
+ "maxPriorityFeePerGas",
53
+ "maxFeePerGas",
54
+ "cumulativeGasUsed",
55
+ "effectiveGasPrice",
56
+ "gasUsed",
57
+ "input",
58
+ "nonce",
59
+ "value",
60
+ "v",
61
+ "r",
62
+ "s",
63
+ "contractAddress",
64
+ "logsBloom",
65
+ "root",
66
+ "status",
67
+ "yParity",
68
+ "chainId",
69
+ "maxFeePerBlobGas",
70
+ "blobVersionedHashes",
71
+ "type",
72
+ "l1Fee",
73
+ "l1GasPrice",
74
+ "l1GasUsed",
75
+ "l1FeeScalar",
76
+ "gasUsedForL1",
77
+ "accessList",
78
+ "authorizationList"
79
+ ],
80
+ blockNumberName: "number",
81
+ blockTimestampName: "timestamp",
82
+ blockHashName: "hash",
83
+ cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace,
84
+ onBlockMethodName: "onBlock",
85
+ onBlockFilterSchema: S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("number", S$RescriptSchema.unknown))))),
86
+ onEventBlockFilterSchema: S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("number", S$RescriptSchema.unknown))))),
87
+ logger: logger,
88
+ toEvent: eventItem => eventItem.payload,
89
+ toEventLogger: eventItem => Logging.createChildFrom(logger, {
90
+ contract: eventItem.eventConfig.contractName,
91
+ event: eventItem.eventConfig.name,
92
+ chainId: eventItem.chain,
93
+ block: eventItem.blockNumber,
94
+ logIndex: eventItem.logIndex,
95
+ address: eventItem.payload.srcAddress
96
+ }),
97
+ toRawEvent: eventItem => {
98
+ let payload = eventItem.payload;
99
+ return RawEvent.make(eventItem, payload.block, payload.transaction, payload.params, payload.srcAddress, cleanUpRawEventFieldsInPlace);
100
+ }
101
+ };
102
+ }
93
103
 
94
104
  export {
95
105
  cleanUpRawEventFieldsInPlace,
96
- ecosystem,
106
+ make,
97
107
  }
98
- /* ecosystem Not a pure module */
108
+ /* Logging Not a pure module */
@@ -1,10 +1,25 @@
1
+ // Fuel's concrete item payload. Erased to `Internal.eventPayload` on the item
2
+ // and recovered here via `toPayload`.
3
+ type payload = {
4
+ contractName: string,
5
+ eventName: string,
6
+ params: Internal.eventParams,
7
+ chainId: int,
8
+ srcAddress: Address.t,
9
+ logIndex: int,
10
+ transaction: Internal.eventTransaction,
11
+ block: Internal.eventBlock,
12
+ }
13
+ external fromPayload: payload => Internal.eventPayload = "%identity"
14
+ external toPayload: Internal.eventPayload => payload = "%identity"
15
+
1
16
  let cleanUpRawEventFieldsInPlace: JSON.t => unit = %raw(`fields => {
2
17
  delete fields.id
3
18
  delete fields.height
4
19
  delete fields.time
5
20
  }`)
6
21
 
7
- let ecosystem: Ecosystem.t = {
22
+ let make = (~logger: Pino.t): Ecosystem.t => {
8
23
  name: Fuel,
9
24
  blockFields: ["id", "height", "time"],
10
25
  transactionFields: ["id"],
@@ -25,4 +40,28 @@ let ecosystem: Ecosystem.t = {
25
40
  onEventBlockFilterSchema: S.object(s =>
26
41
  s.field("block", S.option(S.object(s2 => s2.field("height", S.unknown))))
27
42
  ),
43
+ logger,
44
+ toEvent: eventItem => eventItem.payload->Internal.payloadToEvent,
45
+ toEventLogger: eventItem =>
46
+ Logging.createChildFrom(
47
+ ~logger,
48
+ ~params={
49
+ "contract": eventItem.eventConfig.contractName,
50
+ "event": eventItem.eventConfig.name,
51
+ "chainId": eventItem.chain->ChainMap.Chain.toChainId,
52
+ "block": eventItem.blockNumber,
53
+ "logIndex": eventItem.logIndex,
54
+ "address": (eventItem.payload->toPayload).srcAddress,
55
+ },
56
+ ),
57
+ toRawEvent: eventItem => {
58
+ let payload = eventItem.payload->toPayload
59
+ eventItem->RawEvent.make(
60
+ ~block=payload.block,
61
+ ~transaction=payload.transaction,
62
+ ~params=payload.params,
63
+ ~srcAddress=payload.srcAddress,
64
+ ~cleanUpRawEventFieldsInPlace,
65
+ )
66
+ },
28
67
  }
@@ -1,5 +1,7 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
+ import * as Logging from "../Logging.res.mjs";
4
+ import * as RawEvent from "../RawEvent.res.mjs";
3
5
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
4
6
 
5
7
  let cleanUpRawEventFieldsInPlace = (fields => {
@@ -8,33 +10,41 @@ let cleanUpRawEventFieldsInPlace = (fields => {
8
10
  delete fields.time
9
11
  });
10
12
 
11
- let ecosystem_blockFields = [
12
- "id",
13
- "height",
14
- "time"
15
- ];
16
-
17
- let ecosystem_transactionFields = ["id"];
18
-
19
- let ecosystem_onBlockFilterSchema = S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("height", S$RescriptSchema.unknown)))));
20
-
21
- let ecosystem_onEventBlockFilterSchema = S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("height", S$RescriptSchema.unknown)))));
22
-
23
- let ecosystem = {
24
- name: "fuel",
25
- blockFields: ecosystem_blockFields,
26
- transactionFields: ecosystem_transactionFields,
27
- blockNumberName: "height",
28
- blockTimestampName: "time",
29
- blockHashName: "id",
30
- cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace,
31
- onBlockMethodName: "onBlock",
32
- onBlockFilterSchema: ecosystem_onBlockFilterSchema,
33
- onEventBlockFilterSchema: ecosystem_onEventBlockFilterSchema
34
- };
13
+ function make(logger) {
14
+ return {
15
+ name: "fuel",
16
+ blockFields: [
17
+ "id",
18
+ "height",
19
+ "time"
20
+ ],
21
+ transactionFields: ["id"],
22
+ blockNumberName: "height",
23
+ blockTimestampName: "time",
24
+ blockHashName: "id",
25
+ cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace,
26
+ onBlockMethodName: "onBlock",
27
+ onBlockFilterSchema: S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("height", S$RescriptSchema.unknown))))),
28
+ onEventBlockFilterSchema: S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("height", S$RescriptSchema.unknown))))),
29
+ logger: logger,
30
+ toEvent: eventItem => eventItem.payload,
31
+ toEventLogger: eventItem => Logging.createChildFrom(logger, {
32
+ contract: eventItem.eventConfig.contractName,
33
+ event: eventItem.eventConfig.name,
34
+ chainId: eventItem.chain,
35
+ block: eventItem.blockNumber,
36
+ logIndex: eventItem.logIndex,
37
+ address: eventItem.payload.srcAddress
38
+ }),
39
+ toRawEvent: eventItem => {
40
+ let payload = eventItem.payload;
41
+ return RawEvent.make(eventItem, payload.block, payload.transaction, payload.params, payload.srcAddress, cleanUpRawEventFieldsInPlace);
42
+ }
43
+ };
44
+ }
35
45
 
36
46
  export {
37
47
  cleanUpRawEventFieldsInPlace,
38
- ecosystem,
48
+ make,
39
49
  }
40
- /* ecosystem Not a pure module */
50
+ /* Logging Not a pure module */