-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
346 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigAndParent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package tech.pegasys.teku.spec.config; | ||
|
||
import tech.pegasys.teku.spec.SpecMilestone; | ||
|
||
import java.util.Optional; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
public record SpecConfigAndParent<TConfig extends TParentConfig, | ||
TParentConfig extends SpecConfig>(TConfig specConfig, Optional<SpecConfigAndParent<TParentConfig, SpecConfig>> parentSpecConfig) { | ||
|
||
public static <TConfig extends TParentConfig, TParentConfig extends SpecConfig> SpecConfigAndParent<TConfig, TParentConfig> of(final TConfig spec, final SpecConfigAndParent<TParentConfig, SpecConfig> parentSpec) { | ||
return new SpecConfigAndParent<>(spec, Optional.of(parentSpec)); | ||
} | ||
|
||
public static <TConfig extends TParentConfig, TParentConfig extends SpecConfig> SpecConfigAndParent<TConfig, TParentConfig> of(final TConfig spec) { | ||
return new SpecConfigAndParent<>(spec, Optional.empty()); | ||
} | ||
|
||
public SpecConfig forMilestone(final SpecMilestone milestone) { | ||
if(specConfig.getMilestone() == milestone) { | ||
return specConfig; | ||
} | ||
if(parentSpecConfig.isEmpty()) { | ||
throw new IllegalArgumentException("No config available for milestone " + milestone); | ||
} | ||
return parentSpecConfig.get().forMilestone(milestone); | ||
} | ||
|
||
|
||
@SuppressWarnings("unchecked") | ||
public static SpecConfigAndParent<SpecConfigPhase0, SpecConfig> requirePhase0(final SpecConfigAndParent<?, SpecConfig> specConfigAndParent) { | ||
checkArgument( | ||
specConfigAndParent.specConfig.getMilestone() == SpecMilestone.PHASE0); | ||
return (SpecConfigAndParent<SpecConfigPhase0, SpecConfig>) specConfigAndParent; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static SpecConfigAndParent<SpecConfigAltair, SpecConfig> requireAltair(final SpecConfigAndParent<?, SpecConfig> specConfigAndParent) { | ||
checkArgument( | ||
specConfigAndParent.specConfig.getMilestone() == SpecMilestone.ALTAIR); | ||
return (SpecConfigAndParent<SpecConfigAltair, SpecConfig>) specConfigAndParent; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static SpecConfigAndParent<SpecConfigBellatrix, SpecConfig> requireBellatrix(final SpecConfigAndParent<?, SpecConfig> specConfigAndParent) { | ||
checkArgument( | ||
specConfigAndParent.specConfig.getMilestone() == SpecMilestone.BELLATRIX); | ||
return (SpecConfigAndParent<SpecConfigBellatrix, SpecConfig>) specConfigAndParent; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static SpecConfigAndParent<SpecConfigCapella, SpecConfig> requireCapella(final SpecConfigAndParent<?, SpecConfig> specConfigAndParent) { | ||
checkArgument( | ||
specConfigAndParent.specConfig.getMilestone() == SpecMilestone.CAPELLA); | ||
return (SpecConfigAndParent<SpecConfigCapella, SpecConfig>) specConfigAndParent; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static SpecConfigAndParent<SpecConfigDeneb, SpecConfig> requireDeneb(final SpecConfigAndParent<?, SpecConfig> specConfigAndParent) { | ||
checkArgument( | ||
specConfigAndParent.specConfig.getMilestone() == SpecMilestone.DENEB); | ||
return (SpecConfigAndParent<SpecConfigDeneb, SpecConfig>) specConfigAndParent; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static SpecConfigAndParent<SpecConfigElectra, SpecConfig> requireElectra(final SpecConfigAndParent<?, SpecConfig> specConfigAndParent) { | ||
checkArgument( | ||
specConfigAndParent.specConfig.getMilestone() == SpecMilestone.ELECTRA); | ||
return (SpecConfigAndParent<SpecConfigElectra, SpecConfig>) specConfigAndParent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.