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 signed validator registration list type #38

Draft
wants to merge 2 commits into
base: electra
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions api/v1/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package v1

// Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work.
//go:generate rm -f signedvalidatorregistration_encoding.go validatorregistration_encoding.go
//go:generate rm -f signedvalidatorregistrationlist_encoding.go signedvalidatorregistration_encoding.go validatorregistration_encoding.go
//nolint:revive
//go:generate sszgen -include ../../../go-eth2-client/spec/bellatrix,../../../go-eth2-client/spec/phase0 --path . --objs SignedValidatorRegistration,ValidatorRegistration
//go:generate goimports -w signedvalidatorregistration_encoding.go validatorregistration_encoding.go
//go:generate sszgen -include ../../../go-eth2-client/spec/bellatrix,../../../go-eth2-client/spec/phase0 --path . --objs SignedValidatorRegistrationList,SignedValidatorRegistration,ValidatorRegistration
//go:generate goimports -w signedvalidatorregistrationlist_encoding.go signedvalidatorregistration_encoding.go validatorregistration_encoding.go
56 changes: 56 additions & 0 deletions api/v1/signedvalidatorregistrationlist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package v1

import (
"encoding/json"
"fmt"

"github.com/goccy/go-yaml"
"github.com/pkg/errors"
)

// SignedValidatorRegistrationList represents a list of SignedValidatorRegistration.
type SignedValidatorRegistrationList struct {
Items []*SignedValidatorRegistration `json:"items" ssz-max:"1099511627776" yaml:"items"`
}

// MarshalJSON implements json.Marshaler.
func (s *SignedValidatorRegistrationList) MarshalJSON() ([]byte, error) {
return json.Marshal(s.Items)
}

// UnmarshalJSON implements json.Unmarshaler.
func (s *SignedValidatorRegistrationList) UnmarshalJSON(input []byte) error {
var data []*SignedValidatorRegistration
if err := json.Unmarshal(input, &data); err != nil {
return errors.Wrap(err, "invalid JSON")
}
s.Items = data

return nil
}

// MarshalYAML implements yaml.Marshaler.
func (s *SignedValidatorRegistrationList) MarshalYAML() ([]byte, error) {
return yaml.Marshal(s.Items)
}

// UnmarshalYAML implements yaml.Unmarshaler.
func (s *SignedValidatorRegistrationList) UnmarshalYAML(input []byte) error {
var data []*SignedValidatorRegistration
if err := yaml.Unmarshal(input, &data); err != nil {
return err
}
s.Items = data

return nil
}

// String returns a YAML representation of the list.
func (s *SignedValidatorRegistrationList) String() string {
data, err := yaml.Marshal(s)
if err != nil {
return fmt.Sprintf("ERR: %v", err)
}

return string(data)
}
119 changes: 119 additions & 0 deletions api/v1/signedvalidatorregistrationlist_encoding.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.