Skip to content

Commit

Permalink
refac forktypes
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Aug 21, 2023
1 parent b0f53c5 commit 021d947
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
4 changes: 1 addition & 3 deletions packages/api/src/beacon/routes/validator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ContainerType, fromHexString, toHexString, Type} from "@chainsafe/ssz";
import {ForkName, ForkBlobs, isForkBlobs, isForkExecution} from "@lodestar/params";
import {ForkName, ForkBlobs, isForkBlobs, isForkExecution, ForkPreBlobs} from "@lodestar/params";
import {
allForks,
altair,
Expand Down Expand Up @@ -44,8 +44,6 @@ import {
} from "../../utils/routes.js";
import {ExecutionOptimistic} from "./beacon/block.js";

type ForkPreBlobs = ForkName.phase0 | ForkName.altair | ForkName.bellatrix | ForkName.capella;

export type ProduceBlockOrContentsRes = {executionPayloadValue: Wei} & (
| {data: allForks.BeaconBlock; version: ForkPreBlobs}
| {data: BlockContents; version: ForkBlobs}
Expand Down
12 changes: 8 additions & 4 deletions packages/params/src/forkName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@ export enum ForkSeq {
deneb = 4,
}

export type ForkLightClient = Exclude<ForkName, ForkName.phase0>;
export type ForkPreLightClient = ForkName.phase0;
export type ForkLightClient = Exclude<ForkName, ForkPreLightClient>;
export function isForkLightClient(fork: ForkName): fork is ForkLightClient {
return fork !== ForkName.phase0;
}

export type ForkExecution = Exclude<ForkLightClient, ForkName.altair>;
export type ForkPreExecution = ForkPreLightClient | ForkName.altair;
export type ForkExecution = Exclude<ForkLightClient, ForkPreExecution>;
export function isForkExecution(fork: ForkName): fork is ForkExecution {
return isForkLightClient(fork) && fork !== ForkName.altair;
}

export type ForkWithdrawals = Exclude<ForkExecution, ForkName.bellatrix>;
export type ForkPreWithdrawals = ForkPreExecution | ForkName.bellatrix;
export type ForkWithdrawals = Exclude<ForkExecution, ForkPreWithdrawals>;
export function isForkWithdrawals(fork: ForkName): fork is ForkWithdrawals {
return isForkExecution(fork) && fork !== ForkName.bellatrix;
}

export type ForkBlobs = Exclude<ForkExecution, ForkName.bellatrix | ForkName.capella>;
export type ForkPreBlobs = ForkPreWithdrawals | ForkName.capella;
export type ForkBlobs = Exclude<ForkExecution, ForkPreBlobs>;
export function isForkBlobs(fork: ForkName): fork is ForkBlobs {
return isForkWithdrawals(fork) && fork !== ForkName.capella;
}
12 changes: 1 addition & 11 deletions packages/params/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@ import {presetStatus} from "./presetStatus.js";
import {userSelectedPreset, userOverrides} from "./setPreset.js";

export {BeaconPreset} from "./types.js";
export {
ForkName,
ForkSeq,
ForkLightClient,
ForkExecution,
ForkBlobs,
isForkExecution,
isForkWithdrawals,
isForkBlobs,
isForkLightClient,
} from "./forkName.js";
export * from "./forkName.js";
export {presetToJson} from "./json.js";
export {PresetName};

Expand Down

0 comments on commit 021d947

Please sign in to comment.