From 824cbc694cb9f0cd29b53010e00cb6e2b5971aa6 Mon Sep 17 00:00:00 2001 From: pk910 Date: Mon, 23 Sep 2024 19:37:08 +0200 Subject: [PATCH] add `VersionedSignedBeaconBlock.ExecutionRequests()` --- spec/versionedsignedbeaconblock.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/versionedsignedbeaconblock.go b/spec/versionedsignedbeaconblock.go index 69a7ce51..d05fcd69 100644 --- a/spec/versionedsignedbeaconblock.go +++ b/spec/versionedsignedbeaconblock.go @@ -1017,6 +1017,32 @@ func (v *VersionedSignedBeaconBlock) BlobKZGCommitments() ([]deneb.KZGCommitment } } +// ExecutionRequests returs the execution requests for the block. +func (v *VersionedSignedBeaconBlock) ExecutionRequests() (*electra.ExecutionRequests, error) { + switch v.Version { + case DataVersionPhase0: + return nil, errors.New("phase0 block does not have execution requests") + case DataVersionAltair: + return nil, errors.New("altair block does not have execution requests") + case DataVersionBellatrix: + return nil, errors.New("bellatrix block does not have execution requests") + case DataVersionCapella: + return nil, errors.New("capella block does not have execution requests") + case DataVersionDeneb: + return nil, errors.New("deneb block does not have execution requests") + case DataVersionElectra: + if v.Electra == nil || + v.Electra.Message == nil || + v.Electra.Message.Body == nil { + return nil, errors.New("no electra block") + } + + return v.Electra.Message.Body.ExecutionRequests, nil + default: + return nil, errors.New("unknown version") + } +} + // String returns a string version of the structure. func (v *VersionedSignedBeaconBlock) String() string { switch v.Version {