envio 2.32.1 → 3.0.0-alpha-main-clickhouse-sink
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/index.d.ts +1 -0
- package/package.json +6 -5
- package/src/Batch.res +4 -4
- package/src/Change.res +9 -0
- package/src/Change.res.js +2 -0
- package/src/Config.res +5 -5
- package/src/Config.res.js +3 -1
- package/src/Envio.gen.ts +3 -3
- package/src/Envio.res +14 -3
- package/src/EventRegister.res +3 -11
- package/src/EventRegister.res.js +4 -8
- package/src/EventRegister.resi +1 -1
- package/src/InMemoryStore.gen.ts +6 -0
- package/src/InMemoryStore.res +149 -0
- package/src/InMemoryStore.res.js +161 -0
- package/src/InMemoryTable.res +50 -35
- package/src/InMemoryTable.res.js +52 -84
- package/src/Internal.gen.ts +0 -2
- package/src/Internal.res +20 -38
- package/src/Internal.res.js +2 -16
- package/src/LoadManager.res +23 -16
- package/src/LoadManager.res.js +17 -15
- package/src/Persistence.res +190 -38
- package/src/Persistence.res.js +92 -39
- package/src/PgStorage.res +700 -14
- package/src/PgStorage.res.js +431 -19
- package/src/Platform.res +141 -0
- package/src/Platform.res.js +170 -0
- package/src/Prometheus.res +41 -0
- package/src/Prometheus.res.js +45 -0
- package/src/SafeCheckpointTracking.res +5 -4
- package/src/Sink.res +47 -0
- package/src/Sink.res.js +36 -0
- package/src/Utils.res +2 -0
- package/src/Utils.res.js +3 -0
- package/src/bindings/ClickHouse.res +387 -0
- package/src/bindings/ClickHouse.res.js +274 -0
- package/src/bindings/Postgres.res +15 -0
- package/src/bindings/Promise.res +3 -0
- package/src/db/EntityHistory.res +33 -156
- package/src/db/EntityHistory.res.js +40 -115
- package/src/db/InternalTable.res +56 -55
- package/src/db/InternalTable.res.js +49 -52
- package/src/db/Table.res +86 -22
- package/src/db/Table.res.js +77 -10
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "envio",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "v3.0.0-alpha-main-clickhouse-sink",
|
|
4
4
|
"description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
|
|
5
5
|
"bin": "./bin.js",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -25,12 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://envio.dev",
|
|
27
27
|
"optionalDependencies": {
|
|
28
|
-
"envio-linux-x64": "
|
|
29
|
-
"envio-linux-arm64": "
|
|
30
|
-
"envio-darwin-x64": "
|
|
31
|
-
"envio-darwin-arm64": "
|
|
28
|
+
"envio-linux-x64": "v3.0.0-alpha-main-clickhouse-sink",
|
|
29
|
+
"envio-linux-arm64": "v3.0.0-alpha-main-clickhouse-sink",
|
|
30
|
+
"envio-darwin-x64": "v3.0.0-alpha-main-clickhouse-sink",
|
|
31
|
+
"envio-darwin-arm64": "v3.0.0-alpha-main-clickhouse-sink"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@clickhouse/client": "1.12.1",
|
|
34
35
|
"@envio-dev/hypersync-client": "0.6.6",
|
|
35
36
|
"@envio-dev/hyperfuel-client": "1.2.2",
|
|
36
37
|
"rescript": "11.1.3",
|
package/src/Batch.res
CHANGED
|
@@ -24,7 +24,7 @@ type t = {
|
|
|
24
24
|
items: array<Internal.item>,
|
|
25
25
|
progressedChainsById: dict<chainAfterBatch>,
|
|
26
26
|
// Unnest-like checkpoint fields:
|
|
27
|
-
checkpointIds: array<
|
|
27
|
+
checkpointIds: array<float>,
|
|
28
28
|
checkpointChainIds: array<int>,
|
|
29
29
|
checkpointBlockNumbers: array<int>,
|
|
30
30
|
checkpointBlockHashes: array<Js.Null.t<string>>,
|
|
@@ -196,7 +196,7 @@ let addReorgCheckpoints = (
|
|
|
196
196
|
for blockNumber in fromBlockExclusive + 1 to toBlockExclusive - 1 {
|
|
197
197
|
switch reorgDetection->ReorgDetection.getHashByBlockNumber(~blockNumber) {
|
|
198
198
|
| Js.Null.Value(hash) =>
|
|
199
|
-
let checkpointId = prevCheckpointId.contents
|
|
199
|
+
let checkpointId = prevCheckpointId.contents +. 1.
|
|
200
200
|
prevCheckpointId := checkpointId
|
|
201
201
|
|
|
202
202
|
mutCheckpointIds->Js.Array2.push(checkpointId)->ignore
|
|
@@ -277,7 +277,7 @@ let prepareOrderedBatch = (
|
|
|
277
277
|
~mutCheckpointEventsProcessed=checkpointEventsProcessed,
|
|
278
278
|
)
|
|
279
279
|
|
|
280
|
-
let checkpointId = prevCheckpointId.contents
|
|
280
|
+
let checkpointId = prevCheckpointId.contents +. 1.
|
|
281
281
|
|
|
282
282
|
items
|
|
283
283
|
->Js.Array2.push(item0)
|
|
@@ -421,7 +421,7 @@ let prepareUnorderedBatch = (
|
|
|
421
421
|
~mutCheckpointEventsProcessed=checkpointEventsProcessed,
|
|
422
422
|
)
|
|
423
423
|
|
|
424
|
-
let checkpointId = prevCheckpointId.contents
|
|
424
|
+
let checkpointId = prevCheckpointId.contents +. 1.
|
|
425
425
|
|
|
426
426
|
checkpointIds->Js.Array2.push(checkpointId)->ignore
|
|
427
427
|
checkpointChainIds->Js.Array2.push(fetchState.chainId)->ignore
|
package/src/Change.res
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
@tag("type")
|
|
2
|
+
type t<'entity> =
|
|
3
|
+
| @as("SET") Set({entityId: string, entity: 'entity, checkpointId: float})
|
|
4
|
+
| @as("DELETE") Delete({entityId: string, checkpointId: float})
|
|
5
|
+
|
|
6
|
+
@get
|
|
7
|
+
external getEntityId: t<'entity> => string = "entityId"
|
|
8
|
+
@get
|
|
9
|
+
external getCheckpointId: t<'entity> => float = "checkpointId"
|
package/src/Config.res
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
open Belt
|
|
2
2
|
|
|
3
|
-
type ecosystem = | @as("evm") Evm | @as("fuel") Fuel
|
|
4
|
-
|
|
5
3
|
type sourceSyncOptions = {
|
|
6
4
|
initialBlockInterval?: int,
|
|
7
5
|
backoffMultiplicative?: float,
|
|
@@ -47,7 +45,7 @@ type t = {
|
|
|
47
45
|
multichain: multichain,
|
|
48
46
|
chainMap: ChainMap.t<chain>,
|
|
49
47
|
defaultChain: option<chain>,
|
|
50
|
-
|
|
48
|
+
platform: Platform.t,
|
|
51
49
|
enableRawEvents: bool,
|
|
52
50
|
preloadHandlers: bool,
|
|
53
51
|
maxAddrInPartition: int,
|
|
@@ -62,7 +60,7 @@ let make = (
|
|
|
62
60
|
~chains: array<chain>=[],
|
|
63
61
|
~enableRawEvents=false,
|
|
64
62
|
~preloadHandlers=false,
|
|
65
|
-
~ecosystem=Evm,
|
|
63
|
+
~ecosystem: Platform.name=Platform.Evm,
|
|
66
64
|
~batchSize=5000,
|
|
67
65
|
~lowercaseAddresses=false,
|
|
68
66
|
~multichain=Unordered,
|
|
@@ -92,6 +90,8 @@ let make = (
|
|
|
92
90
|
})
|
|
93
91
|
})
|
|
94
92
|
|
|
93
|
+
let platform = Platform.fromName(ecosystem)
|
|
94
|
+
|
|
95
95
|
{
|
|
96
96
|
shouldRollbackOnReorg,
|
|
97
97
|
shouldSaveFullHistory,
|
|
@@ -99,7 +99,7 @@ let make = (
|
|
|
99
99
|
chainMap,
|
|
100
100
|
defaultChain: chains->Array.get(0),
|
|
101
101
|
enableRawEvents,
|
|
102
|
-
|
|
102
|
+
platform,
|
|
103
103
|
maxAddrInPartition,
|
|
104
104
|
preloadHandlers,
|
|
105
105
|
batchSize,
|
package/src/Config.res.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
var Utils = require("./Utils.res.js");
|
|
5
5
|
var Js_exn = require("rescript/lib/js/js_exn.js");
|
|
6
6
|
var ChainMap = require("./ChainMap.res.js");
|
|
7
|
+
var Platform = require("./Platform.res.js");
|
|
7
8
|
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
8
9
|
|
|
9
10
|
function make(shouldRollbackOnReorgOpt, shouldSaveFullHistoryOpt, chainsOpt, enableRawEventsOpt, preloadHandlersOpt, ecosystemOpt, batchSizeOpt, lowercaseAddressesOpt, multichainOpt, shouldUseHypersyncClientDecoderOpt, maxAddrInPartitionOpt) {
|
|
@@ -34,13 +35,14 @@ function make(shouldRollbackOnReorgOpt, shouldSaveFullHistoryOpt, chainsOpt, ena
|
|
|
34
35
|
addContractNameToContractNameMapping[addKey] = contract.name;
|
|
35
36
|
}));
|
|
36
37
|
}));
|
|
38
|
+
var platform = Platform.fromName(ecosystem);
|
|
37
39
|
return {
|
|
38
40
|
shouldRollbackOnReorg: shouldRollbackOnReorg,
|
|
39
41
|
shouldSaveFullHistory: shouldSaveFullHistory,
|
|
40
42
|
multichain: multichain,
|
|
41
43
|
chainMap: chainMap,
|
|
42
44
|
defaultChain: Belt_Array.get(chains, 0),
|
|
43
|
-
|
|
45
|
+
platform: platform,
|
|
44
46
|
enableRawEvents: enableRawEvents,
|
|
45
47
|
preloadHandlers: preloadHandlers,
|
|
46
48
|
maxAddrInPartition: maxAddrInPartition,
|
package/src/Envio.gen.ts
CHANGED
|
@@ -11,11 +11,11 @@ import type {Logger as $$logger} from './Types.ts';
|
|
|
11
11
|
|
|
12
12
|
import type {S_t as RescriptSchema_S_t} from 'rescript-schema/RescriptSchema.gen';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
export type blockEvent = { readonly number: number; readonly chainId: number };
|
|
15
15
|
|
|
16
|
-
export type
|
|
16
|
+
export type fuelBlockEvent = { readonly height: number; readonly chainId: number };
|
|
17
17
|
|
|
18
|
-
export type onBlockArgs<context> = { readonly block:
|
|
18
|
+
export type onBlockArgs<block,context> = { readonly block: block; readonly context: context };
|
|
19
19
|
|
|
20
20
|
export type onBlockOptions<chain> = {
|
|
21
21
|
readonly name: string;
|
package/src/Envio.res
CHANGED
|
@@ -2,12 +2,23 @@
|
|
|
2
2
|
// Should be an entry point after we get rid of the generated project.
|
|
3
3
|
// Don't forget to keep index.d.ts in sync with this file.
|
|
4
4
|
|
|
5
|
+
// EVM block event with 'number' field for backward compatibility
|
|
5
6
|
@genType
|
|
6
|
-
type blockEvent =
|
|
7
|
+
type blockEvent = {
|
|
8
|
+
number: int,
|
|
9
|
+
chainId: int,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Fuel block event with 'height' field
|
|
13
|
+
@genType
|
|
14
|
+
type fuelBlockEvent = {
|
|
15
|
+
height: int,
|
|
16
|
+
chainId: int,
|
|
17
|
+
}
|
|
7
18
|
|
|
8
19
|
@genType
|
|
9
|
-
type onBlockArgs<'context> = {
|
|
10
|
-
block:
|
|
20
|
+
type onBlockArgs<'block, 'context> = {
|
|
21
|
+
block: 'block,
|
|
11
22
|
context: 'context,
|
|
12
23
|
}
|
|
13
24
|
|
package/src/EventRegister.res
CHANGED
|
@@ -4,7 +4,7 @@ type registrations = {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
type activeRegistration = {
|
|
7
|
-
|
|
7
|
+
platform: Platform.t,
|
|
8
8
|
multichain: Config.multichain,
|
|
9
9
|
preloadHandlers: bool,
|
|
10
10
|
registrations: registrations,
|
|
@@ -36,9 +36,9 @@ let withRegistration = (fn: activeRegistration => unit) => {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
let startRegistration = (~
|
|
39
|
+
let startRegistration = (~platform, ~multichain, ~preloadHandlers) => {
|
|
40
40
|
let r = {
|
|
41
|
-
|
|
41
|
+
platform,
|
|
42
42
|
multichain,
|
|
43
43
|
preloadHandlers,
|
|
44
44
|
registrations: {
|
|
@@ -80,14 +80,6 @@ let onBlockOptionsSchema = S.schema(s =>
|
|
|
80
80
|
|
|
81
81
|
let onBlock = (rawOptions: unknown, handler: Internal.onBlockArgs => promise<unit>) => {
|
|
82
82
|
withRegistration(registration => {
|
|
83
|
-
// There's no big reason for this. It's just more work
|
|
84
|
-
switch registration.ecosystem {
|
|
85
|
-
| Evm => ()
|
|
86
|
-
| Fuel =>
|
|
87
|
-
Js.Exn.raiseError(
|
|
88
|
-
"Block Handlers are not supported for non-EVM ecosystems. Please reach out to the Envio team if you need this feature.",
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
83
|
// We need to get timestamp for ordered multichain mode
|
|
92
84
|
switch registration.multichain {
|
|
93
85
|
| Unordered => ()
|
package/src/EventRegister.res.js
CHANGED
|
@@ -28,9 +28,9 @@ function withRegistration(fn) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function startRegistration(
|
|
31
|
+
function startRegistration(platform, multichain, preloadHandlers) {
|
|
32
32
|
var r = {
|
|
33
|
-
|
|
33
|
+
platform: platform,
|
|
34
34
|
multichain: multichain,
|
|
35
35
|
preloadHandlers: preloadHandlers,
|
|
36
36
|
registrations: {
|
|
@@ -71,12 +71,8 @@ var onBlockOptionsSchema = S$RescriptSchema.schema(function (s) {
|
|
|
71
71
|
|
|
72
72
|
function onBlock(rawOptions, handler) {
|
|
73
73
|
withRegistration(function (registration) {
|
|
74
|
-
var match = registration.
|
|
75
|
-
if (match
|
|
76
|
-
Js_exn.raiseError("Block Handlers are not supported for non-EVM ecosystems. Please reach out to the Envio team if you need this feature.");
|
|
77
|
-
}
|
|
78
|
-
var match$1 = registration.multichain;
|
|
79
|
-
if (match$1 === "ordered") {
|
|
74
|
+
var match = registration.multichain;
|
|
75
|
+
if (match === "ordered") {
|
|
80
76
|
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 with `unordered_multichain_mode: true` in your config.");
|
|
81
77
|
}
|
|
82
78
|
if (registration.preloadHandlers) {
|
package/src/EventRegister.resi
CHANGED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
@genType
|
|
2
|
+
type rawEventsKey = {
|
|
3
|
+
chainId: int,
|
|
4
|
+
eventId: string,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
let hashRawEventsKey = (key: rawEventsKey) =>
|
|
8
|
+
EventUtils.getEventIdKeyString(~chainId=key.chainId, ~eventId=key.eventId)
|
|
9
|
+
|
|
10
|
+
module EntityTables = {
|
|
11
|
+
type t = dict<InMemoryTable.Entity.t<Internal.entity>>
|
|
12
|
+
exception UndefinedEntity({entityName: string})
|
|
13
|
+
let make = (entities: array<Internal.entityConfig>): t => {
|
|
14
|
+
let init = Js.Dict.empty()
|
|
15
|
+
entities->Belt.Array.forEach(entityConfig => {
|
|
16
|
+
init->Js.Dict.set((entityConfig.name :> string), InMemoryTable.Entity.make())
|
|
17
|
+
})
|
|
18
|
+
init
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let get = (type entity, self: t, ~entityName: string) => {
|
|
22
|
+
switch self->Utils.Dict.dangerouslyGetNonOption(entityName) {
|
|
23
|
+
| Some(table) =>
|
|
24
|
+
table->(
|
|
25
|
+
Utils.magic: InMemoryTable.Entity.t<Internal.entity> => InMemoryTable.Entity.t<entity>
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
| None =>
|
|
29
|
+
UndefinedEntity({entityName: entityName})->ErrorHandling.mkLogAndRaise(
|
|
30
|
+
~msg="Unexpected, entity InMemoryTable is undefined",
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let clone = (self: t) => {
|
|
36
|
+
self
|
|
37
|
+
->Js.Dict.entries
|
|
38
|
+
->Belt.Array.map(((k, v)) => (k, v->InMemoryTable.Entity.clone))
|
|
39
|
+
->Js.Dict.fromArray
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type effectCacheInMemTable = {
|
|
44
|
+
idsToStore: array<string>,
|
|
45
|
+
mutable invalidationsCount: int,
|
|
46
|
+
dict: dict<Internal.effectOutput>,
|
|
47
|
+
effect: Internal.effect,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type t = {
|
|
51
|
+
rawEvents: InMemoryTable.t<rawEventsKey, InternalTable.RawEvents.t>,
|
|
52
|
+
entities: dict<InMemoryTable.Entity.t<Internal.entity>>,
|
|
53
|
+
effects: dict<effectCacheInMemTable>,
|
|
54
|
+
rollbackTargetCheckpointId: option<Internal.checkpointId>,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let make = (~entities: array<Internal.entityConfig>, ~rollbackTargetCheckpointId=?): t => {
|
|
58
|
+
rawEvents: InMemoryTable.make(~hash=hashRawEventsKey),
|
|
59
|
+
entities: EntityTables.make(entities),
|
|
60
|
+
effects: Js.Dict.empty(),
|
|
61
|
+
rollbackTargetCheckpointId,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let clone = (self: t) => {
|
|
65
|
+
rawEvents: self.rawEvents->InMemoryTable.clone,
|
|
66
|
+
entities: self.entities->EntityTables.clone,
|
|
67
|
+
effects: Js.Dict.map(table => {
|
|
68
|
+
idsToStore: table.idsToStore->Array.copy,
|
|
69
|
+
invalidationsCount: table.invalidationsCount,
|
|
70
|
+
dict: table.dict->Utils.Dict.shallowCopy,
|
|
71
|
+
effect: table.effect,
|
|
72
|
+
}, self.effects),
|
|
73
|
+
rollbackTargetCheckpointId: self.rollbackTargetCheckpointId,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let getEffectInMemTable = (inMemoryStore: t, ~effect: Internal.effect) => {
|
|
77
|
+
let key = effect.name
|
|
78
|
+
switch inMemoryStore.effects->Utils.Dict.dangerouslyGetNonOption(key) {
|
|
79
|
+
| Some(table) => table
|
|
80
|
+
| None =>
|
|
81
|
+
let table = {
|
|
82
|
+
idsToStore: [],
|
|
83
|
+
dict: Js.Dict.empty(),
|
|
84
|
+
invalidationsCount: 0,
|
|
85
|
+
effect,
|
|
86
|
+
}
|
|
87
|
+
inMemoryStore.effects->Js.Dict.set(key, table)
|
|
88
|
+
table
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let getInMemTable = (
|
|
93
|
+
inMemoryStore: t,
|
|
94
|
+
~entityConfig: Internal.entityConfig,
|
|
95
|
+
): InMemoryTable.Entity.t<Internal.entity> => {
|
|
96
|
+
inMemoryStore.entities->EntityTables.get(~entityName=entityConfig.name)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let isRollingBack = (inMemoryStore: t) => inMemoryStore.rollbackTargetCheckpointId !== None
|
|
100
|
+
|
|
101
|
+
let setBatchDcs = (inMemoryStore: t, ~batch: Batch.t, ~shouldSaveHistory) => {
|
|
102
|
+
let inMemTable =
|
|
103
|
+
inMemoryStore->getInMemTable(~entityConfig=InternalTable.DynamicContractRegistry.config)
|
|
104
|
+
|
|
105
|
+
let itemIdx = ref(0)
|
|
106
|
+
|
|
107
|
+
for checkpoint in 0 to batch.checkpointIds->Array.length - 1 {
|
|
108
|
+
let checkpointId = batch.checkpointIds->Js.Array2.unsafe_get(checkpoint)
|
|
109
|
+
let chainId = batch.checkpointChainIds->Js.Array2.unsafe_get(checkpoint)
|
|
110
|
+
let checkpointEventsProcessed =
|
|
111
|
+
batch.checkpointEventsProcessed->Js.Array2.unsafe_get(checkpoint)
|
|
112
|
+
|
|
113
|
+
for idx in 0 to checkpointEventsProcessed - 1 {
|
|
114
|
+
let item = batch.items->Js.Array2.unsafe_get(itemIdx.contents + idx)
|
|
115
|
+
switch item->Internal.getItemDcs {
|
|
116
|
+
| None => ()
|
|
117
|
+
| Some(dcs) =>
|
|
118
|
+
// Currently only events support contract registration, so we can cast to event item
|
|
119
|
+
let eventItem = item->Internal.castUnsafeEventItem
|
|
120
|
+
for dcIdx in 0 to dcs->Array.length - 1 {
|
|
121
|
+
let dc = dcs->Js.Array2.unsafe_get(dcIdx)
|
|
122
|
+
let entity: InternalTable.DynamicContractRegistry.t = {
|
|
123
|
+
id: InternalTable.DynamicContractRegistry.makeId(~chainId, ~contractAddress=dc.address),
|
|
124
|
+
chainId,
|
|
125
|
+
contractAddress: dc.address,
|
|
126
|
+
contractName: dc.contractName,
|
|
127
|
+
registeringEventBlockNumber: eventItem.blockNumber,
|
|
128
|
+
registeringEventLogIndex: eventItem.logIndex,
|
|
129
|
+
registeringEventBlockTimestamp: eventItem.timestamp,
|
|
130
|
+
registeringEventContractName: eventItem.eventConfig.contractName,
|
|
131
|
+
registeringEventName: eventItem.eventConfig.name,
|
|
132
|
+
registeringEventSrcAddress: eventItem.event.srcAddress,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
inMemTable->InMemoryTable.Entity.set(
|
|
136
|
+
Set({
|
|
137
|
+
entityId: entity.id,
|
|
138
|
+
checkpointId,
|
|
139
|
+
entity: entity->InternalTable.DynamicContractRegistry.castToInternal,
|
|
140
|
+
}),
|
|
141
|
+
~shouldSaveHistory,
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
itemIdx := itemIdx.contents + checkpointEventsProcessed
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var $$Array = require("rescript/lib/js/array.js");
|
|
5
|
+
var Utils = require("./Utils.res.js");
|
|
6
|
+
var Js_dict = require("rescript/lib/js/js_dict.js");
|
|
7
|
+
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
8
|
+
var EventUtils = require("./EventUtils.res.js");
|
|
9
|
+
var ErrorHandling = require("./ErrorHandling.res.js");
|
|
10
|
+
var InMemoryTable = require("./InMemoryTable.res.js");
|
|
11
|
+
var InternalTable = require("./db/InternalTable.res.js");
|
|
12
|
+
var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
|
|
13
|
+
|
|
14
|
+
function hashRawEventsKey(key) {
|
|
15
|
+
return EventUtils.getEventIdKeyString(key.chainId, key.eventId);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var UndefinedEntity = /* @__PURE__ */Caml_exceptions.create("InMemoryStore.EntityTables.UndefinedEntity");
|
|
19
|
+
|
|
20
|
+
function make(entities) {
|
|
21
|
+
var init = {};
|
|
22
|
+
Belt_Array.forEach(entities, (function (entityConfig) {
|
|
23
|
+
init[entityConfig.name] = InMemoryTable.Entity.make();
|
|
24
|
+
}));
|
|
25
|
+
return init;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function get(self, entityName) {
|
|
29
|
+
var table = self[entityName];
|
|
30
|
+
if (table !== undefined) {
|
|
31
|
+
return table;
|
|
32
|
+
} else {
|
|
33
|
+
return ErrorHandling.mkLogAndRaise(undefined, "Unexpected, entity InMemoryTable is undefined", {
|
|
34
|
+
RE_EXN_ID: UndefinedEntity,
|
|
35
|
+
entityName: entityName
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function clone(self) {
|
|
41
|
+
return Js_dict.fromArray(Belt_Array.map(Js_dict.entries(self), (function (param) {
|
|
42
|
+
return [
|
|
43
|
+
param[0],
|
|
44
|
+
InMemoryTable.Entity.clone(param[1])
|
|
45
|
+
];
|
|
46
|
+
})));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var EntityTables = {
|
|
50
|
+
UndefinedEntity: UndefinedEntity,
|
|
51
|
+
make: make,
|
|
52
|
+
get: get,
|
|
53
|
+
clone: clone
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function make$1(entities, rollbackTargetCheckpointId) {
|
|
57
|
+
return {
|
|
58
|
+
rawEvents: InMemoryTable.make(hashRawEventsKey),
|
|
59
|
+
entities: make(entities),
|
|
60
|
+
effects: {},
|
|
61
|
+
rollbackTargetCheckpointId: rollbackTargetCheckpointId
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function clone$1(self) {
|
|
66
|
+
return {
|
|
67
|
+
rawEvents: InMemoryTable.clone(self.rawEvents),
|
|
68
|
+
entities: clone(self.entities),
|
|
69
|
+
effects: Js_dict.map((function (table) {
|
|
70
|
+
return {
|
|
71
|
+
idsToStore: $$Array.copy(table.idsToStore),
|
|
72
|
+
invalidationsCount: table.invalidationsCount,
|
|
73
|
+
dict: Utils.Dict.shallowCopy(table.dict),
|
|
74
|
+
effect: table.effect
|
|
75
|
+
};
|
|
76
|
+
}), self.effects),
|
|
77
|
+
rollbackTargetCheckpointId: self.rollbackTargetCheckpointId
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getEffectInMemTable(inMemoryStore, effect) {
|
|
82
|
+
var key = effect.name;
|
|
83
|
+
var table = inMemoryStore.effects[key];
|
|
84
|
+
if (table !== undefined) {
|
|
85
|
+
return table;
|
|
86
|
+
}
|
|
87
|
+
var table$1 = {
|
|
88
|
+
idsToStore: [],
|
|
89
|
+
invalidationsCount: 0,
|
|
90
|
+
dict: {},
|
|
91
|
+
effect: effect
|
|
92
|
+
};
|
|
93
|
+
inMemoryStore.effects[key] = table$1;
|
|
94
|
+
return table$1;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getInMemTable(inMemoryStore, entityConfig) {
|
|
98
|
+
return get(inMemoryStore.entities, entityConfig.name);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isRollingBack(inMemoryStore) {
|
|
102
|
+
return inMemoryStore.rollbackTargetCheckpointId !== undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function setBatchDcs(inMemoryStore, batch, shouldSaveHistory) {
|
|
106
|
+
var inMemTable = getInMemTable(inMemoryStore, InternalTable.DynamicContractRegistry.config);
|
|
107
|
+
var itemIdx = 0;
|
|
108
|
+
for(var checkpoint = 0 ,checkpoint_finish = batch.checkpointIds.length; checkpoint < checkpoint_finish; ++checkpoint){
|
|
109
|
+
var checkpointId = batch.checkpointIds[checkpoint];
|
|
110
|
+
var chainId = batch.checkpointChainIds[checkpoint];
|
|
111
|
+
var checkpointEventsProcessed = batch.checkpointEventsProcessed[checkpoint];
|
|
112
|
+
for(var idx = 0; idx < checkpointEventsProcessed; ++idx){
|
|
113
|
+
var item = batch.items[itemIdx + idx | 0];
|
|
114
|
+
var dcs = item.dcs;
|
|
115
|
+
if (dcs !== undefined) {
|
|
116
|
+
for(var dcIdx = 0 ,dcIdx_finish = dcs.length; dcIdx < dcIdx_finish; ++dcIdx){
|
|
117
|
+
var dc = dcs[dcIdx];
|
|
118
|
+
var entity_id = InternalTable.DynamicContractRegistry.makeId(chainId, dc.address);
|
|
119
|
+
var entity_registering_event_block_number = item.blockNumber;
|
|
120
|
+
var entity_registering_event_log_index = item.logIndex;
|
|
121
|
+
var entity_registering_event_block_timestamp = item.timestamp;
|
|
122
|
+
var entity_registering_event_contract_name = item.eventConfig.contractName;
|
|
123
|
+
var entity_registering_event_name = item.eventConfig.name;
|
|
124
|
+
var entity_registering_event_src_address = item.event.srcAddress;
|
|
125
|
+
var entity_contract_address = dc.address;
|
|
126
|
+
var entity_contract_name = dc.contractName;
|
|
127
|
+
var entity = {
|
|
128
|
+
id: entity_id,
|
|
129
|
+
chain_id: chainId,
|
|
130
|
+
registering_event_block_number: entity_registering_event_block_number,
|
|
131
|
+
registering_event_log_index: entity_registering_event_log_index,
|
|
132
|
+
registering_event_block_timestamp: entity_registering_event_block_timestamp,
|
|
133
|
+
registering_event_contract_name: entity_registering_event_contract_name,
|
|
134
|
+
registering_event_name: entity_registering_event_name,
|
|
135
|
+
registering_event_src_address: entity_registering_event_src_address,
|
|
136
|
+
contract_address: entity_contract_address,
|
|
137
|
+
contract_name: entity_contract_name
|
|
138
|
+
};
|
|
139
|
+
InMemoryTable.Entity.set(inMemTable, {
|
|
140
|
+
type: "SET",
|
|
141
|
+
entityId: entity_id,
|
|
142
|
+
entity: entity,
|
|
143
|
+
checkpointId: checkpointId
|
|
144
|
+
}, shouldSaveHistory, undefined);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
itemIdx = itemIdx + checkpointEventsProcessed | 0;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
exports.hashRawEventsKey = hashRawEventsKey;
|
|
154
|
+
exports.EntityTables = EntityTables;
|
|
155
|
+
exports.make = make$1;
|
|
156
|
+
exports.clone = clone$1;
|
|
157
|
+
exports.getEffectInMemTable = getEffectInMemTable;
|
|
158
|
+
exports.getInMemTable = getInMemTable;
|
|
159
|
+
exports.isRollingBack = isRollingBack;
|
|
160
|
+
exports.setBatchDcs = setBatchDcs;
|
|
161
|
+
/* Utils Not a pure module */
|