From 9402fb53665c0766ae1be7254613397d9908699b Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Thu, 20 Jul 2023 13:10:47 +0100 Subject: [PATCH] Fix linting. --- api/v1/forkchoice.go | 4 ++-- api/v1/forkchoice_test.go | 2 +- spec/versionedsignedbeaconblock.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/api/v1/forkchoice.go b/api/v1/forkchoice.go index f170a493..b241565a 100644 --- a/api/v1/forkchoice.go +++ b/api/v1/forkchoice.go @@ -108,7 +108,7 @@ var ForkChoiceNodeValidityStrings = [...]string{ } func ForkChoiceNodeValidityFromString(input string) (ForkChoiceNodeValidity, error) { - switch strings.ToLower(string(input)) { + switch strings.ToLower(input) { case "invalid": return ForkChoiceNodeValidityInvalid, nil case "valid": @@ -116,7 +116,7 @@ func ForkChoiceNodeValidityFromString(input string) (ForkChoiceNodeValidity, err case "optimistic": return ForkChoiceNodeValidityOptimistic, nil default: - return ForkChoiceNodeValidityUnknown, fmt.Errorf("unrecognised fork choice validity: %s", string(input)) + return ForkChoiceNodeValidityUnknown, fmt.Errorf("unrecognised fork choice validity: %s", input) } } diff --git a/api/v1/forkchoice_test.go b/api/v1/forkchoice_test.go index bf26c245..ed4b1947 100644 --- a/api/v1/forkchoice_test.go +++ b/api/v1/forkchoice_test.go @@ -5,8 +5,8 @@ import ( "testing" api "github.com/attestantio/go-eth2-client/api/v1" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gotest.tools/assert" ) func TestForkChoiceJSON(t *testing.T) { diff --git a/spec/versionedsignedbeaconblock.go b/spec/versionedsignedbeaconblock.go index 0b484858..77676820 100644 --- a/spec/versionedsignedbeaconblock.go +++ b/spec/versionedsignedbeaconblock.go @@ -297,6 +297,36 @@ func (v *VersionedSignedBeaconBlock) ProposerSlashings() ([]*phase0.ProposerSlas } } +// SyncAggregate returns the sync aggregate of the beacon block. +func (v *VersionedSignedBeaconBlock) SyncAggregate() (*altair.SyncAggregate, error) { + switch v.Version { + case DataVersionPhase0: + return nil, errors.New("phase0 block does not have sync aggregate") + case DataVersionAltair: + if v.Altair == nil { + return nil, errors.New("no altair block") + } + return v.Altair.Message.Body.SyncAggregate, nil + case DataVersionBellatrix: + if v.Bellatrix == nil { + return nil, errors.New("no bellatrix block") + } + return v.Bellatrix.Message.Body.SyncAggregate, nil + case DataVersionCapella: + if v.Capella == nil { + return nil, errors.New("no capella block") + } + return v.Capella.Message.Body.SyncAggregate, nil + case DataVersionDeneb: + if v.Deneb == nil { + return nil, errors.New("no deneb block") + } + return v.Deneb.Message.Body.SyncAggregate, nil + default: + return nil, errors.New("unknown version") + } +} + // String returns a string version of the structure. func (v *VersionedSignedBeaconBlock) String() string { switch v.Version {