mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
beacon/engine,eth/catalyst: add Is(..) method to PayloadID to check version
Co-authored-by: lightclient <lightclient@protonmail.io> Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
parent
d8b4500586
commit
06aa873752
2 changed files with 24 additions and 0 deletions
|
|
@ -123,6 +123,21 @@ type TransitionConfigurationV1 struct {
|
||||||
// PayloadID is an identifier of the payload build process
|
// PayloadID is an identifier of the payload build process
|
||||||
type PayloadID [8]byte
|
type PayloadID [8]byte
|
||||||
|
|
||||||
|
// Version returns the payload version associated with the identifier.
|
||||||
|
func (b PayloadID) Version() PayloadVersion {
|
||||||
|
return PayloadVersion(b[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is returns whether the identifier matches any of provided payload versions.
|
||||||
|
func (b PayloadID) Is(versions ...PayloadVersion) bool {
|
||||||
|
for _, v := range versions {
|
||||||
|
if v == b.Version() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (b PayloadID) String() string {
|
func (b PayloadID) String() string {
|
||||||
return hexutil.Encode(b[:])
|
return hexutil.Encode(b[:])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -431,6 +431,9 @@ func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config engine.Transit
|
||||||
|
|
||||||
// GetPayloadV1 returns a cached payload by id.
|
// GetPayloadV1 returns a cached payload by id.
|
||||||
func (api *ConsensusAPI) GetPayloadV1(payloadID engine.PayloadID) (*engine.ExecutableData, error) {
|
func (api *ConsensusAPI) GetPayloadV1(payloadID engine.PayloadID) (*engine.ExecutableData, error) {
|
||||||
|
if !payloadID.Is(engine.PayloadV1) {
|
||||||
|
return nil, engine.UnsupportedFork
|
||||||
|
}
|
||||||
data, err := api.getPayload(payloadID, false)
|
data, err := api.getPayload(payloadID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -440,11 +443,17 @@ func (api *ConsensusAPI) GetPayloadV1(payloadID engine.PayloadID) (*engine.Execu
|
||||||
|
|
||||||
// GetPayloadV2 returns a cached payload by id.
|
// GetPayloadV2 returns a cached payload by id.
|
||||||
func (api *ConsensusAPI) GetPayloadV2(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
func (api *ConsensusAPI) GetPayloadV2(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
||||||
|
if !payloadID.Is(engine.PayloadV1, engine.PayloadV2) {
|
||||||
|
return nil, engine.UnsupportedFork
|
||||||
|
}
|
||||||
return api.getPayload(payloadID, false)
|
return api.getPayload(payloadID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPayloadV3 returns a cached payload by id.
|
// GetPayloadV3 returns a cached payload by id.
|
||||||
func (api *ConsensusAPI) GetPayloadV3(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
func (api *ConsensusAPI) GetPayloadV3(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
||||||
|
if !payloadID.Is(engine.PayloadV3) {
|
||||||
|
return nil, engine.UnsupportedFork
|
||||||
|
}
|
||||||
return api.getPayload(payloadID, false)
|
return api.getPayload(payloadID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue