envio 3.2.0 → 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.
- package/package.json +6 -7
- package/src/Batch.res +12 -15
- package/src/Batch.res.mjs +4 -5
- package/src/BatchProcessing.res +199 -0
- package/src/BatchProcessing.res.mjs +125 -0
- package/src/ChainFetching.res +375 -0
- package/src/ChainFetching.res.mjs +206 -0
- package/src/ChainMetadata.res +27 -0
- package/src/ChainMetadata.res.mjs +27 -0
- package/src/ChainState.res +618 -0
- package/src/ChainState.res.mjs +461 -0
- package/src/ChainState.resi +85 -0
- package/src/Config.res +13 -4
- package/src/Config.res.mjs +8 -3
- package/src/ContractRegisterContext.res +106 -0
- package/src/ContractRegisterContext.res.mjs +76 -0
- package/src/Core.res +3 -0
- package/src/CrossChainState.res +269 -0
- package/src/CrossChainState.res.mjs +197 -0
- package/src/CrossChainState.resi +47 -0
- package/src/Ecosystem.res +58 -0
- package/src/Ecosystem.res.mjs +43 -1
- package/src/Env.res +7 -2
- package/src/Env.res.mjs +5 -2
- package/src/EventConfigBuilder.res +35 -0
- package/src/EventConfigBuilder.res.mjs +21 -0
- package/src/EventProcessing.res +60 -46
- package/src/EventProcessing.res.mjs +33 -32
- package/src/EventUtils.res +0 -4
- package/src/EventUtils.res.mjs +0 -4
- package/src/ExitOnCaughtUp.res +10 -0
- package/src/ExitOnCaughtUp.res.mjs +22 -0
- package/src/FetchState.res +162 -113
- package/src/FetchState.res.mjs +181 -119
- package/src/HandlerLoader.res +6 -1
- package/src/HandlerLoader.res.mjs +13 -36
- package/src/InMemoryStore.res +36 -451
- package/src/InMemoryStore.res.mjs +20 -369
- package/src/IndexerLoop.res +44 -0
- package/src/IndexerLoop.res.mjs +46 -0
- package/src/IndexerState.res +544 -0
- package/src/IndexerState.res.mjs +547 -0
- package/src/IndexerState.resi +132 -0
- package/src/Internal.res +44 -7
- package/src/LoadLayer.res +20 -18
- package/src/LoadLayer.res.mjs +14 -12
- package/src/LoadLayer.resi +6 -3
- package/src/LogSelection.res +86 -17
- package/src/LogSelection.res.mjs +67 -14
- package/src/Logging.res +11 -44
- package/src/Logging.res.mjs +10 -42
- package/src/Main.res +54 -79
- package/src/Main.res.mjs +44 -56
- package/src/PgStorage.res +8 -71
- package/src/PgStorage.res.mjs +3 -47
- package/src/Prometheus.res +7 -8
- package/src/Prometheus.res.mjs +7 -4
- package/src/PruneStaleHistory.res +45 -0
- package/src/PruneStaleHistory.res.mjs +46 -0
- package/src/RawEvent.res +73 -0
- package/src/RawEvent.res.mjs +51 -0
- package/src/Rollback.res +204 -0
- package/src/Rollback.res.mjs +118 -0
- package/src/SimulateItems.res +12 -10
- package/src/SimulateItems.res.mjs +1 -1
- package/src/TestIndexer.res +34 -27
- package/src/TestIndexer.res.mjs +4 -1
- package/src/UserContext.res +26 -114
- package/src/UserContext.res.mjs +15 -78
- package/src/Writing.res +242 -0
- package/src/Writing.res.mjs +215 -0
- package/src/db/InternalTable.res +14 -27
- package/src/sources/Evm.res +40 -1
- package/src/sources/Evm.res.mjs +94 -84
- package/src/sources/Fuel.res +40 -1
- package/src/sources/Fuel.res.mjs +36 -26
- package/src/sources/HyperFuel.res +41 -120
- package/src/sources/HyperFuel.res.mjs +42 -80
- package/src/sources/HyperFuel.resi +1 -24
- package/src/sources/HyperFuelClient.res +16 -297
- package/src/sources/HyperFuelClient.res.mjs +5 -4
- package/src/sources/HyperFuelSource.res +33 -8
- package/src/sources/HyperFuelSource.res.mjs +56 -10
- package/src/sources/HyperSyncSource.res +7 -5
- package/src/sources/HyperSyncSource.res.mjs +3 -3
- package/src/sources/RpcSource.res +2 -2
- package/src/sources/RpcSource.res.mjs +1 -1
- package/src/sources/SourceManager.res +8 -18
- package/src/sources/SourceManager.res.mjs +8 -5
- package/src/sources/SourceManager.resi +4 -1
- package/src/sources/Svm.res +18 -1
- package/src/sources/Svm.res.mjs +30 -22
- package/src/sources/SvmHyperSyncSource.res +1 -1
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
- package/src/tui/Tui.res +38 -36
- package/src/tui/Tui.res.mjs +51 -51
- package/src/ChainFetcher.res +0 -519
- package/src/ChainFetcher.res.mjs +0 -314
- package/src/ChainManager.res +0 -358
- package/src/ChainManager.res.mjs +0 -291
- package/src/Ctx.res +0 -6
- package/src/Ctx.res.mjs +0 -2
- package/src/GlobalState.res +0 -1056
- package/src/GlobalState.res.mjs +0 -1086
- package/src/GlobalStateManager.res +0 -57
- package/src/GlobalStateManager.res.mjs +0 -68
- package/src/GlobalStateManager.resi +0 -7
- package/src/Ports.res +0 -5
- package/src/Ports.res.mjs +0 -9
- package/src/adapters/MarkBatchProcessedAdapter.res +0 -5
- package/src/adapters/MarkBatchProcessedAdapter.res.mjs +0 -14
- package/src/sources/EnvioApiClient.res +0 -15
- package/src/sources/EnvioApiClient.res.mjs +0 -24
package/src/SimulateItems.res
CHANGED
|
@@ -288,16 +288,18 @@ let parse = (~simulateItems: array<JSON.t>, ~config: Config.t, ~chainConfig: Con
|
|
|
288
288
|
blockNumber,
|
|
289
289
|
blockHash,
|
|
290
290
|
logIndex,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
291
|
+
payload: (
|
|
292
|
+
{
|
|
293
|
+
contractName: eventConfig.contractName,
|
|
294
|
+
eventName: eventConfig.name,
|
|
295
|
+
params,
|
|
296
|
+
chainId,
|
|
297
|
+
srcAddress,
|
|
298
|
+
logIndex,
|
|
299
|
+
transaction,
|
|
300
|
+
block,
|
|
301
|
+
}: Evm.payload
|
|
302
|
+
)->Evm.fromPayload,
|
|
301
303
|
}),
|
|
302
304
|
)
|
|
303
305
|
->ignore
|
|
@@ -241,7 +241,7 @@ function parse(simulateItems, config, chainConfig) {
|
|
|
241
241
|
blockNumber: blockNumber,
|
|
242
242
|
blockHash: match$3[3],
|
|
243
243
|
logIndex: logIndex,
|
|
244
|
-
|
|
244
|
+
payload: {
|
|
245
245
|
contractName: eventConfig.contractName,
|
|
246
246
|
eventName: eventConfig.name,
|
|
247
247
|
params: params,
|
package/src/TestIndexer.res
CHANGED
|
@@ -44,35 +44,42 @@ let toIndexingAddress = (dc: InternalTable.EnvioAddresses.t): Internal.indexingA
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
let handleLoad = (state: testIndexerState, ~tableName: string, ~filter: EntityFilter.t): JSON.t => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
let
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// Cast entity to dict of field values (same approach as InMemoryTable)
|
|
67
|
-
let entityAsDict = entity->(Utils.magic: Internal.entity => dict<EntityFilter.FieldValue.t>)
|
|
68
|
-
if filter->EntityFilter.matches(~entity=entityAsDict) {
|
|
69
|
-
// Serialize entity back to JSON for worker thread
|
|
70
|
-
let jsonEntity = entity->S.reverseConvertToJsonOrThrow(entityConfig.schema)
|
|
71
|
-
results->Array.push(jsonEntity)->ignore
|
|
47
|
+
// Loads for non-entity tables (e.g. effect caches `envio_effect_<name>`) reach
|
|
48
|
+
// here too. TestIndexer never persists those, so there's nothing to return —
|
|
49
|
+
// an empty result makes the effect recompute instead of crashing on a missing
|
|
50
|
+
// entityConfig.
|
|
51
|
+
switch state.entityConfigs->Dict.get(tableName) {
|
|
52
|
+
| None => []->JSON.Encode.array
|
|
53
|
+
| Some(entityConfig) =>
|
|
54
|
+
let entityDict = state.entities->Dict.get(tableName)->Option.getOr(Dict.make())
|
|
55
|
+
let results = []
|
|
56
|
+
|
|
57
|
+
// Field values arrive as JSON from the worker boundary, so parse them
|
|
58
|
+
// with the field's schema before comparing. This properly handles
|
|
59
|
+
// bigint and BigDecimal comparisons
|
|
60
|
+
let parseLeaf = (~fieldName, ~fieldValue: unknown, ~isArray): unknown => {
|
|
61
|
+
let queryField = switch entityConfig.table->Table.queryFields->Dict.get(fieldName) {
|
|
62
|
+
| Some(queryField) => queryField
|
|
63
|
+
| None => JsError.throwWithMessage(`Field ${fieldName} not found in entity ${tableName}`)
|
|
64
|
+
}
|
|
65
|
+
fieldValue->S.convertOrThrow(isArray ? queryField.arrayFieldSchema : queryField.fieldSchema)
|
|
72
66
|
}
|
|
73
|
-
|
|
67
|
+
let filter = filter->EntityFilter.mapValues(~mapValue=parseLeaf)
|
|
68
|
+
|
|
69
|
+
entityDict
|
|
70
|
+
->Dict.valuesToArray
|
|
71
|
+
->Array.forEach(entity => {
|
|
72
|
+
// Cast entity to dict of field values (same approach as InMemoryTable)
|
|
73
|
+
let entityAsDict = entity->(Utils.magic: Internal.entity => dict<EntityFilter.FieldValue.t>)
|
|
74
|
+
if filter->EntityFilter.matches(~entity=entityAsDict) {
|
|
75
|
+
// Serialize entity back to JSON for worker thread
|
|
76
|
+
let jsonEntity = entity->S.reverseConvertToJsonOrThrow(entityConfig.schema)
|
|
77
|
+
results->Array.push(jsonEntity)->ignore
|
|
78
|
+
}
|
|
79
|
+
})
|
|
74
80
|
|
|
75
|
-
|
|
81
|
+
results->JSON.Encode.array
|
|
82
|
+
}
|
|
76
83
|
}
|
|
77
84
|
|
|
78
85
|
let handleWriteBatch = (
|
package/src/TestIndexer.res.mjs
CHANGED
|
@@ -33,8 +33,11 @@ function toIndexingAddress(dc) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function handleLoad(state, tableName, filter) {
|
|
36
|
-
let entityDict = Stdlib_Option.getOr(state.entities[tableName], {});
|
|
37
36
|
let entityConfig = state.entityConfigs[tableName];
|
|
37
|
+
if (entityConfig === undefined) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
let entityDict = Stdlib_Option.getOr(state.entities[tableName], {});
|
|
38
41
|
let results = [];
|
|
39
42
|
let parseLeaf = (fieldName, fieldValue, isArray) => {
|
|
40
43
|
let queryField = Table.queryFields(entityConfig.table)[fieldName];
|
package/src/UserContext.res
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
type contextParams = {
|
|
2
2
|
item: Internal.item,
|
|
3
3
|
checkpointId: Internal.checkpointId,
|
|
4
|
-
|
|
4
|
+
indexerState: IndexerState.t,
|
|
5
5
|
loadManager: LoadManager.t,
|
|
6
6
|
persistence: Persistence.t,
|
|
7
7
|
isPreload: bool,
|
|
@@ -22,7 +22,8 @@ Utils.Object.defineProperty(
|
|
|
22
22
|
{
|
|
23
23
|
// Wrap with toMethod so `this` binds to the EffectContext instance.
|
|
24
24
|
get: Utils.toMethod(() => {
|
|
25
|
-
|
|
25
|
+
let params = paramsByThis->Utils.WeakMap.unsafeGet(%raw(`this`))
|
|
26
|
+
Ecosystem.getItemUserLogger(params.item, ~ecosystem=params.config.ecosystem)
|
|
26
27
|
}),
|
|
27
28
|
},
|
|
28
29
|
)
|
|
@@ -60,9 +61,10 @@ let initEffect = (params: contextParams) => {
|
|
|
60
61
|
~persistence=params.persistence,
|
|
61
62
|
~effect,
|
|
62
63
|
~effectArgs,
|
|
63
|
-
~
|
|
64
|
+
~indexerState=params.indexerState,
|
|
64
65
|
~shouldGroup=params.isPreload,
|
|
65
66
|
~item=params.item,
|
|
67
|
+
~ecosystem=params.config.ecosystem,
|
|
66
68
|
)
|
|
67
69
|
}
|
|
68
70
|
callEffect
|
|
@@ -82,9 +84,10 @@ let getWhereHandler = (params: entityContextParams, filter: dict<dict<unknown>>)
|
|
|
82
84
|
~loadManager=params.loadManager,
|
|
83
85
|
~persistence=params.persistence,
|
|
84
86
|
~entityConfig,
|
|
85
|
-
~
|
|
87
|
+
~indexerState=params.indexerState,
|
|
86
88
|
~shouldGroup=params.isPreload,
|
|
87
89
|
~item=params.item,
|
|
90
|
+
~ecosystem=params.config.ecosystem,
|
|
88
91
|
~filter,
|
|
89
92
|
)
|
|
90
93
|
|
|
@@ -121,10 +124,10 @@ let entityTraps: Utils.Proxy.traps<entityContextParams> = {
|
|
|
121
124
|
let set = params.isPreload
|
|
122
125
|
? noopSet
|
|
123
126
|
: (entity: Internal.entity) => {
|
|
124
|
-
params.
|
|
127
|
+
params.indexerState
|
|
125
128
|
->InMemoryStore.getInMemTable(~entityConfig=params.entityConfig)
|
|
126
129
|
->InMemoryTable.Entity.set(
|
|
127
|
-
~committedCheckpointId=params.
|
|
130
|
+
~committedCheckpointId=params.indexerState->IndexerState.committedCheckpointId,
|
|
128
131
|
Set({
|
|
129
132
|
entityId: entity.id,
|
|
130
133
|
checkpointId: params.checkpointId,
|
|
@@ -146,9 +149,10 @@ let entityTraps: Utils.Proxy.traps<entityContextParams> = {
|
|
|
146
149
|
~loadManager=params.loadManager,
|
|
147
150
|
~persistence=params.persistence,
|
|
148
151
|
~entityConfig=params.entityConfig,
|
|
149
|
-
~
|
|
152
|
+
~indexerState=params.indexerState,
|
|
150
153
|
~shouldGroup=params.isPreload,
|
|
151
154
|
~item=params.item,
|
|
155
|
+
~ecosystem=params.config.ecosystem,
|
|
152
156
|
~entityId,
|
|
153
157
|
)
|
|
154
158
|
)->(Utils.magic: (string => promise<option<Internal.entity>>) => unknown)
|
|
@@ -177,9 +181,10 @@ let entityTraps: Utils.Proxy.traps<entityContextParams> = {
|
|
|
177
181
|
~loadManager=params.loadManager,
|
|
178
182
|
~persistence=params.persistence,
|
|
179
183
|
~entityConfig=params.entityConfig,
|
|
180
|
-
~
|
|
184
|
+
~indexerState=params.indexerState,
|
|
181
185
|
~shouldGroup=params.isPreload,
|
|
182
186
|
~item=params.item,
|
|
187
|
+
~ecosystem=params.config.ecosystem,
|
|
183
188
|
~entityId,
|
|
184
189
|
)->Promise.thenResolve(entity => {
|
|
185
190
|
switch entity {
|
|
@@ -206,9 +211,10 @@ let entityTraps: Utils.Proxy.traps<entityContextParams> = {
|
|
|
206
211
|
~loadManager=params.loadManager,
|
|
207
212
|
~persistence=params.persistence,
|
|
208
213
|
~entityConfig=params.entityConfig,
|
|
209
|
-
~
|
|
214
|
+
~indexerState=params.indexerState,
|
|
210
215
|
~shouldGroup=params.isPreload,
|
|
211
216
|
~item=params.item,
|
|
217
|
+
~ecosystem=params.config.ecosystem,
|
|
212
218
|
~entityId=entity.id,
|
|
213
219
|
)->Promise.thenResolve(storageEntity => {
|
|
214
220
|
switch storageEntity {
|
|
@@ -227,10 +233,10 @@ let entityTraps: Utils.Proxy.traps<entityContextParams> = {
|
|
|
227
233
|
noopDeleteUnsafe
|
|
228
234
|
} else {
|
|
229
235
|
entityId => {
|
|
230
|
-
params.
|
|
236
|
+
params.indexerState
|
|
231
237
|
->InMemoryStore.getInMemTable(~entityConfig=params.entityConfig)
|
|
232
238
|
->InMemoryTable.Entity.set(
|
|
233
|
-
~committedCheckpointId=params.
|
|
239
|
+
~committedCheckpointId=params.indexerState->IndexerState.committedCheckpointId,
|
|
234
240
|
Delete({
|
|
235
241
|
entityId,
|
|
236
242
|
checkpointId: params.checkpointId,
|
|
@@ -250,13 +256,17 @@ let handlerTraps: Utils.Proxy.traps<contextParams> = {
|
|
|
250
256
|
if params.isResolved {
|
|
251
257
|
Utils.Error.make(
|
|
252
258
|
`Impossible to access context.${prop} after the handler is resolved. Make sure you didn't miss an await in the handler.`,
|
|
253
|
-
)->ErrorHandling.mkLogAndRaise(
|
|
259
|
+
)->ErrorHandling.mkLogAndRaise(
|
|
260
|
+
~logger=Ecosystem.getItemLogger(params.item, ~ecosystem=params.config.ecosystem),
|
|
261
|
+
)
|
|
254
262
|
}
|
|
255
263
|
switch prop {
|
|
256
264
|
| "log" =>
|
|
257
|
-
(
|
|
258
|
-
|
|
259
|
-
|
|
265
|
+
(
|
|
266
|
+
params.isPreload
|
|
267
|
+
? Logging.noopLogger
|
|
268
|
+
: Ecosystem.getItemUserLogger(params.item, ~ecosystem=params.config.ecosystem)
|
|
269
|
+
)->(Utils.magic: Envio.logger => unknown)
|
|
260
270
|
|
|
261
271
|
| "effect" =>
|
|
262
272
|
initEffect((params :> contextParams))->(
|
|
@@ -277,7 +287,7 @@ let handlerTraps: Utils.Proxy.traps<contextParams> = {
|
|
|
277
287
|
{
|
|
278
288
|
item: params.item,
|
|
279
289
|
isPreload: params.isPreload,
|
|
280
|
-
|
|
290
|
+
indexerState: params.indexerState,
|
|
281
291
|
loadManager: params.loadManager,
|
|
282
292
|
persistence: params.persistence,
|
|
283
293
|
checkpointId: params.checkpointId,
|
|
@@ -300,101 +310,3 @@ let handlerTraps: Utils.Proxy.traps<contextParams> = {
|
|
|
300
310
|
let getHandlerContext = (params: contextParams): Internal.handlerContext => {
|
|
301
311
|
params->Utils.Proxy.make(handlerTraps)->(Utils.magic: contextParams => Internal.handlerContext)
|
|
302
312
|
}
|
|
303
|
-
|
|
304
|
-
// Contract register context creation
|
|
305
|
-
type contractRegisterParams = {
|
|
306
|
-
item: Internal.item,
|
|
307
|
-
onRegister: (~item: Internal.item, ~contractAddress: Address.t, ~contractName: string) => unit,
|
|
308
|
-
config: Config.t,
|
|
309
|
-
mutable isResolved: bool,
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// Helper to create a validated add function for contract registration.
|
|
313
|
-
// The isResolved check has to live inside the returned closure (not just in the
|
|
314
|
-
// outer proxy trap) because users can capture `const add = context.chain.X.add`
|
|
315
|
-
// before awaiting — a later call would otherwise bypass the resolved guard.
|
|
316
|
-
let makeAddFunction = (~params: contractRegisterParams, ~contractName: string): (
|
|
317
|
-
Address.t => unit
|
|
318
|
-
) => {
|
|
319
|
-
(contractAddress: Address.t) => {
|
|
320
|
-
if params.isResolved {
|
|
321
|
-
Utils.Error.make(`Impossible to access context.chain after the contract register is resolved. Make sure you didn't miss an await in the handler.`)->ErrorHandling.mkLogAndRaise(
|
|
322
|
-
~logger=params.item->Logging.getItemLogger,
|
|
323
|
-
)
|
|
324
|
-
}
|
|
325
|
-
let validatedAddress = if params.config.ecosystem.name === Evm {
|
|
326
|
-
// The value is passed from the user-land,
|
|
327
|
-
// so we need to validate and checksum/lowercase the address.
|
|
328
|
-
if params.config.lowercaseAddresses {
|
|
329
|
-
contractAddress->Address.Evm.fromAddressLowercaseOrThrow
|
|
330
|
-
} else {
|
|
331
|
-
contractAddress->Address.Evm.fromAddressOrThrow
|
|
332
|
-
}
|
|
333
|
-
} else {
|
|
334
|
-
// TODO: Ideally we should do the same for other ecosystems
|
|
335
|
-
contractAddress
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
params.onRegister(~item=params.item, ~contractAddress=validatedAddress, ~contractName)
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// Chain proxy for contractRegister context: context.chain.ContractName.add(address)
|
|
343
|
-
let contractRegisterChainTraps: Utils.Proxy.traps<contractRegisterParams> = {
|
|
344
|
-
get: (~target as params, ~prop: unknown) => {
|
|
345
|
-
let prop = prop->(Utils.magic: unknown => string)
|
|
346
|
-
switch prop {
|
|
347
|
-
| "id" =>
|
|
348
|
-
let eventItem = params.item->Internal.castUnsafeEventItem
|
|
349
|
-
eventItem.chain->ChainMap.Chain.toChainId->(Utils.magic: int => unknown)
|
|
350
|
-
| _ =>
|
|
351
|
-
// Look up the contract name directly in config contracts across all chains.
|
|
352
|
-
let contractName = prop
|
|
353
|
-
let isValidContract =
|
|
354
|
-
params.config.chainMap
|
|
355
|
-
->ChainMap.values
|
|
356
|
-
->Array.some(chain => chain.contracts->Array.some(c => c.name === contractName))
|
|
357
|
-
if isValidContract {
|
|
358
|
-
let addFn = makeAddFunction(~params, ~contractName)
|
|
359
|
-
{"add": addFn}->(Utils.magic: {"add": Address.t => unit} => unknown)
|
|
360
|
-
} else {
|
|
361
|
-
JsError.throwWithMessage(
|
|
362
|
-
`Invalid contract name '${prop}' on context.chain. ${EntityFilter.codegenHelpMessage}`,
|
|
363
|
-
)
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
},
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
let contractRegisterTraps: Utils.Proxy.traps<contractRegisterParams> = {
|
|
370
|
-
get: (~target as params, ~prop: unknown) => {
|
|
371
|
-
let prop = prop->(Utils.magic: unknown => string)
|
|
372
|
-
if params.isResolved {
|
|
373
|
-
Utils.Error.make(
|
|
374
|
-
`Impossible to access context.${prop} after the contract register is resolved. Make sure you didn't miss an await in the handler.`,
|
|
375
|
-
)->ErrorHandling.mkLogAndRaise(~logger=params.item->Logging.getItemLogger)
|
|
376
|
-
}
|
|
377
|
-
switch prop {
|
|
378
|
-
| "log" => params.item->Logging.getUserLogger->(Utils.magic: Envio.logger => unknown)
|
|
379
|
-
| "chain" =>
|
|
380
|
-
params
|
|
381
|
-
->Utils.Proxy.make(contractRegisterChainTraps)
|
|
382
|
-
->(Utils.magic: contractRegisterParams => unknown)
|
|
383
|
-
| _ =>
|
|
384
|
-
JsError.throwWithMessage(
|
|
385
|
-
`Invalid context access by '${prop}' property. Use context.chain.ContractName.add(address) to register contracts. ${EntityFilter.codegenHelpMessage}`,
|
|
386
|
-
)
|
|
387
|
-
}
|
|
388
|
-
},
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
let getContractRegisterContext = (params: contractRegisterParams) => {
|
|
392
|
-
params
|
|
393
|
-
->Utils.Proxy.make(contractRegisterTraps)
|
|
394
|
-
->(Utils.magic: contractRegisterParams => Internal.contractRegisterContext)
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
let getContractRegisterArgs = (params: contractRegisterParams): Internal.contractRegisterArgs => {
|
|
398
|
-
event: (params.item->Internal.castUnsafeEventItem).event,
|
|
399
|
-
context: getContractRegisterContext(params),
|
|
400
|
-
}
|
package/src/UserContext.res.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Utils from "./Utils.res.mjs";
|
|
4
|
-
import * as Address from "./Address.res.mjs";
|
|
5
4
|
import * as Logging from "./Logging.res.mjs";
|
|
6
|
-
import * as ChainMap from "./ChainMap.res.mjs";
|
|
7
5
|
import * as Internal from "./Internal.res.mjs";
|
|
6
|
+
import * as Ecosystem from "./Ecosystem.res.mjs";
|
|
8
7
|
import * as LoadLayer from "./LoadLayer.res.mjs";
|
|
9
8
|
import * as EntityFilter from "./db/EntityFilter.res.mjs";
|
|
9
|
+
import * as IndexerState from "./IndexerState.res.mjs";
|
|
10
10
|
import * as ErrorHandling from "./ErrorHandling.res.mjs";
|
|
11
11
|
import * as InMemoryStore from "./InMemoryStore.res.mjs";
|
|
12
12
|
import * as InMemoryTable from "./InMemoryTable.res.mjs";
|
|
@@ -20,7 +20,8 @@ let effectContextPrototype = (Object.create(null));
|
|
|
20
20
|
|
|
21
21
|
Object.defineProperty(effectContextPrototype, "log", {
|
|
22
22
|
get: function () {
|
|
23
|
-
|
|
23
|
+
let params = paramsByThis.get(this);
|
|
24
|
+
return Ecosystem.getItemUserLogger(params.item, params.config.ecosystem);
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
27
|
|
|
@@ -43,7 +44,7 @@ function initEffect(params) {
|
|
|
43
44
|
cacheKey: effectArgs_cacheKey,
|
|
44
45
|
checkpointId: effectArgs_checkpointId
|
|
45
46
|
};
|
|
46
|
-
return LoadLayer.loadEffect(params.loadManager, params.persistence, effect, effectArgs, params.
|
|
47
|
+
return LoadLayer.loadEffect(params.loadManager, params.persistence, effect, effectArgs, params.indexerState, params.isPreload, params.item, params.config.ecosystem);
|
|
47
48
|
};
|
|
48
49
|
return callEffect;
|
|
49
50
|
}
|
|
@@ -52,9 +53,9 @@ function getWhereHandler(params, filter) {
|
|
|
52
53
|
let entityConfig = params.entityConfig;
|
|
53
54
|
let filters = EntityFilter.parseGetWhereOrThrow(filter, entityConfig.name, entityConfig.table);
|
|
54
55
|
if (filters.length !== 1) {
|
|
55
|
-
return Promise.all(filters.map(filter => LoadLayer.loadByFilter(params.loadManager, params.persistence, entityConfig, params.
|
|
56
|
+
return Promise.all(filters.map(filter => LoadLayer.loadByFilter(params.loadManager, params.persistence, entityConfig, params.indexerState, params.isPreload, params.item, params.config.ecosystem, filter))).then(results => results.flat());
|
|
56
57
|
} else {
|
|
57
|
-
return LoadLayer.loadByFilter(params.loadManager, params.persistence, entityConfig, params.
|
|
58
|
+
return LoadLayer.loadByFilter(params.loadManager, params.persistence, entityConfig, params.indexerState, params.isPreload, params.item, params.config.ecosystem, filters[0]);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
|
|
@@ -72,7 +73,7 @@ function throwClickHouseReadOnly(entityConfig, op) {
|
|
|
72
73
|
|
|
73
74
|
let entityTraps_get = (params, prop) => {
|
|
74
75
|
let isClickHouseOnly = !params.entityConfig.storage.postgres;
|
|
75
|
-
let set = params.isPreload ? noopSet : entity => InMemoryTable.Entity.set(InMemoryStore.getInMemTable(params.
|
|
76
|
+
let set = params.isPreload ? noopSet : entity => InMemoryTable.Entity.set(InMemoryStore.getInMemTable(params.indexerState, params.entityConfig), IndexerState.committedCheckpointId(params.indexerState), {
|
|
76
77
|
type: "SET",
|
|
77
78
|
entityId: entity.id,
|
|
78
79
|
entity: entity,
|
|
@@ -83,7 +84,7 @@ let entityTraps_get = (params, prop) => {
|
|
|
83
84
|
if (params.isPreload) {
|
|
84
85
|
return noopDeleteUnsafe;
|
|
85
86
|
} else {
|
|
86
|
-
return entityId => InMemoryTable.Entity.set(InMemoryStore.getInMemTable(params.
|
|
87
|
+
return entityId => InMemoryTable.Entity.set(InMemoryStore.getInMemTable(params.indexerState, params.entityConfig), IndexerState.committedCheckpointId(params.indexerState), {
|
|
87
88
|
type: "DELETE",
|
|
88
89
|
entityId: entityId,
|
|
89
90
|
checkpointId: params.checkpointId
|
|
@@ -93,13 +94,13 @@ let entityTraps_get = (params, prop) => {
|
|
|
93
94
|
if (isClickHouseOnly) {
|
|
94
95
|
return _entityId => throwClickHouseReadOnly(params.entityConfig, "get");
|
|
95
96
|
} else {
|
|
96
|
-
return entityId => LoadLayer.loadById(params.loadManager, params.persistence, params.entityConfig, params.
|
|
97
|
+
return entityId => LoadLayer.loadById(params.loadManager, params.persistence, params.entityConfig, params.indexerState, params.isPreload, params.item, params.config.ecosystem, entityId);
|
|
97
98
|
}
|
|
98
99
|
case "getOrCreate" :
|
|
99
100
|
if (isClickHouseOnly) {
|
|
100
101
|
return _entity => throwClickHouseReadOnly(params.entityConfig, "getOrCreate");
|
|
101
102
|
} else {
|
|
102
|
-
return entity => LoadLayer.loadById(params.loadManager, params.persistence, params.entityConfig, params.
|
|
103
|
+
return entity => LoadLayer.loadById(params.loadManager, params.persistence, params.entityConfig, params.indexerState, params.isPreload, params.item, params.config.ecosystem, entity.id).then(storageEntity => {
|
|
103
104
|
if (storageEntity !== undefined) {
|
|
104
105
|
return storageEntity;
|
|
105
106
|
} else {
|
|
@@ -112,7 +113,7 @@ let entityTraps_get = (params, prop) => {
|
|
|
112
113
|
if (isClickHouseOnly) {
|
|
113
114
|
return (_entityId, param) => throwClickHouseReadOnly(params.entityConfig, "getOrThrow");
|
|
114
115
|
} else {
|
|
115
|
-
return (entityId, message) => LoadLayer.loadById(params.loadManager, params.persistence, params.entityConfig, params.
|
|
116
|
+
return (entityId, message) => LoadLayer.loadById(params.loadManager, params.persistence, params.entityConfig, params.indexerState, params.isPreload, params.item, params.config.ecosystem, entityId).then(entity => {
|
|
116
117
|
if (entity !== undefined) {
|
|
117
118
|
return entity;
|
|
118
119
|
} else {
|
|
@@ -139,7 +140,7 @@ let entityTraps = {
|
|
|
139
140
|
|
|
140
141
|
let handlerTraps_get = (params, prop) => {
|
|
141
142
|
if (params.isResolved) {
|
|
142
|
-
ErrorHandling.mkLogAndRaise(
|
|
143
|
+
ErrorHandling.mkLogAndRaise(Ecosystem.getItemLogger(params.item, params.config.ecosystem), undefined, new Error(`Impossible to access context.` + prop + ` after the handler is resolved. Make sure you didn't miss an await in the handler.`));
|
|
143
144
|
}
|
|
144
145
|
switch (prop) {
|
|
145
146
|
case "chain" :
|
|
@@ -153,7 +154,7 @@ let handlerTraps_get = (params, prop) => {
|
|
|
153
154
|
if (params.isPreload) {
|
|
154
155
|
return Logging.noopLogger;
|
|
155
156
|
} else {
|
|
156
|
-
return
|
|
157
|
+
return Ecosystem.getItemUserLogger(params.item, params.config.ecosystem);
|
|
157
158
|
}
|
|
158
159
|
default:
|
|
159
160
|
let entityConfig = params.config.userEntitiesByName[prop];
|
|
@@ -161,7 +162,7 @@ let handlerTraps_get = (params, prop) => {
|
|
|
161
162
|
return new Proxy({
|
|
162
163
|
item: params.item,
|
|
163
164
|
checkpointId: params.checkpointId,
|
|
164
|
-
|
|
165
|
+
indexerState: params.indexerState,
|
|
165
166
|
loadManager: params.loadManager,
|
|
166
167
|
persistence: params.persistence,
|
|
167
168
|
isPreload: params.isPreload,
|
|
@@ -184,65 +185,6 @@ function getHandlerContext(params) {
|
|
|
184
185
|
return new Proxy(params, handlerTraps);
|
|
185
186
|
}
|
|
186
187
|
|
|
187
|
-
function makeAddFunction(params, contractName) {
|
|
188
|
-
return contractAddress => {
|
|
189
|
-
if (params.isResolved) {
|
|
190
|
-
ErrorHandling.mkLogAndRaise(Logging.getItemLogger(params.item), undefined, new Error(`Impossible to access context.chain after the contract register is resolved. Make sure you didn't miss an await in the handler.`));
|
|
191
|
-
}
|
|
192
|
-
let validatedAddress = params.config.ecosystem.name === "evm" ? (
|
|
193
|
-
params.config.lowercaseAddresses ? Address.Evm.fromAddressLowercaseOrThrow(contractAddress) : Address.Evm.fromAddressOrThrow(contractAddress)
|
|
194
|
-
) : contractAddress;
|
|
195
|
-
params.onRegister(params.item, validatedAddress, contractName);
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
let contractRegisterChainTraps_get = (params, prop) => {
|
|
200
|
-
if (prop === "id") {
|
|
201
|
-
return params.item.chain;
|
|
202
|
-
}
|
|
203
|
-
let isValidContract = ChainMap.values(params.config.chainMap).some(chain => chain.contracts.some(c => c.name === prop));
|
|
204
|
-
if (isValidContract) {
|
|
205
|
-
return {
|
|
206
|
-
add: makeAddFunction(params, prop)
|
|
207
|
-
};
|
|
208
|
-
} else {
|
|
209
|
-
return Stdlib_JsError.throwWithMessage(`Invalid contract name '` + prop + `' on context.chain. ` + EntityFilter.codegenHelpMessage);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
let contractRegisterChainTraps = {
|
|
214
|
-
get: contractRegisterChainTraps_get
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
let contractRegisterTraps_get = (params, prop) => {
|
|
218
|
-
if (params.isResolved) {
|
|
219
|
-
ErrorHandling.mkLogAndRaise(Logging.getItemLogger(params.item), undefined, new Error(`Impossible to access context.` + prop + ` after the contract register is resolved. Make sure you didn't miss an await in the handler.`));
|
|
220
|
-
}
|
|
221
|
-
switch (prop) {
|
|
222
|
-
case "chain" :
|
|
223
|
-
return new Proxy(params, contractRegisterChainTraps);
|
|
224
|
-
case "log" :
|
|
225
|
-
return Logging.getUserLogger(params.item);
|
|
226
|
-
default:
|
|
227
|
-
return Stdlib_JsError.throwWithMessage(`Invalid context access by '` + prop + `' property. Use context.chain.ContractName.add(address) to register contracts. ` + EntityFilter.codegenHelpMessage);
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
let contractRegisterTraps = {
|
|
232
|
-
get: contractRegisterTraps_get
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
function getContractRegisterContext(params) {
|
|
236
|
-
return new Proxy(params, contractRegisterTraps);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function getContractRegisterArgs(params) {
|
|
240
|
-
return {
|
|
241
|
-
event: params.item.event,
|
|
242
|
-
context: new Proxy(params, contractRegisterTraps)
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
188
|
export {
|
|
247
189
|
paramsByThis,
|
|
248
190
|
effectContextPrototype,
|
|
@@ -254,10 +196,5 @@ export {
|
|
|
254
196
|
entityTraps,
|
|
255
197
|
handlerTraps,
|
|
256
198
|
getHandlerContext,
|
|
257
|
-
makeAddFunction,
|
|
258
|
-
contractRegisterChainTraps,
|
|
259
|
-
contractRegisterTraps,
|
|
260
|
-
getContractRegisterContext,
|
|
261
|
-
getContractRegisterArgs,
|
|
262
199
|
}
|
|
263
200
|
/* paramsByThis Not a pure module */
|