From 31dd168ac6164b4d0cf2f3ac3d2766317e550d14 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 24 Oct 2023 09:27:57 +0530 Subject: [PATCH 1/4] add slot() to versioned signed proposal --- api/versionedsignedproposal.go | 39 ++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/api/versionedsignedproposal.go b/api/versionedsignedproposal.go index 63e18473..9a806524 100644 --- a/api/versionedsignedproposal.go +++ b/api/versionedsignedproposal.go @@ -14,7 +14,8 @@ package api import ( - apiv1deneb "github.com/attestantio/go-eth2-client/api/v1/deneb" + "errors" + "github.com/attestantio/go-eth2-client/api/v1/deneb" "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/altair" "github.com/attestantio/go-eth2-client/spec/bellatrix" @@ -29,7 +30,41 @@ type VersionedSignedProposal struct { Altair *altair.SignedBeaconBlock Bellatrix *bellatrix.SignedBeaconBlock Capella *capella.SignedBeaconBlock - Deneb *apiv1deneb.SignedBlockContents + Deneb *deneb.SignedBlockContents +} + +// Slot returns the slot of the signed proposal. +func Slot(p VersionedSignedProposal) (phase0.Slot, error) { + switch p.Version { + case spec.DataVersionPhase0: + if p.Phase0 == nil || p.Phase0.Message == nil { + return 0, errors.New("no phase0 block") + } + case spec.DataVersionAltair: + if p.Altair == nil || p.Altair.Message == nil { + return 0, errors.New("no altair block") + } + case spec.DataVersionBellatrix: + if p.Bellatrix == nil || p.Bellatrix.Message == nil { + return 0, errors.New("no bellatrix block") + } + + return p.Bellatrix.Message.Slot, nil + case spec.DataVersionCapella: + if p.Capella == nil || p.Capella.Message == nil { + return 0, errors.New("no capella block") + } + + return p.Capella.Message.Slot, nil + case spec.DataVersionDeneb: + if p.Deneb == nil || p.Deneb.SignedBlock == nil || p.Deneb.SignedBlock.Message == nil { + return 0, errors.New("no deneb block") + } + + return p.Deneb.SignedBlock.Message.Slot, nil + default: + return 0, errors.New("unsupported version") + } } // String returns a string version of the structure. From 3e38a5fdcc2b11be8d738f25f14912938f36f685 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 24 Oct 2023 09:30:46 +0530 Subject: [PATCH 2/4] add slot() to versioned signed proposal --- api/versionedsignedproposal.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/versionedsignedproposal.go b/api/versionedsignedproposal.go index 9a806524..dd38f954 100644 --- a/api/versionedsignedproposal.go +++ b/api/versionedsignedproposal.go @@ -65,6 +65,8 @@ func Slot(p VersionedSignedProposal) (phase0.Slot, error) { default: return 0, errors.New("unsupported version") } + + return 0, errors.New("unsupported version") } // String returns a string version of the structure. From 07c31fb2efc4747f0fe7a6e98238c94e7232f024 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 25 Oct 2023 16:13:34 +0530 Subject: [PATCH 3/4] review comments --- api/versionedsignedproposal.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/api/versionedsignedproposal.go b/api/versionedsignedproposal.go index dd38f954..4d032062 100644 --- a/api/versionedsignedproposal.go +++ b/api/versionedsignedproposal.go @@ -15,7 +15,7 @@ package api import ( "errors" - "github.com/attestantio/go-eth2-client/api/v1/deneb" + apiv1deneb "github.com/attestantio/go-eth2-client/api/v1/deneb" "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/altair" "github.com/attestantio/go-eth2-client/spec/bellatrix" @@ -30,20 +30,18 @@ type VersionedSignedProposal struct { Altair *altair.SignedBeaconBlock Bellatrix *bellatrix.SignedBeaconBlock Capella *capella.SignedBeaconBlock - Deneb *deneb.SignedBlockContents + Deneb *apiv1deneb.SignedBlockContents } // Slot returns the slot of the signed proposal. func Slot(p VersionedSignedProposal) (phase0.Slot, error) { switch p.Version { - case spec.DataVersionPhase0: - if p.Phase0 == nil || p.Phase0.Message == nil { - return 0, errors.New("no phase0 block") - } case spec.DataVersionAltair: if p.Altair == nil || p.Altair.Message == nil { return 0, errors.New("no altair block") } + + return p.Altair.Message.Slot, nil case spec.DataVersionBellatrix: if p.Bellatrix == nil || p.Bellatrix.Message == nil { return 0, errors.New("no bellatrix block") @@ -65,8 +63,6 @@ func Slot(p VersionedSignedProposal) (phase0.Slot, error) { default: return 0, errors.New("unsupported version") } - - return 0, errors.New("unsupported version") } // String returns a string version of the structure. From 6e3146972a804acce7e4f65bb5c28667bec3f4f8 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 25 Oct 2023 16:16:10 +0530 Subject: [PATCH 4/4] fix golangci-lint error --- api/versionedsignedproposal.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/versionedsignedproposal.go b/api/versionedsignedproposal.go index 4d032062..afc7b08d 100644 --- a/api/versionedsignedproposal.go +++ b/api/versionedsignedproposal.go @@ -15,6 +15,7 @@ package api import ( "errors" + apiv1deneb "github.com/attestantio/go-eth2-client/api/v1/deneb" "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/altair"