Skip to content

Commit ea0cc5d

Browse files
committed
Clean up FetchState.make function
1 parent 907e769 commit ea0cc5d

File tree

4 files changed

+19
-34
lines changed

4 files changed

+19
-34
lines changed

codegenerator/cli/templates/static/codegen/src/EventUtils.res

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ type eventIndex = {
2828
logIndex: int,
2929
}
3030

31-
let eventIndexSchema = S.object(s => {
32-
blockNumber: s.field("blockNumber", S.int),
33-
logIndex: s.field("logIndex", S.int),
34-
})
35-
3631
// takes blockNumber, logIndex and packs them into a number with
3732
//32 bits, 16 bits and 16 bits respectively
3833
let packEventIndex = (~blockNumber, ~logIndex) => {

codegenerator/cli/templates/static/codegen/src/eventFetching/FetchState.res

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,6 @@ with a dynamicContractId
278278
*/
279279
type id = Root | DynamicContract(dynamicContractId)
280280

281-
let idSchema = S.union([
282-
S.literal(Root),
283-
S.schema(s => DynamicContract(s.matches(EventUtils.eventIndexSchema))),
284-
])
285-
286281
/**
287282
Constructs id from a register
288283
*/
@@ -774,26 +769,20 @@ let getEarliestEvent = (self: t) => {
774769
}
775770
}
776771

777-
let makeInternal = (
778-
~registerType,
772+
/**
773+
Instantiates a fetch state with root register
774+
*/
775+
let make = (
779776
~staticContracts,
780777
~dynamicContractRegistrations: array<TablesStatic.DynamicContractRegistry.t>,
781778
~startBlock,
779+
~endBlock,
782780
~isFetchingAtHead,
783-
~logger,
781+
~logger as _,
784782
): t => {
785783
let contractAddressMapping = ContractAddressingMap.make()
786784

787785
staticContracts->Belt.Array.forEach(((contractName, address)) => {
788-
Logging.childTrace(
789-
logger,
790-
{
791-
"msg": "adding contract address",
792-
"contractName": contractName,
793-
"address": address,
794-
},
795-
)
796-
797786
contractAddressMapping->ContractAddressingMap.addAddress(~name=contractName, ~address)
798787
})
799788

@@ -816,7 +805,7 @@ let makeInternal = (
816805
})
817806

818807
let baseRegister = {
819-
registerType,
808+
registerType: RootRegister({endBlock: endBlock}),
820809
latestFetchedBlock: {
821810
blockTimestamp: 0,
822811
// Here's a bug that startBlock: 1 won't work
@@ -835,11 +824,6 @@ let makeInternal = (
835824
}
836825
}
837826

838-
/**
839-
Instantiates a fetch state with root register
840-
*/
841-
let makeRoot = (~endBlock) => makeInternal(~registerType=RootRegister({endBlock: endBlock}), ...)
842-
843827
/**
844828
Calculates the cummulative queue sizes in all registers
845829
*/

codegenerator/cli/templates/static/codegen/src/eventFetching/PartitionedFetchState.res

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ let make = (
2828
let partitions = []
2929

3030
if numAddresses <= maxAddrInPartition {
31-
let partition = FetchState.makeRoot(~endBlock)(
31+
let partition = FetchState.make(
3232
~staticContracts,
3333
~dynamicContractRegistrations,
3434
~startBlock,
35+
~endBlock,
3536
~logger,
3637
~isFetchingAtHead=false,
3738
)
@@ -44,10 +45,11 @@ let make = (
4445
let staticContractsChunk =
4546
staticContractsClone->Js.Array2.removeCountInPlace(~pos=0, ~count=maxAddrInPartition)
4647

47-
let staticContractPartition = FetchState.makeRoot(~endBlock)(
48+
let staticContractPartition = FetchState.make(
4849
~staticContracts=staticContractsChunk,
4950
~dynamicContractRegistrations=[],
5051
~startBlock,
52+
~endBlock,
5153
~logger,
5254
~isFetchingAtHead=false,
5355
)
@@ -58,13 +60,14 @@ let make = (
5860

5961
//Add the rest of the static addresses filling the remainder of the partition with dynamic contract
6062
//registrations
61-
let remainingStaticContractsWithDynamicPartition = FetchState.makeRoot(~endBlock)(
63+
let remainingStaticContractsWithDynamicPartition = FetchState.make(
6264
~staticContracts=staticContractsClone,
6365
~dynamicContractRegistrations=dynamicContractRegistrationsClone->Js.Array2.removeCountInPlace(
6466
~pos=0,
6567
~count=maxAddrInPartition - staticContractsClone->Array.length,
6668
),
6769
~startBlock,
70+
~endBlock,
6871
~logger,
6972
~isFetchingAtHead=false,
7073
)
@@ -78,10 +81,11 @@ let make = (
7881
~count=maxAddrInPartition,
7982
)
8083

81-
let dynamicContractPartition = FetchState.makeRoot(~endBlock)(
84+
let dynamicContractPartition = FetchState.make(
8285
~staticContracts=[],
8386
~dynamicContractRegistrations=dynamicContractRegistrationsChunk,
8487
~startBlock,
88+
~endBlock,
8589
~logger,
8690
~isFetchingAtHead=false,
8791
)
@@ -125,8 +129,9 @@ let registerDynamicContracts = (
125129
)
126130
partitions->Utils.Array.setIndexImmutable(newestPartitionIndex, updated)
127131
} else {
128-
let newPartition = FetchState.makeRoot(~endBlock)(
132+
let newPartition = FetchState.make(
129133
~startBlock,
134+
~endBlock,
130135
~logger,
131136
~staticContracts=[],
132137
~dynamicContractRegistrations=dynamicContractRegistration.dynamicContracts,

scenarios/test_codegen/test/lib_tests/FetchState_test.res

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ describe("FetchState.fetchState", () => {
8585
})
8686

8787
it("dynamic contract registration", () => {
88-
let root = makeRoot(~endBlock=None)(
88+
let root = make(
8989
~startBlock=10_000,
90+
~endBlock=None,
9091
~staticContracts=[((Gravatar :> string), mockAddress1)],
9192
~dynamicContractRegistrations=[],
9293
~isFetchingAtHead=false,

0 commit comments

Comments
 (0)