Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve types package to use forks as generics #6825

Merged
merged 40 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fdd6428
Update the types to use generics
nazarhussain May 24, 2024
50774c6
Update the types with default generics
nazarhussain May 28, 2024
dc4a23f
Fix the block type
nazarhussain May 28, 2024
fbbc279
Add missing type
nazarhussain May 28, 2024
5b8e573
Add missing type
nazarhussain May 28, 2024
ccf59cd
Add ssz types
nazarhussain May 28, 2024
33caf6e
Remove allForks namespace
nazarhussain May 28, 2024
8a33570
Make ssz types generic
nazarhussain May 28, 2024
bbd076a
Update config package
nazarhussain May 28, 2024
92f6aae
Fix blok fork types
nazarhussain May 28, 2024
046af93
Fix api package types
nazarhussain May 28, 2024
930e577
Update types
nazarhussain May 29, 2024
175c8c3
Update state-transition package
nazarhussain May 29, 2024
57feebe
Update config package
nazarhussain May 29, 2024
ab52f1a
Fix types
nazarhussain Jun 3, 2024
c56c7de
Fix types for all packages
nazarhussain Jun 3, 2024
d417c3b
Update api package
nazarhussain May 29, 2024
efa70a4
Fix types for tests files
nazarhussain Jun 5, 2024
7ca3416
Fix ssz types
nazarhussain Jun 5, 2024
5b9c388
Fix build error
nazarhussain Jun 5, 2024
037050d
Fix lint errors
nazarhussain Jun 5, 2024
a396cd9
Fix lint errors
nazarhussain Jun 5, 2024
ccaa449
Fix type issues after rebase
nazarhussain Jun 12, 2024
4d30310
Update redundant generics
nazarhussain Jun 13, 2024
947016e
Fix the type
nazarhussain Jun 13, 2024
d59b127
Update types to use single generic
nazarhussain Jun 14, 2024
a4d07eb
Fix all types
nazarhussain Jun 14, 2024
4a36622
Fix the code as per feedback
nazarhussain Jun 15, 2024
4e17424
Merge branch 'unstable' into nh/types-refactor
nazarhussain Jun 15, 2024
3c075ba
Merge branch 'nh/types-refactor' of github.com:ChainSafe/lodestar int…
nazarhussain Jun 15, 2024
5319f1c
Update the code with feedback
nazarhussain Jun 15, 2024
dbfea50
Update packages/types/README.md
nazarhussain Jun 15, 2024
f33b835
Merge branch 'nh/types-refactor' of github.com:ChainSafe/lodestar int…
nazarhussain Jun 15, 2024
04c38a1
chore: review #6825 (#6887)
nflaig Jun 16, 2024
d6d7eb9
Fix publishBlockWrapper input type
nflaig Jun 16, 2024
6374b0a
Updated the type guard
nazarhussain Jun 21, 2024
2661efc
Merge branch 'unstable' into nh/types-refactor
nflaig Jun 21, 2024
2ea3be7
Remove ssz instance type
nazarhussain Jun 22, 2024
68ff948
Rename BlindedExecutionPayload to ExecutionPayloadheader
nazarhussain Jun 22, 2024
536d8c9
Update code as per feedback
nazarhussain Jun 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update code as per feedback
  • Loading branch information
nazarhussain committed Jun 22, 2024
commit 536d8c99e931e12e14b6db6a0c9f0543a8241ff2
10 changes: 5 additions & 5 deletions packages/types/src/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ export type SSZBlindedTypesFor<
? // It compiles fine, need to debug the error
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
{[K2 in keyof SSZBlindedTypesByFork[F]]: UnionForksTypeOf<SSZBlindedTypesByFork[F][K2]>}
{[K2 in keyof SSZBlindedTypesByFork[F]]: UnionSSZForksTypeOf<SSZBlindedTypesByFork[F][K2]>}
: // It compiles fine, need to debug the error
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
UnionForksTypeOf<SSZBlindedTypesByFork[F][Exclude<K, void>]>;
UnionSSZForksTypeOf<SSZBlindedTypesByFork[F][Exclude<K, void>]>;

/**
* A type of union of forks must accept as any parameter the UNION of all fork types.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type UnionForksTypeOf<UnionOfForkTypes extends ContainerType<any>> = CompositeType<
type UnionSSZForksTypeOf<UnionOfForkTypes extends ContainerType<any>> = CompositeType<
ValueOf<UnionOfForkTypes>,
CompositeView<UnionOfForkTypes>,
CompositeViewDU<UnionOfForkTypes>
Expand All @@ -169,11 +169,11 @@ export type SSZTypesFor<F extends ForkName, K extends keyof SSZTypesByFork[F] |
? // It compiles fine, need to debug the error
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
{[K2 in keyof SSZTypesByFork[F]]: UnionForksTypeOf<SSZTypesByFork[F][K2]>}
{[K2 in keyof SSZTypesByFork[F]]: UnionSSZForksTypeOf<SSZTypesByFork[F][K2]>}
: // It compiles fine, need to debug the error
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
UnionForksTypeOf<SSZTypesByFork[F][Exclude<K, void>]>;
UnionSSZForksTypeOf<SSZTypesByFork[F][Exclude<K, void>]>;

export function sszTypesFor<F extends ForkName, K extends keyof SSZTypesByFork[F] | void = void>(
fork: F,
Expand Down
6 changes: 3 additions & 3 deletions packages/types/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ForkAll, ForkBlobs, ForkExecution, ForkLightClient, ForkName} from "@lodestar/params";
import {ForkAll, ForkBlobs, ForkExecution, ForkLightClient, ForkName, ForkPreBlobs} from "@lodestar/params";
import {ts as phase0} from "./phase0/index.js";
import {ts as altair} from "./altair/index.js";
import {ts as bellatrix} from "./bellatrix/index.js";
Expand Down Expand Up @@ -159,11 +159,11 @@ export type BlockContents<F extends ForkBlobs = ForkBlobs> = TypesByFork[F]["Blo
export type SignedBlockContents<F extends ForkBlobs = ForkBlobs> = TypesByFork[F]["SignedBlockContents"];
export type SignedOrUnsignedBlockContents<F extends ForkBlobs = ForkBlobs> = BlockContents<F> | SignedBlockContents<F>;

export type BeaconBlockOrContents<FB extends ForkAll = ForkAll, FC extends ForkBlobs = ForkBlobs> =
export type BeaconBlockOrContents<FB extends ForkPreBlobs = ForkPreBlobs, FC extends ForkBlobs = ForkBlobs> =
| BeaconBlock<FB>
| BlockContents<FC>;

export type SignedBeaconBlockOrContents<FB extends ForkAll = ForkAll, FC extends ForkBlobs = ForkBlobs> =
export type SignedBeaconBlockOrContents<FB extends ForkPreBlobs = ForkPreBlobs, FC extends ForkBlobs = ForkBlobs> =
| SignedBeaconBlock<FB>
| SignedBlockContents<FC>;

Expand Down
Loading