Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Slot() to VersionedSignedProposal #86

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions api/versionedsignedproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
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"
Expand All @@ -32,6 +34,38 @@ type VersionedSignedProposal struct {
Deneb *apiv1deneb.SignedBlockContents
}

// Slot returns the slot of the signed proposal.
func Slot(p VersionedSignedProposal) (phase0.Slot, error) {
switch p.Version {
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")
}

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.
func (v *VersionedSignedProposal) String() string {
switch v.Version {
Expand Down