diff --git a/.golangci.yml b/.golangci.yml index 99afd744..1872bc6f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -126,19 +126,13 @@ linters: # Disable specific linter # https://golangci-lint.run/usage/linters/#disabled-by-default disable: - - contextcheck - cyclop - deadcode - - decorder - depguard - dupl - - dupword - - errchkjson - - errorlint - exhaustive - exhaustivestruct - exhaustruct - - forbidigo - forcetypeassert - funlen - gci @@ -147,7 +141,6 @@ linters: - gocognit - goconst - goerr113 - - gofumpt - goheader - golint - gomnd @@ -158,19 +151,11 @@ linters: - maintidx - maligned - musttag - - nilnil - - nlreturn - - nolintlint - nosnakecase - - promlinter - - rowserrcheck - scopelint - - sqlclosecheck - structcheck - - thelper - varcheck - varnamelen - - wastedassign - whitespace - wrapcheck - wsl diff --git a/api/v1/attesterduty.go b/api/v1/attesterduty.go index b87cfa2a..c70e3905 100644 --- a/api/v1/attesterduty.go +++ b/api/v1/attesterduty.go @@ -143,5 +143,6 @@ func (a *AttesterDuty) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/beaconblockheader.go b/api/v1/beaconblockheader.go index e41c80e3..d93734cd 100644 --- a/api/v1/beaconblockheader.go +++ b/api/v1/beaconblockheader.go @@ -84,5 +84,6 @@ func (b *BeaconBlockHeader) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/beaconcommittee.go b/api/v1/beaconcommittee.go index e2d83a4d..f6786dfe 100644 --- a/api/v1/beaconcommittee.go +++ b/api/v1/beaconcommittee.go @@ -45,6 +45,7 @@ func (b *BeaconCommittee) MarshalJSON() ([]byte, error) { for i := range b.Validators { validators[i] = fmt.Sprintf("%d", b.Validators[i]) } + return json.Marshal(&beaconCommitteeJSON{ Slot: fmt.Sprintf("%d", b.Slot), Index: fmt.Sprintf("%d", b.Index), @@ -100,5 +101,6 @@ func (b *BeaconCommittee) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/beaconcommitteesubscription.go b/api/v1/beaconcommitteesubscription.go index d5fab1d6..78cbba48 100644 --- a/api/v1/beaconcommitteesubscription.go +++ b/api/v1/beaconcommitteesubscription.go @@ -108,5 +108,6 @@ func (b *BeaconCommitteeSubscription) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/bellatrix/blindedbeaconblock.go b/api/v1/bellatrix/blindedbeaconblock.go index cd3af115..07ef4308 100644 --- a/api/v1/bellatrix/blindedbeaconblock.go +++ b/api/v1/bellatrix/blindedbeaconblock.go @@ -35,5 +35,6 @@ func (b *BlindedBeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/bellatrix/blindedbeaconblock_json.go b/api/v1/bellatrix/blindedbeaconblock_json.go index d50addc0..d418bf8b 100644 --- a/api/v1/bellatrix/blindedbeaconblock_json.go +++ b/api/v1/bellatrix/blindedbeaconblock_json.go @@ -50,6 +50,7 @@ func (b *BlindedBeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } diff --git a/api/v1/bellatrix/blindedbeaconblock_yaml.go b/api/v1/bellatrix/blindedbeaconblock_yaml.go index 55e22589..a46ccdeb 100644 --- a/api/v1/bellatrix/blindedbeaconblock_yaml.go +++ b/api/v1/bellatrix/blindedbeaconblock_yaml.go @@ -41,6 +41,7 @@ func (b *BlindedBeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -51,5 +52,6 @@ func (b *BlindedBeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } diff --git a/api/v1/bellatrix/blindedbeaconblockbody.go b/api/v1/bellatrix/blindedbeaconblockbody.go index 73776dd2..5908fcc6 100644 --- a/api/v1/bellatrix/blindedbeaconblockbody.go +++ b/api/v1/bellatrix/blindedbeaconblockbody.go @@ -42,5 +42,6 @@ func (b *BlindedBeaconBlockBody) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/bellatrix/blindedbeaconblockbody_json.go b/api/v1/bellatrix/blindedbeaconblockbody_json.go index be6b9194..6609d761 100644 --- a/api/v1/bellatrix/blindedbeaconblockbody_json.go +++ b/api/v1/bellatrix/blindedbeaconblockbody_json.go @@ -61,6 +61,7 @@ func (b *BlindedBeaconBlockBody) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } diff --git a/api/v1/bellatrix/blindedbeaconblockbody_yaml.go b/api/v1/bellatrix/blindedbeaconblockbody_yaml.go index 5b37951b..8dcccdc2 100644 --- a/api/v1/bellatrix/blindedbeaconblockbody_yaml.go +++ b/api/v1/bellatrix/blindedbeaconblockbody_yaml.go @@ -54,6 +54,7 @@ func (b *BlindedBeaconBlockBody) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -64,5 +65,6 @@ func (b *BlindedBeaconBlockBody) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } diff --git a/api/v1/bellatrix/signedblindedbeaconblock.go b/api/v1/bellatrix/signedblindedbeaconblock.go index 8ab0b208..11f80c31 100644 --- a/api/v1/bellatrix/signedblindedbeaconblock.go +++ b/api/v1/bellatrix/signedblindedbeaconblock.go @@ -32,5 +32,6 @@ func (s *SignedBlindedBeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/bellatrix/signedblindedbeaconblock_json.go b/api/v1/bellatrix/signedblindedbeaconblock_json.go index 3b05fff2..ef3b86b8 100644 --- a/api/v1/bellatrix/signedblindedbeaconblock_json.go +++ b/api/v1/bellatrix/signedblindedbeaconblock_json.go @@ -43,6 +43,7 @@ func (s *SignedBlindedBeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&data) } diff --git a/api/v1/bellatrix/signedblindedbeaconblock_yaml.go b/api/v1/bellatrix/signedblindedbeaconblock_yaml.go index 2eb39fbd..4db5a064 100644 --- a/api/v1/bellatrix/signedblindedbeaconblock_yaml.go +++ b/api/v1/bellatrix/signedblindedbeaconblock_yaml.go @@ -35,6 +35,7 @@ func (s *SignedBlindedBeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -45,5 +46,6 @@ func (s *SignedBlindedBeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } diff --git a/api/v1/blobsidecarevent.go b/api/v1/blobsidecarevent.go index ef566a7d..c84f4646 100644 --- a/api/v1/blobsidecarevent.go +++ b/api/v1/blobsidecarevent.go @@ -92,5 +92,6 @@ func (e *BlobSidecarEvent) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/blockevent.go b/api/v1/blockevent.go index 6808f88f..fb748c29 100644 --- a/api/v1/blockevent.go +++ b/api/v1/blockevent.go @@ -85,5 +85,6 @@ func (e *BlockEvent) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/capella/blindedbeaconblock.go b/api/v1/capella/blindedbeaconblock.go index 8772a882..5e2e953b 100644 --- a/api/v1/capella/blindedbeaconblock.go +++ b/api/v1/capella/blindedbeaconblock.go @@ -35,5 +35,6 @@ func (b *BlindedBeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/capella/blindedbeaconblock_json.go b/api/v1/capella/blindedbeaconblock_json.go index 7c182ccf..2e7c9336 100644 --- a/api/v1/capella/blindedbeaconblock_json.go +++ b/api/v1/capella/blindedbeaconblock_json.go @@ -50,6 +50,7 @@ func (b *BlindedBeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } diff --git a/api/v1/capella/blindedbeaconblock_yaml.go b/api/v1/capella/blindedbeaconblock_yaml.go index 349c5b20..2f62d051 100644 --- a/api/v1/capella/blindedbeaconblock_yaml.go +++ b/api/v1/capella/blindedbeaconblock_yaml.go @@ -41,6 +41,7 @@ func (b *BlindedBeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -51,5 +52,6 @@ func (b *BlindedBeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } diff --git a/api/v1/capella/blindedbeaconblockbody.go b/api/v1/capella/blindedbeaconblockbody.go index 9c5fe134..d0a2b77e 100644 --- a/api/v1/capella/blindedbeaconblockbody.go +++ b/api/v1/capella/blindedbeaconblockbody.go @@ -43,5 +43,6 @@ func (b *BlindedBeaconBlockBody) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/capella/blindedbeaconblockbody_json.go b/api/v1/capella/blindedbeaconblockbody_json.go index ad57b55c..dd399db3 100644 --- a/api/v1/capella/blindedbeaconblockbody_json.go +++ b/api/v1/capella/blindedbeaconblockbody_json.go @@ -63,6 +63,7 @@ func (b *BlindedBeaconBlockBody) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } diff --git a/api/v1/capella/blindedbeaconblockbody_yaml.go b/api/v1/capella/blindedbeaconblockbody_yaml.go index ee37cc5a..f618ebef 100644 --- a/api/v1/capella/blindedbeaconblockbody_yaml.go +++ b/api/v1/capella/blindedbeaconblockbody_yaml.go @@ -56,6 +56,7 @@ func (b *BlindedBeaconBlockBody) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -66,5 +67,6 @@ func (b *BlindedBeaconBlockBody) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } diff --git a/api/v1/capella/signedblindedbeaconblock.go b/api/v1/capella/signedblindedbeaconblock.go index c6c1878f..920257e8 100644 --- a/api/v1/capella/signedblindedbeaconblock.go +++ b/api/v1/capella/signedblindedbeaconblock.go @@ -32,5 +32,6 @@ func (s *SignedBlindedBeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/capella/signedblindedbeaconblock_json.go b/api/v1/capella/signedblindedbeaconblock_json.go index 40b8df0b..2d4a13d0 100644 --- a/api/v1/capella/signedblindedbeaconblock_json.go +++ b/api/v1/capella/signedblindedbeaconblock_json.go @@ -43,6 +43,7 @@ func (s *SignedBlindedBeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&data) } diff --git a/api/v1/capella/signedblindedbeaconblock_yaml.go b/api/v1/capella/signedblindedbeaconblock_yaml.go index 7bd6e7c5..366d59df 100644 --- a/api/v1/capella/signedblindedbeaconblock_yaml.go +++ b/api/v1/capella/signedblindedbeaconblock_yaml.go @@ -35,6 +35,7 @@ func (s *SignedBlindedBeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -45,5 +46,6 @@ func (s *SignedBlindedBeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } diff --git a/api/v1/chainreorgevent.go b/api/v1/chainreorgevent.go index b5197558..dd5a8fd2 100644 --- a/api/v1/chainreorgevent.go +++ b/api/v1/chainreorgevent.go @@ -143,5 +143,6 @@ func (e *ChainReorgEvent) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/deneb/blindedbeaconblock.go b/api/v1/deneb/blindedbeaconblock.go index 8e3f6b9c..80605b49 100644 --- a/api/v1/deneb/blindedbeaconblock.go +++ b/api/v1/deneb/blindedbeaconblock.go @@ -35,5 +35,6 @@ func (b *BlindedBeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/deneb/blindedbeaconblock_json.go b/api/v1/deneb/blindedbeaconblock_json.go index 8a174813..abb72656 100644 --- a/api/v1/deneb/blindedbeaconblock_json.go +++ b/api/v1/deneb/blindedbeaconblock_json.go @@ -50,6 +50,7 @@ func (b *BlindedBeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } diff --git a/api/v1/deneb/blindedbeaconblock_yaml.go b/api/v1/deneb/blindedbeaconblock_yaml.go index 9f5e8210..cf60000a 100644 --- a/api/v1/deneb/blindedbeaconblock_yaml.go +++ b/api/v1/deneb/blindedbeaconblock_yaml.go @@ -41,6 +41,7 @@ func (b *BlindedBeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -51,5 +52,6 @@ func (b *BlindedBeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } diff --git a/api/v1/deneb/blindedbeaconblockbody.go b/api/v1/deneb/blindedbeaconblockbody.go index e7930e4b..f88adb1b 100644 --- a/api/v1/deneb/blindedbeaconblockbody.go +++ b/api/v1/deneb/blindedbeaconblockbody.go @@ -45,5 +45,6 @@ func (b *BlindedBeaconBlockBody) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/deneb/blindedbeaconblockbody_json.go b/api/v1/deneb/blindedbeaconblockbody_json.go index b40d92b7..e76a0809 100644 --- a/api/v1/deneb/blindedbeaconblockbody_json.go +++ b/api/v1/deneb/blindedbeaconblockbody_json.go @@ -71,6 +71,7 @@ func (b *BlindedBeaconBlockBody) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } diff --git a/api/v1/deneb/blindedbeaconblockbody_yaml.go b/api/v1/deneb/blindedbeaconblockbody_yaml.go index b600c1c0..504d418d 100644 --- a/api/v1/deneb/blindedbeaconblockbody_yaml.go +++ b/api/v1/deneb/blindedbeaconblockbody_yaml.go @@ -64,6 +64,7 @@ func (b *BlindedBeaconBlockBody) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -74,5 +75,6 @@ func (b *BlindedBeaconBlockBody) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } diff --git a/api/v1/deneb/blindedblobsidecar.go b/api/v1/deneb/blindedblobsidecar.go index 573033c7..f09e54a3 100644 --- a/api/v1/deneb/blindedblobsidecar.go +++ b/api/v1/deneb/blindedblobsidecar.go @@ -39,5 +39,6 @@ func (b *BlindedBlobSidecar) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/deneb/blindedblobsidecar_yaml.go b/api/v1/deneb/blindedblobsidecar_yaml.go index 332170c2..9319802a 100644 --- a/api/v1/deneb/blindedblobsidecar_yaml.go +++ b/api/v1/deneb/blindedblobsidecar_yaml.go @@ -50,6 +50,7 @@ func (b *BlindedBlobSidecar) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } diff --git a/api/v1/deneb/blindedblockcontents.go b/api/v1/deneb/blindedblockcontents.go index b106a471..af82916b 100644 --- a/api/v1/deneb/blindedblockcontents.go +++ b/api/v1/deneb/blindedblockcontents.go @@ -31,5 +31,6 @@ func (b *BlindedBlockContents) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/deneb/blindedblockcontents_yaml.go b/api/v1/deneb/blindedblockcontents_yaml.go index 9c592173..86d66fb9 100644 --- a/api/v1/deneb/blindedblockcontents_yaml.go +++ b/api/v1/deneb/blindedblockcontents_yaml.go @@ -27,7 +27,7 @@ type blindedBlockContentsYAML struct { BlindedBlobSidecars []*BlindedBlobSidecar `yaml:"blinded_blob_sidecars"` } -// MarshalJSON implements json.Marshaler. +// MarshalYAML implements yaml.Marshaler. func (b *BlindedBlockContents) MarshalYAML() ([]byte, error) { yamlBytes, err := yaml.MarshalWithOptions(&blindedBlockContentsYAML{ BlindedBlock: b.BlindedBlock, @@ -36,10 +36,11 @@ func (b *BlindedBlockContents) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } -// UnmarshalJSON implements json.Unmarshaler. +// UnmarshalYAML implements yaml.Unmarshaler. func (b *BlindedBlockContents) UnmarshalYAML(input []byte) error { var data blindedBlockContentsJSON if err := yaml.Unmarshal(input, &data); err != nil { diff --git a/api/v1/deneb/blockcontents.go b/api/v1/deneb/blockcontents.go index 8658ba6c..2b143dd5 100644 --- a/api/v1/deneb/blockcontents.go +++ b/api/v1/deneb/blockcontents.go @@ -32,5 +32,6 @@ func (b *BlockContents) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/deneb/blockcontents_json.go b/api/v1/deneb/blockcontents_json.go index f4d1c2ff..afb6e5a5 100644 --- a/api/v1/deneb/blockcontents_json.go +++ b/api/v1/deneb/blockcontents_json.go @@ -40,6 +40,7 @@ func (b *BlockContents) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } diff --git a/api/v1/deneb/blockcontents_yaml.go b/api/v1/deneb/blockcontents_yaml.go index b29afe2e..0ca06890 100644 --- a/api/v1/deneb/blockcontents_yaml.go +++ b/api/v1/deneb/blockcontents_yaml.go @@ -35,6 +35,7 @@ func (b *BlockContents) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -45,5 +46,6 @@ func (b *BlockContents) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } diff --git a/api/v1/deneb/signedblindedbeaconblock.go b/api/v1/deneb/signedblindedbeaconblock.go index af6d0464..6d2f8179 100644 --- a/api/v1/deneb/signedblindedbeaconblock.go +++ b/api/v1/deneb/signedblindedbeaconblock.go @@ -32,5 +32,6 @@ func (s *SignedBlindedBeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/deneb/signedblindedbeaconblock_json.go b/api/v1/deneb/signedblindedbeaconblock_json.go index 4e29c276..6c72f920 100644 --- a/api/v1/deneb/signedblindedbeaconblock_json.go +++ b/api/v1/deneb/signedblindedbeaconblock_json.go @@ -43,6 +43,7 @@ func (s *SignedBlindedBeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&data) } diff --git a/api/v1/deneb/signedblindedbeaconblock_yaml.go b/api/v1/deneb/signedblindedbeaconblock_yaml.go index e3637f19..c65e7a4e 100644 --- a/api/v1/deneb/signedblindedbeaconblock_yaml.go +++ b/api/v1/deneb/signedblindedbeaconblock_yaml.go @@ -35,6 +35,7 @@ func (s *SignedBlindedBeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -45,5 +46,6 @@ func (s *SignedBlindedBeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } diff --git a/api/v1/deneb/signedblindedblobsidecar.go b/api/v1/deneb/signedblindedblobsidecar.go index bb77e45e..c314e751 100644 --- a/api/v1/deneb/signedblindedblobsidecar.go +++ b/api/v1/deneb/signedblindedblobsidecar.go @@ -32,5 +32,6 @@ func (s *SignedBlindedBlobSidecar) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/deneb/signedblindedblobsidecar_yaml.go b/api/v1/deneb/signedblindedblobsidecar_yaml.go index b82ad0e7..814b3105 100644 --- a/api/v1/deneb/signedblindedblobsidecar_yaml.go +++ b/api/v1/deneb/signedblindedblobsidecar_yaml.go @@ -27,7 +27,7 @@ type signedBlindedBlobSidecarYAML struct { Signature string `yaml:"signature"` } -// MarshalJSON implements json.Marshaler. +// MarshalYAML implements yaml.Marshaler. func (s *SignedBlindedBlobSidecar) MarshalYAML() ([]byte, error) { yamlBytes, err := yaml.MarshalWithOptions(&signedBlindedBlobSidecarYAML{ Message: s.Message, @@ -36,10 +36,11 @@ func (s *SignedBlindedBlobSidecar) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } -// UnmarshalJSON implements json.Unmarshaler. +// UnmarshalYAML implements yaml.Unmarshaler. func (s *SignedBlindedBlobSidecar) UnmarshalYAML(input []byte) error { var data signedBlindedBlobSidecarJSON if err := yaml.Unmarshal(input, &data); err != nil { diff --git a/api/v1/deneb/signedblindedblockcontents.go b/api/v1/deneb/signedblindedblockcontents.go index 896d74b8..a35b9092 100644 --- a/api/v1/deneb/signedblindedblockcontents.go +++ b/api/v1/deneb/signedblindedblockcontents.go @@ -31,5 +31,6 @@ func (s *SignedBlindedBlockContents) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/deneb/signedblindedblockcontents_yaml.go b/api/v1/deneb/signedblindedblockcontents_yaml.go index 48cd2199..202c26a9 100644 --- a/api/v1/deneb/signedblindedblockcontents_yaml.go +++ b/api/v1/deneb/signedblindedblockcontents_yaml.go @@ -27,7 +27,7 @@ type signedBlindedBlockContentsYAML struct { SignedBlindedBlobSidecars []*SignedBlindedBlobSidecar `yaml:"signed_blinded_blob_sidecars"` } -// MarshalJSON implements json.Marshaler. +// MarshalYAML implements yaml.Marshaler. func (s *SignedBlindedBlockContents) MarshalYAML() ([]byte, error) { yamlBytes, err := yaml.MarshalWithOptions(&signedBlindedBlockContentsYAML{ SignedBlindedBlock: s.SignedBlindedBlock, @@ -36,10 +36,11 @@ func (s *SignedBlindedBlockContents) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } -// UnmarshalJSON implements json.Unmarshaler. +// UnmarshalYAML implements yaml.Unmarshaler. func (s *SignedBlindedBlockContents) UnmarshalYAML(input []byte) error { var data signedBlindedBlockContentsJSON if err := yaml.Unmarshal(input, &data); err != nil { diff --git a/api/v1/deneb/signedblockcontents.go b/api/v1/deneb/signedblockcontents.go index 5a647f79..00de2cd6 100644 --- a/api/v1/deneb/signedblockcontents.go +++ b/api/v1/deneb/signedblockcontents.go @@ -32,5 +32,6 @@ func (s *SignedBlockContents) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/deneb/signedblockcontents_yaml.go b/api/v1/deneb/signedblockcontents_yaml.go index d2bdf5c6..6333cb32 100644 --- a/api/v1/deneb/signedblockcontents_yaml.go +++ b/api/v1/deneb/signedblockcontents_yaml.go @@ -37,6 +37,7 @@ func (s *SignedBlockContents) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } diff --git a/api/v1/depositcontract.go b/api/v1/depositcontract.go index fb79c3db..9333cdfc 100644 --- a/api/v1/depositcontract.go +++ b/api/v1/depositcontract.go @@ -76,5 +76,6 @@ func (d *DepositContract) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/event.go b/api/v1/event.go index 06724def..5de4ddb8 100644 --- a/api/v1/event.go +++ b/api/v1/event.go @@ -123,5 +123,6 @@ func (e *Event) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/finality.go b/api/v1/finality.go index 1c461407..dc622033 100644 --- a/api/v1/finality.go +++ b/api/v1/finality.go @@ -77,5 +77,6 @@ func (f *Finality) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/finalizedcheckpointevent.go b/api/v1/finalizedcheckpointevent.go index 8850a53d..d65cb9a4 100644 --- a/api/v1/finalizedcheckpointevent.go +++ b/api/v1/finalizedcheckpointevent.go @@ -95,5 +95,6 @@ func (e *FinalizedCheckpointEvent) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/forkchoice.go b/api/v1/forkchoice.go index b241565a..bc23e073 100644 --- a/api/v1/forkchoice.go +++ b/api/v1/forkchoice.go @@ -76,6 +76,7 @@ func (f *ForkChoice) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } @@ -100,6 +101,7 @@ const ( ForkChoiceNodeValidityOptimistic ) +// ForkChoiceNodeValidityStrings are the strings for fork choice validity names. var ForkChoiceNodeValidityStrings = [...]string{ "unknown", "invalid", @@ -107,6 +109,7 @@ var ForkChoiceNodeValidityStrings = [...]string{ "optimistic", } +// ForkChoiceNodeValidityFromString converts a string input to a fork choice. func ForkChoiceNodeValidityFromString(input string) (ForkChoiceNodeValidity, error) { switch strings.ToLower(input) { case "invalid": @@ -142,9 +145,11 @@ func (d ForkChoiceNodeValidity) String() string { if int(d) >= len(ForkChoiceNodeValidityStrings) { return "unknown" } + return ForkChoiceNodeValidityStrings[d] } +// ForkChoiceNode is a node in the fork choice tree. type ForkChoiceNode struct { // Slot is the slot of the node. Slot phase0.Slot @@ -268,5 +273,6 @@ func (f *ForkChoiceNode) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/genesis.go b/api/v1/genesis.go index 2e0f42d0..e2345845 100644 --- a/api/v1/genesis.go +++ b/api/v1/genesis.go @@ -99,5 +99,6 @@ func (g *Genesis) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/headevent.go b/api/v1/headevent.go index a08b74ca..605f9359 100644 --- a/api/v1/headevent.go +++ b/api/v1/headevent.go @@ -136,5 +136,6 @@ func (e *HeadEvent) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/payloadattributesevent.go b/api/v1/payloadattributesevent.go index 91f9f086..2ef57d6e 100644 --- a/api/v1/payloadattributesevent.go +++ b/api/v1/payloadattributesevent.go @@ -124,6 +124,7 @@ func (p *PayloadAttributesV1) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &payloadAttributes); err != nil { return errors.Wrap(err, "invalid JSON") } + return p.unpack(&payloadAttributes) } @@ -171,6 +172,7 @@ func (p *PayloadAttributesV2) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &payloadAttributes); err != nil { return errors.Wrap(err, "invalid JSON") } + return p.unpack(&payloadAttributes) } @@ -217,11 +219,13 @@ func (p *PayloadAttributesV2) unpack(data *payloadAttributesV2JSON) error { return nil } +// UnmarshalJSON implements json.Unmarshaler. func (p *PayloadAttributesV3) UnmarshalJSON(input []byte) error { var payloadAttributes payloadAttributesV3JSON if err := json.Unmarshal(input, &payloadAttributes); err != nil { return errors.Wrap(err, "invalid JSON") } + return p.unpack(&payloadAttributes) } @@ -350,6 +354,7 @@ func (e *PayloadAttributesEvent) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &event); err != nil { return errors.Wrap(err, "invalid JSON") } + return e.unpack(&event) } @@ -452,5 +457,6 @@ func (e *PayloadAttributesEvent) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/proposalpreparation.go b/api/v1/proposalpreparation.go index 9085e3cd..f1394489 100644 --- a/api/v1/proposalpreparation.go +++ b/api/v1/proposalpreparation.go @@ -83,5 +83,6 @@ func (p *ProposalPreparation) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/proposerduty.go b/api/v1/proposerduty.go index a1389f04..a271d6b6 100644 --- a/api/v1/proposerduty.go +++ b/api/v1/proposerduty.go @@ -92,5 +92,6 @@ func (p *ProposerDuty) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/signedvalidatorregistration.go b/api/v1/signedvalidatorregistration.go index 5e0eb463..4594a8eb 100644 --- a/api/v1/signedvalidatorregistration.go +++ b/api/v1/signedvalidatorregistration.go @@ -57,6 +57,7 @@ func (s *SignedValidatorRegistration) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&data) } @@ -89,6 +90,7 @@ func (s *SignedValidatorRegistration) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -99,6 +101,7 @@ func (s *SignedValidatorRegistration) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } @@ -108,5 +111,6 @@ func (s *SignedValidatorRegistration) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/synccommittee.go b/api/v1/synccommittee.go index 56db98b4..5ef48a17 100644 --- a/api/v1/synccommittee.go +++ b/api/v1/synccommittee.go @@ -109,5 +109,6 @@ func (s *SyncCommittee) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/synccommitteeduty.go b/api/v1/synccommitteeduty.go index f602f2c9..53456aed 100644 --- a/api/v1/synccommitteeduty.go +++ b/api/v1/synccommitteeduty.go @@ -47,6 +47,7 @@ func (s *SyncCommitteeDuty) MarshalJSON() ([]byte, error) { for i := range s.ValidatorSyncCommitteeIndices { validatorSyncCommitteeIndices[i] = fmt.Sprintf("%d", s.ValidatorSyncCommitteeIndices[i]) } + return json.Marshal(&syncCommitteeDutyJSON{ PubKey: fmt.Sprintf("%#x", s.PubKey), ValidatorIndex: fmt.Sprintf("%d", s.ValidatorIndex), @@ -103,5 +104,6 @@ func (s *SyncCommitteeDuty) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/synccommitteesubscription.go b/api/v1/synccommitteesubscription.go index 8d38cfce..a6d72a6f 100644 --- a/api/v1/synccommitteesubscription.go +++ b/api/v1/synccommitteesubscription.go @@ -45,6 +45,7 @@ func (s *SyncCommitteeSubscription) MarshalJSON() ([]byte, error) { for i, syncCommitteeIndex := range s.SyncCommitteeIndices { syncCommitteeIndices[i] = fmt.Sprintf("%d", syncCommitteeIndex) } + return json.Marshal(&syncCommitteeSubscriptionJSON{ ValidatorIndex: fmt.Sprintf("%d", s.ValidatorIndex), SyncCommitteeIndices: syncCommitteeIndices, @@ -98,5 +99,6 @@ func (s *SyncCommitteeSubscription) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/syncstate.go b/api/v1/syncstate.go index 688f8816..00c86c38 100644 --- a/api/v1/syncstate.go +++ b/api/v1/syncstate.go @@ -88,5 +88,6 @@ func (s *SyncState) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/validator.go b/api/v1/validator.go index 3c9e7262..a96c635f 100644 --- a/api/v1/validator.go +++ b/api/v1/validator.go @@ -88,6 +88,7 @@ func (v *Validator) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/validatorbalance.go b/api/v1/validatorbalance.go index bd3c5b07..538a2887 100644 --- a/api/v1/validatorbalance.go +++ b/api/v1/validatorbalance.go @@ -76,5 +76,6 @@ func (v *ValidatorBalance) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/validatorregistration.go b/api/v1/validatorregistration.go index b69d8302..df161fd3 100644 --- a/api/v1/validatorregistration.go +++ b/api/v1/validatorregistration.go @@ -68,6 +68,7 @@ func (v *ValidatorRegistration) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return v.unpack(&data) } @@ -125,6 +126,7 @@ func (v *ValidatorRegistration) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -135,6 +137,7 @@ func (v *ValidatorRegistration) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return v.unpack(&data) } @@ -144,5 +147,6 @@ func (v *ValidatorRegistration) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/api/v1/validatorstate.go b/api/v1/validatorstate.go index c7037dcd..046156d2 100644 --- a/api/v1/validatorstate.go +++ b/api/v1/validatorstate.go @@ -91,6 +91,7 @@ func (v *ValidatorState) UnmarshalJSON(input []byte) error { default: err = fmt.Errorf("unrecognised validator state %s", string(input)) } + return err } @@ -161,6 +162,7 @@ func ValidatorToState(validator *phase0.Validator, if validator.ActivationEligibilityEpoch == farFutureEpoch { return ValidatorStatePendingInitialized } + return ValidatorStatePendingQueued } @@ -172,6 +174,7 @@ func ValidatorToState(validator *phase0.Validator, if validator.Slashed { return ValidatorStateActiveSlashed } + return ValidatorStateActiveExiting } @@ -180,6 +183,7 @@ func ValidatorToState(validator *phase0.Validator, if validator.Slashed { return ValidatorStateExitedSlashed } + return ValidatorStateExitedUnslashed } @@ -188,6 +192,7 @@ func ValidatorToState(validator *phase0.Validator, // We have a definite balance of 0. return ValidatorStateWithdrawalDone } + // No balance information, or balance > 0. return ValidatorStateWithdrawalPossible } diff --git a/api/versionedblindedbeaconblock.go b/api/versionedblindedbeaconblock.go index b272ef5b..51d29bd7 100644 --- a/api/versionedblindedbeaconblock.go +++ b/api/versionedblindedbeaconblock.go @@ -44,16 +44,19 @@ func (v *VersionedBlindedBeaconBlock) Slot() (phase0.Slot, error) { if v.Bellatrix == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Slot, nil case spec.DataVersionCapella: if v.Capella == nil { return 0, errors.New("no capella block") } + return v.Capella.Slot, nil case spec.DataVersionDeneb: if v.Deneb == nil { return 0, errors.New("no deneb block") } + return v.Deneb.Slot, nil default: return 0, errors.New("unsupported version") @@ -67,16 +70,19 @@ func (v *VersionedBlindedBeaconBlock) ProposerIndex() (phase0.ValidatorIndex, er if v.Bellatrix == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.ProposerIndex, nil case spec.DataVersionCapella: if v.Capella == nil { return 0, errors.New("no capella block") } + return v.Capella.ProposerIndex, nil case spec.DataVersionDeneb: if v.Deneb == nil { return 0, errors.New("no deneb block") } + return v.Deneb.ProposerIndex, nil default: return 0, errors.New("unknown version") @@ -90,16 +96,19 @@ func (v *VersionedBlindedBeaconBlock) RandaoReveal() (phase0.BLSSignature, error if v.Bellatrix == nil || v.Bellatrix.Body == nil { return phase0.BLSSignature{}, errors.New("no bellatrix block") } + return v.Bellatrix.Body.RANDAOReveal, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return phase0.BLSSignature{}, errors.New("no capella block") } + return v.Capella.Body.RANDAOReveal, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Body == nil { return phase0.BLSSignature{}, errors.New("no deneb block") } + return v.Deneb.Body.RANDAOReveal, nil default: return phase0.BLSSignature{}, errors.New("unsupported version") @@ -113,16 +122,19 @@ func (v *VersionedBlindedBeaconBlock) Graffiti() ([32]byte, error) { if v.Bellatrix == nil || v.Bellatrix.Body == nil { return [32]byte{}, errors.New("no bellatrix block") } + return v.Bellatrix.Body.Graffiti, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return [32]byte{}, errors.New("no capella block") } + return v.Capella.Body.Graffiti, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Body == nil { return [32]byte{}, errors.New("no deneb block") } + return v.Deneb.Body.Graffiti, nil default: return [32]byte{}, errors.New("unsupported version") @@ -136,16 +148,19 @@ func (v *VersionedBlindedBeaconBlock) Attestations() ([]*phase0.Attestation, err if v.Bellatrix == nil || v.Bellatrix.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Body.Attestations, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Body.Attestations, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Body.Attestations, nil default: return nil, errors.New("unsupported version") @@ -159,16 +174,19 @@ func (v *VersionedBlindedBeaconBlock) Root() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -182,16 +200,19 @@ func (v *VersionedBlindedBeaconBlock) BodyRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Body.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Body.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Body.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -205,16 +226,19 @@ func (v *VersionedBlindedBeaconBlock) ParentRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.ParentRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.ParentRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.ParentRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -228,16 +252,19 @@ func (v *VersionedBlindedBeaconBlock) StateRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.StateRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.StateRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.StateRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -257,6 +284,7 @@ func (v *VersionedBlindedBeaconBlock) TransactionsRoot() (phase0.Root, error) { if v.Bellatrix.Body.ExecutionPayloadHeader == nil { return phase0.Root{}, errors.New("no bellatrix block body execution payload header") } + return v.Bellatrix.Body.ExecutionPayloadHeader.TransactionsRoot, nil case spec.DataVersionCapella: if v.Capella == nil { @@ -268,6 +296,7 @@ func (v *VersionedBlindedBeaconBlock) TransactionsRoot() (phase0.Root, error) { if v.Capella.Body.ExecutionPayloadHeader == nil { return phase0.Root{}, errors.New("no capella block body execution payload header") } + return v.Capella.Body.ExecutionPayloadHeader.TransactionsRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil { @@ -279,6 +308,7 @@ func (v *VersionedBlindedBeaconBlock) TransactionsRoot() (phase0.Root, error) { if v.Deneb.Body.ExecutionPayloadHeader == nil { return phase0.Root{}, errors.New("no deneb block body execution payload header") } + return v.Deneb.Body.ExecutionPayloadHeader.TransactionsRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -298,6 +328,7 @@ func (v *VersionedBlindedBeaconBlock) FeeRecipient() (bellatrix.ExecutionAddress if v.Bellatrix.Body.ExecutionPayloadHeader == nil { return bellatrix.ExecutionAddress{}, errors.New("no bellatrix block body execution payload header") } + return v.Bellatrix.Body.ExecutionPayloadHeader.FeeRecipient, nil case spec.DataVersionCapella: if v.Capella == nil { @@ -309,6 +340,7 @@ func (v *VersionedBlindedBeaconBlock) FeeRecipient() (bellatrix.ExecutionAddress if v.Capella.Body.ExecutionPayloadHeader == nil { return bellatrix.ExecutionAddress{}, errors.New("no capella block body execution payload header") } + return v.Capella.Body.ExecutionPayloadHeader.FeeRecipient, nil case spec.DataVersionDeneb: if v.Deneb == nil { @@ -320,6 +352,7 @@ func (v *VersionedBlindedBeaconBlock) FeeRecipient() (bellatrix.ExecutionAddress if v.Deneb.Body.ExecutionPayloadHeader == nil { return bellatrix.ExecutionAddress{}, errors.New("no deneb block body execution payload header") } + return v.Deneb.Body.ExecutionPayloadHeader.FeeRecipient, nil default: return bellatrix.ExecutionAddress{}, errors.New("unsupported version") @@ -339,6 +372,7 @@ func (v *VersionedBlindedBeaconBlock) Timestamp() (uint64, error) { if v.Bellatrix.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no bellatrix block body execution payload header") } + return v.Bellatrix.Body.ExecutionPayloadHeader.Timestamp, nil case spec.DataVersionCapella: if v.Capella == nil { @@ -350,6 +384,7 @@ func (v *VersionedBlindedBeaconBlock) Timestamp() (uint64, error) { if v.Capella.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no capella block body execution payload header") } + return v.Capella.Body.ExecutionPayloadHeader.Timestamp, nil case spec.DataVersionDeneb: if v.Deneb == nil { @@ -361,6 +396,7 @@ func (v *VersionedBlindedBeaconBlock) Timestamp() (uint64, error) { if v.Deneb.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no deneb block body execution payload header") } + return v.Deneb.Body.ExecutionPayloadHeader.Timestamp, nil default: return 0, errors.New("unsupported version") @@ -374,16 +410,19 @@ func (v *VersionedBlindedBeaconBlock) String() string { if v.Bellatrix == nil { return "" } + return v.Bellatrix.String() case spec.DataVersionCapella: if v.Capella == nil { return "" } + return v.Capella.String() case spec.DataVersionDeneb: if v.Deneb == nil { return "" } + return v.Deneb.String() default: return "unknown version" diff --git a/api/versionedblindedblockrequest.go b/api/versionedblindedblockrequest.go index 244b21ca..5d03d3f7 100644 --- a/api/versionedblindedblockrequest.go +++ b/api/versionedblindedblockrequest.go @@ -38,16 +38,19 @@ func (v *VersionedBlindedBlockRequest) Slot() (phase0.Slot, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Slot, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.Slot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil { return 0, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Slot, nil default: return 0, errors.New("unsupported version") @@ -61,16 +64,19 @@ func (v *VersionedBlindedBlockRequest) Attestations() ([]*phase0.Attestation, er if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.Attestations, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.Attestations, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil || v.Deneb.SignedBlindedBlock.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.Attestations, nil default: return nil, errors.New("unsupported version") @@ -84,16 +90,19 @@ func (v *VersionedBlindedBlockRequest) Root() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -107,16 +116,19 @@ func (v *VersionedBlindedBlockRequest) BodyRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.Body.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -130,16 +142,19 @@ func (v *VersionedBlindedBlockRequest) ParentRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.ParentRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.ParentRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.ParentRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -153,16 +168,19 @@ func (v *VersionedBlindedBlockRequest) StateRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.StateRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.StateRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.StateRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -176,16 +194,19 @@ func (v *VersionedBlindedBlockRequest) AttesterSlashings() ([]*phase0.AttesterSl if v.Bellatrix == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.AttesterSlashings, nil case spec.DataVersionCapella: if v.Capella == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.AttesterSlashings, nil case spec.DataVersionDeneb: if v.Deneb == nil { return nil, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.AttesterSlashings, nil default: return nil, errors.New("unknown version") @@ -199,16 +220,19 @@ func (v *VersionedBlindedBlockRequest) ProposerSlashings() ([]*phase0.ProposerSl if v.Bellatrix == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ProposerSlashings, nil case spec.DataVersionCapella: if v.Capella == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.ProposerSlashings, nil case spec.DataVersionDeneb: if v.Deneb == nil { return nil, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.ProposerSlashings, nil default: return nil, errors.New("unknown version") @@ -222,16 +246,19 @@ func (v *VersionedBlindedBlockRequest) ProposerIndex() (phase0.ValidatorIndex, e if v.Bellatrix == nil || v.Bellatrix.Message == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.ProposerIndex, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.ProposerIndex, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock.Message == nil { return 0, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.ProposerIndex, nil default: return 0, errors.New("unknown version") @@ -245,16 +272,19 @@ func (v *VersionedBlindedBlockRequest) ExecutionBlockHash() (phase0.Hash32, erro if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayloadHeader == nil { return phase0.Hash32{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ExecutionPayloadHeader.BlockHash, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayloadHeader == nil { return phase0.Hash32{}, errors.New("no capella block") } + return v.Capella.Message.Body.ExecutionPayloadHeader.BlockHash, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock.Message == nil || v.Deneb.SignedBlindedBlock.Message.Body == nil || v.Deneb.SignedBlindedBlock.Message.Body.ExecutionPayloadHeader == nil { return phase0.Hash32{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.ExecutionPayloadHeader.BlockHash, nil default: return phase0.Hash32{}, errors.New("unknown version") @@ -268,39 +298,45 @@ func (v *VersionedBlindedBlockRequest) ExecutionBlockNumber() (uint64, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ExecutionPayloadHeader.BlockNumber, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.Body.ExecutionPayloadHeader.BlockNumber, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock.Message == nil || v.Deneb.SignedBlindedBlock.Message.Body == nil || v.Deneb.SignedBlindedBlock.Message.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.ExecutionPayloadHeader.BlockNumber, nil default: return 0, errors.New("unknown version") } } -// Signature returns the signature of the beacon block. +// BeaconBlockSignature returns the signature of the beacon block. func (v *VersionedBlindedBlockRequest) BeaconBlockSignature() (phase0.BLSSignature, error) { switch v.Version { case spec.DataVersionBellatrix: if v.Bellatrix == nil { return phase0.BLSSignature{}, errors.New("no bellatrix block") } + return v.Bellatrix.Signature, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.BLSSignature{}, errors.New("no capella block") } + return v.Capella.Signature, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil { return phase0.BLSSignature{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Signature, nil default: return phase0.BLSSignature{}, errors.New("unknown version") diff --git a/api/versionedblindedproposal.go b/api/versionedblindedproposal.go index 4458637e..be9a22f4 100644 --- a/api/versionedblindedproposal.go +++ b/api/versionedblindedproposal.go @@ -44,16 +44,19 @@ func (v *VersionedBlindedProposal) Slot() (phase0.Slot, error) { if v.Bellatrix == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Slot, nil case spec.DataVersionCapella: if v.Capella == nil { return 0, errors.New("no capella block") } + return v.Capella.Slot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.BlindedBlock == nil { return 0, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.Slot, nil default: return 0, errors.New("unsupported version") @@ -67,16 +70,19 @@ func (v *VersionedBlindedProposal) ProposerIndex() (phase0.ValidatorIndex, error if v.Bellatrix == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.ProposerIndex, nil case spec.DataVersionCapella: if v.Capella == nil { return 0, errors.New("no capella block") } + return v.Capella.ProposerIndex, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.BlindedBlock == nil { return 0, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.ProposerIndex, nil default: return 0, errors.New("unknown version") @@ -90,16 +96,19 @@ func (v *VersionedBlindedProposal) RandaoReveal() (phase0.BLSSignature, error) { if v.Bellatrix == nil || v.Bellatrix.Body == nil { return phase0.BLSSignature{}, errors.New("no bellatrix block") } + return v.Bellatrix.Body.RANDAOReveal, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return phase0.BLSSignature{}, errors.New("no capella block") } + return v.Capella.Body.RANDAOReveal, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.BlindedBlock == nil || v.Deneb.BlindedBlock.Body == nil { return phase0.BLSSignature{}, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.Body.RANDAOReveal, nil default: return phase0.BLSSignature{}, errors.New("unsupported version") @@ -113,16 +122,19 @@ func (v *VersionedBlindedProposal) Graffiti() ([32]byte, error) { if v.Bellatrix == nil || v.Bellatrix.Body == nil { return [32]byte{}, errors.New("no bellatrix block") } + return v.Bellatrix.Body.Graffiti, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return [32]byte{}, errors.New("no capella block") } + return v.Capella.Body.Graffiti, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.BlindedBlock == nil || v.Deneb.BlindedBlock.Body == nil { return [32]byte{}, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.Body.Graffiti, nil default: return [32]byte{}, errors.New("unsupported version") @@ -136,16 +148,19 @@ func (v *VersionedBlindedProposal) Attestations() ([]*phase0.Attestation, error) if v.Bellatrix == nil || v.Bellatrix.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Body.Attestations, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Body.Attestations, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.BlindedBlock == nil || v.Deneb.BlindedBlock.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.Body.Attestations, nil default: return nil, errors.New("unsupported version") @@ -159,16 +174,19 @@ func (v *VersionedBlindedProposal) Root() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.BlindedBlock == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -182,16 +200,19 @@ func (v *VersionedBlindedProposal) BodyRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Body.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Body.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.BlindedBlock == nil || v.Deneb.BlindedBlock.Body == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.Body.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -205,16 +226,19 @@ func (v *VersionedBlindedProposal) ParentRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.ParentRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.ParentRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.BlindedBlock == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.ParentRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -228,16 +252,19 @@ func (v *VersionedBlindedProposal) StateRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.StateRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.StateRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.BlindedBlock == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.StateRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -257,6 +284,7 @@ func (v *VersionedBlindedProposal) TransactionsRoot() (phase0.Root, error) { if v.Bellatrix.Body.ExecutionPayloadHeader == nil { return phase0.Root{}, errors.New("no bellatrix block body execution payload header") } + return v.Bellatrix.Body.ExecutionPayloadHeader.TransactionsRoot, nil case spec.DataVersionCapella: if v.Capella == nil { @@ -268,6 +296,7 @@ func (v *VersionedBlindedProposal) TransactionsRoot() (phase0.Root, error) { if v.Capella.Body.ExecutionPayloadHeader == nil { return phase0.Root{}, errors.New("no capella block body execution payload header") } + return v.Capella.Body.ExecutionPayloadHeader.TransactionsRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil || @@ -276,6 +305,7 @@ func (v *VersionedBlindedProposal) TransactionsRoot() (phase0.Root, error) { v.Deneb.BlindedBlock.Body.ExecutionPayloadHeader == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.Body.ExecutionPayloadHeader.TransactionsRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -295,6 +325,7 @@ func (v *VersionedBlindedProposal) FeeRecipient() (bellatrix.ExecutionAddress, e if v.Bellatrix.Body.ExecutionPayloadHeader == nil { return bellatrix.ExecutionAddress{}, errors.New("no bellatrix block body execution payload header") } + return v.Bellatrix.Body.ExecutionPayloadHeader.FeeRecipient, nil case spec.DataVersionCapella: if v.Capella == nil { @@ -306,6 +337,7 @@ func (v *VersionedBlindedProposal) FeeRecipient() (bellatrix.ExecutionAddress, e if v.Capella.Body.ExecutionPayloadHeader == nil { return bellatrix.ExecutionAddress{}, errors.New("no capella block body execution payload header") } + return v.Capella.Body.ExecutionPayloadHeader.FeeRecipient, nil case spec.DataVersionDeneb: if v.Deneb == nil || @@ -314,6 +346,7 @@ func (v *VersionedBlindedProposal) FeeRecipient() (bellatrix.ExecutionAddress, e v.Deneb.BlindedBlock.Body.ExecutionPayloadHeader == nil { return bellatrix.ExecutionAddress{}, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.Body.ExecutionPayloadHeader.FeeRecipient, nil default: return bellatrix.ExecutionAddress{}, errors.New("unsupported version") @@ -333,6 +366,7 @@ func (v *VersionedBlindedProposal) Timestamp() (uint64, error) { if v.Bellatrix.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no bellatrix block body execution payload header") } + return v.Bellatrix.Body.ExecutionPayloadHeader.Timestamp, nil case spec.DataVersionCapella: if v.Capella == nil { @@ -344,6 +378,7 @@ func (v *VersionedBlindedProposal) Timestamp() (uint64, error) { if v.Capella.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no capella block body execution payload header") } + return v.Capella.Body.ExecutionPayloadHeader.Timestamp, nil case spec.DataVersionDeneb: if v.Deneb == nil || @@ -352,6 +387,7 @@ func (v *VersionedBlindedProposal) Timestamp() (uint64, error) { v.Deneb.BlindedBlock.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no deneb block") } + return v.Deneb.BlindedBlock.Body.ExecutionPayloadHeader.Timestamp, nil default: return 0, errors.New("unsupported version") @@ -365,16 +401,19 @@ func (v *VersionedBlindedProposal) String() string { if v.Bellatrix == nil { return "" } + return v.Bellatrix.String() case spec.DataVersionCapella: if v.Capella == nil { return "" } + return v.Capella.String() case spec.DataVersionDeneb: if v.Deneb == nil { return "" } + return v.Deneb.String() default: return "unknown version" diff --git a/api/versionedblockrequest.go b/api/versionedblockrequest.go index 24c28db8..1e9aa6d5 100644 --- a/api/versionedblockrequest.go +++ b/api/versionedblockrequest.go @@ -39,16 +39,19 @@ func (v *VersionedBlockRequest) Slot() (phase0.Slot, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Slot, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.Slot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlock == nil || v.Deneb.SignedBlock.Message == nil { return 0, errors.New("no denb block") } + return v.Deneb.SignedBlock.Message.Slot, nil default: return 0, errors.New("unknown version") @@ -62,16 +65,19 @@ func (v *VersionedBlockRequest) ExecutionBlockHash() (phase0.Hash32, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayload == nil { return phase0.Hash32{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ExecutionPayload.BlockHash, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayload == nil { return phase0.Hash32{}, errors.New("no capella block") } + return v.Capella.Message.Body.ExecutionPayload.BlockHash, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlock == nil || v.Deneb.SignedBlock.Message == nil || v.Deneb.SignedBlock.Message.Body == nil || v.Deneb.SignedBlock.Message.Body.ExecutionPayload == nil { return phase0.Hash32{}, errors.New("no denb block") } + return v.Deneb.SignedBlock.Message.Body.ExecutionPayload.BlockHash, nil default: return phase0.Hash32{}, errors.New("unknown version") @@ -85,16 +91,19 @@ func (v *VersionedBlockRequest) Attestations() ([]*phase0.Attestation, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.Attestations, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.Attestations, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlock == nil || v.Deneb.SignedBlock.Message == nil || v.Deneb.SignedBlock.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.SignedBlock.Message.Body.Attestations, nil default: return nil, errors.New("unknown version") @@ -108,16 +117,19 @@ func (v *VersionedBlockRequest) Root() (phase0.Root, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlock == nil || v.Deneb.SignedBlock.Message == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlock.Message.HashTreeRoot() default: return phase0.Root{}, errors.New("unknown version") @@ -131,16 +143,19 @@ func (v *VersionedBlockRequest) BodyRoot() (phase0.Root, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.Body.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlock == nil || v.Deneb.SignedBlock.Message == nil || v.Deneb.SignedBlock.Message.Body == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlock.Message.Body.HashTreeRoot() default: return phase0.Root{}, errors.New("unknown version") @@ -154,16 +169,19 @@ func (v *VersionedBlockRequest) ParentRoot() (phase0.Root, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.ParentRoot, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.ParentRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlock == nil || v.Deneb.SignedBlock.Message == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlock.Message.ParentRoot, nil default: return phase0.Root{}, errors.New("unknown version") @@ -177,16 +195,19 @@ func (v *VersionedBlockRequest) StateRoot() (phase0.Root, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.StateRoot, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.StateRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlock == nil || v.Deneb.SignedBlock.Message == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlock.Message.StateRoot, nil default: return phase0.Root{}, errors.New("unknown version") @@ -200,16 +221,19 @@ func (v *VersionedBlockRequest) AttesterSlashings() ([]*phase0.AttesterSlashing, if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.AttesterSlashings, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.AttesterSlashings, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlock == nil || v.Deneb.SignedBlock.Message == nil || v.Deneb.SignedBlock.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.SignedBlock.Message.Body.AttesterSlashings, nil default: return nil, errors.New("unknown version") @@ -223,16 +247,19 @@ func (v *VersionedBlockRequest) ProposerSlashings() ([]*phase0.ProposerSlashing, if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ProposerSlashings, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.ProposerSlashings, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlock == nil || v.Deneb.SignedBlock.Message == nil || v.Deneb.SignedBlock.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.SignedBlock.Message.Body.ProposerSlashings, nil default: return nil, errors.New("unknown version") @@ -246,16 +273,19 @@ func (v *VersionedBlockRequest) SyncAggregate() (*altair.SyncAggregate, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.SyncAggregate, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.SyncAggregate, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlock == nil || v.Deneb.SignedBlock.Message == nil || v.Deneb.SignedBlock.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.SignedBlock.Message.Body.SyncAggregate, nil default: return nil, errors.New("unknown version") @@ -269,16 +299,19 @@ func (v *VersionedBlockRequest) String() string { if v.Bellatrix == nil { return "" } + return v.Bellatrix.String() case spec.DataVersionCapella: if v.Capella == nil { return "" } + return v.Capella.String() case spec.DataVersionDeneb: if v.Deneb == nil { return "" } + return v.Deneb.String() default: return "unsupported version" diff --git a/api/versionedproposal.go b/api/versionedproposal.go index 492a2530..76346ea6 100644 --- a/api/versionedproposal.go +++ b/api/versionedproposal.go @@ -51,16 +51,19 @@ func (v *VersionedProposal) Slot() (phase0.Slot, error) { if v.Bellatrix == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Slot, nil case spec.DataVersionCapella: if v.Capella == nil { return 0, errors.New("no capella block") } + return v.Capella.Slot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Block == nil { return 0, errors.New("no deneb block") } + return v.Deneb.Block.Slot, nil default: return 0, errors.New("unsupported version") @@ -74,16 +77,19 @@ func (v *VersionedProposal) ProposerIndex() (phase0.ValidatorIndex, error) { if v.Bellatrix == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.ProposerIndex, nil case spec.DataVersionCapella: if v.Capella == nil { return 0, errors.New("no capella block") } + return v.Capella.ProposerIndex, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Block == nil { return 0, errors.New("no deneb block") } + return v.Deneb.Block.ProposerIndex, nil default: return 0, errors.New("unknown version") @@ -97,16 +103,19 @@ func (v *VersionedProposal) RandaoReveal() (phase0.BLSSignature, error) { if v.Bellatrix == nil || v.Bellatrix.Body == nil { return phase0.BLSSignature{}, errors.New("no bellatrix block") } + return v.Bellatrix.Body.RANDAOReveal, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return phase0.BLSSignature{}, errors.New("no capella block") } + return v.Capella.Body.RANDAOReveal, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Block == nil || v.Deneb.Block.Body == nil { return phase0.BLSSignature{}, errors.New("no deneb block") } + return v.Deneb.Block.Body.RANDAOReveal, nil default: return phase0.BLSSignature{}, errors.New("unsupported version") @@ -120,16 +129,19 @@ func (v *VersionedProposal) Graffiti() ([32]byte, error) { if v.Bellatrix == nil || v.Bellatrix.Body == nil { return [32]byte{}, errors.New("no bellatrix block") } + return v.Bellatrix.Body.Graffiti, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return [32]byte{}, errors.New("no capella block") } + return v.Capella.Body.Graffiti, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Block == nil || v.Deneb.Block.Body == nil { return [32]byte{}, errors.New("no deneb block") } + return v.Deneb.Block.Body.Graffiti, nil default: return [32]byte{}, errors.New("unsupported version") @@ -143,16 +155,19 @@ func (v *VersionedProposal) Attestations() ([]*phase0.Attestation, error) { if v.Bellatrix == nil || v.Bellatrix.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Body.Attestations, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Body.Attestations, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Block == nil || v.Deneb.Block.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Block.Body.Attestations, nil default: return nil, errors.New("unsupported version") @@ -166,16 +181,19 @@ func (v *VersionedProposal) Root() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Block == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Block.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -189,16 +207,19 @@ func (v *VersionedProposal) BodyRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Body.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Body.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Block == nil || v.Deneb.Block.Body == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Block.Body.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -212,16 +233,19 @@ func (v *VersionedProposal) ParentRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.ParentRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.ParentRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Block == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Block.ParentRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -235,16 +259,19 @@ func (v *VersionedProposal) StateRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.StateRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.StateRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Block == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Block.StateRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -264,6 +291,7 @@ func (v *VersionedProposal) Transactions() ([]bellatrix.Transaction, error) { if v.Bellatrix.Body.ExecutionPayload == nil { return nil, errors.New("no bellatrix block body execution payload header") } + return v.Bellatrix.Body.ExecutionPayload.Transactions, nil case spec.DataVersionCapella: if v.Capella == nil { @@ -275,6 +303,7 @@ func (v *VersionedProposal) Transactions() ([]bellatrix.Transaction, error) { if v.Capella.Body.ExecutionPayload == nil { return nil, errors.New("no capella block body execution payload header") } + return v.Capella.Body.ExecutionPayload.Transactions, nil case spec.DataVersionDeneb: if v.Deneb == nil || @@ -283,6 +312,7 @@ func (v *VersionedProposal) Transactions() ([]bellatrix.Transaction, error) { v.Deneb.Block.Body.ExecutionPayload == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Block.Body.ExecutionPayload.Transactions, nil default: return nil, errors.New("unsupported version") @@ -302,6 +332,7 @@ func (v *VersionedProposal) FeeRecipient() (bellatrix.ExecutionAddress, error) { if v.Bellatrix.Body.ExecutionPayload == nil { return bellatrix.ExecutionAddress{}, errors.New("no bellatrix block body execution payload header") } + return v.Bellatrix.Body.ExecutionPayload.FeeRecipient, nil case spec.DataVersionCapella: if v.Capella == nil { @@ -313,6 +344,7 @@ func (v *VersionedProposal) FeeRecipient() (bellatrix.ExecutionAddress, error) { if v.Capella.Body.ExecutionPayload == nil { return bellatrix.ExecutionAddress{}, errors.New("no capella block body execution payload header") } + return v.Capella.Body.ExecutionPayload.FeeRecipient, nil case spec.DataVersionDeneb: if v.Deneb == nil || @@ -321,6 +353,7 @@ func (v *VersionedProposal) FeeRecipient() (bellatrix.ExecutionAddress, error) { v.Deneb.Block.Body.ExecutionPayload == nil { return bellatrix.ExecutionAddress{}, errors.New("no deneb block") } + return v.Deneb.Block.Body.ExecutionPayload.FeeRecipient, nil default: return bellatrix.ExecutionAddress{}, errors.New("unsupported version") @@ -340,6 +373,7 @@ func (v *VersionedProposal) Timestamp() (uint64, error) { if v.Bellatrix.Body.ExecutionPayload == nil { return 0, errors.New("no bellatrix block body execution payload header") } + return v.Bellatrix.Body.ExecutionPayload.Timestamp, nil case spec.DataVersionCapella: if v.Capella == nil { @@ -351,6 +385,7 @@ func (v *VersionedProposal) Timestamp() (uint64, error) { if v.Capella.Body.ExecutionPayload == nil { return 0, errors.New("no capella block body execution payload header") } + return v.Capella.Body.ExecutionPayload.Timestamp, nil case spec.DataVersionDeneb: if v.Deneb == nil || @@ -359,6 +394,7 @@ func (v *VersionedProposal) Timestamp() (uint64, error) { v.Deneb.Block.Body.ExecutionPayload == nil { return 0, errors.New("no deneb block") } + return v.Deneb.Block.Body.ExecutionPayload.Timestamp, nil default: return 0, errors.New("unsupported version") @@ -380,6 +416,7 @@ func (v *VersionedProposal) BlobSidecars() ([]*deneb.BlobSidecar, error) { if v.Deneb == nil { return nil, errors.New("no deneb block") } + return v.Deneb.BlobSidecars, nil default: return nil, errors.New("unknown version") @@ -393,16 +430,19 @@ func (v *VersionedProposal) String() string { if v.Bellatrix == nil { return "" } + return v.Bellatrix.String() case spec.DataVersionCapella: if v.Capella == nil { return "" } + return v.Capella.String() case spec.DataVersionDeneb: if v.Deneb == nil { return "" } + return v.Deneb.String() default: return "unknown version" diff --git a/api/versionedsignedblindedbeaconblock.go b/api/versionedsignedblindedbeaconblock.go index 3ffe788a..025db798 100644 --- a/api/versionedsignedblindedbeaconblock.go +++ b/api/versionedsignedblindedbeaconblock.go @@ -38,16 +38,19 @@ func (v *VersionedSignedBlindedBeaconBlock) Slot() (phase0.Slot, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Slot, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.Slot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil { return 0, errors.New("no deneb block") } + return v.Deneb.Message.Slot, nil default: return 0, errors.New("unsupported version") @@ -61,16 +64,19 @@ func (v *VersionedSignedBlindedBeaconBlock) Attestations() ([]*phase0.Attestatio if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.Attestations, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.Attestations, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.Attestations, nil default: return nil, errors.New("unsupported version") @@ -84,16 +90,19 @@ func (v *VersionedSignedBlindedBeaconBlock) Root() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Message.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -107,16 +116,19 @@ func (v *VersionedSignedBlindedBeaconBlock) BodyRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.Body.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Message.Body.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -130,16 +142,19 @@ func (v *VersionedSignedBlindedBeaconBlock) ParentRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.ParentRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.ParentRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Message.ParentRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -153,16 +168,19 @@ func (v *VersionedSignedBlindedBeaconBlock) StateRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.StateRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.StateRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Message.StateRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -176,16 +194,19 @@ func (v *VersionedSignedBlindedBeaconBlock) AttesterSlashings() ([]*phase0.Attes if v.Bellatrix == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.AttesterSlashings, nil case spec.DataVersionCapella: if v.Capella == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.AttesterSlashings, nil case spec.DataVersionDeneb: if v.Deneb == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.AttesterSlashings, nil default: return nil, errors.New("unknown version") @@ -199,16 +220,19 @@ func (v *VersionedSignedBlindedBeaconBlock) ProposerSlashings() ([]*phase0.Propo if v.Bellatrix == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ProposerSlashings, nil case spec.DataVersionCapella: if v.Capella == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.ProposerSlashings, nil case spec.DataVersionDeneb: if v.Deneb == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.ProposerSlashings, nil default: return nil, errors.New("unknown version") @@ -222,16 +246,19 @@ func (v *VersionedSignedBlindedBeaconBlock) ProposerIndex() (phase0.ValidatorInd if v.Bellatrix == nil || v.Bellatrix.Message == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.ProposerIndex, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.ProposerIndex, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil { return 0, errors.New("no deneb block") } + return v.Deneb.Message.ProposerIndex, nil default: return 0, errors.New("unknown version") @@ -245,16 +272,19 @@ func (v *VersionedSignedBlindedBeaconBlock) ExecutionBlockHash() (phase0.Hash32, if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayloadHeader == nil { return phase0.Hash32{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ExecutionPayloadHeader.BlockHash, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayloadHeader == nil { return phase0.Hash32{}, errors.New("no capella block") } + return v.Capella.Message.Body.ExecutionPayloadHeader.BlockHash, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil || v.Deneb.Message.Body.ExecutionPayloadHeader == nil { return phase0.Hash32{}, errors.New("no deneb block") } + return v.Deneb.Message.Body.ExecutionPayloadHeader.BlockHash, nil default: return phase0.Hash32{}, errors.New("unknown version") @@ -268,16 +298,19 @@ func (v *VersionedSignedBlindedBeaconBlock) ExecutionBlockNumber() (uint64, erro if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ExecutionPayloadHeader.BlockNumber, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.Body.ExecutionPayloadHeader.BlockNumber, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil || v.Deneb.Message.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no deneb block") } + return v.Deneb.Message.Body.ExecutionPayloadHeader.BlockNumber, nil default: return 0, errors.New("unknown version") @@ -291,16 +324,19 @@ func (v *VersionedSignedBlindedBeaconBlock) Signature() (phase0.BLSSignature, er if v.Bellatrix == nil { return phase0.BLSSignature{}, errors.New("no bellatrix block") } + return v.Bellatrix.Signature, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.BLSSignature{}, errors.New("no capella block") } + return v.Capella.Signature, nil case spec.DataVersionDeneb: if v.Deneb == nil { return phase0.BLSSignature{}, errors.New("no deneb block") } + return v.Deneb.Signature, nil default: return phase0.BLSSignature{}, errors.New("unknown version") diff --git a/api/versionedsignedblindedproposal.go b/api/versionedsignedblindedproposal.go index c336cd21..90ed8f77 100644 --- a/api/versionedsignedblindedproposal.go +++ b/api/versionedsignedblindedproposal.go @@ -38,16 +38,19 @@ func (v *VersionedSignedBlindedProposal) Slot() (phase0.Slot, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Slot, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.Slot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil { return 0, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Slot, nil default: return 0, errors.New("unsupported version") @@ -61,16 +64,19 @@ func (v *VersionedSignedBlindedProposal) Attestations() ([]*phase0.Attestation, if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.Attestations, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.Attestations, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil || v.Deneb.SignedBlindedBlock.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.Attestations, nil default: return nil, errors.New("unsupported version") @@ -84,16 +90,19 @@ func (v *VersionedSignedBlindedProposal) Root() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -107,16 +116,19 @@ func (v *VersionedSignedBlindedProposal) BodyRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.HashTreeRoot() case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.Body.HashTreeRoot() case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil || v.Deneb.SignedBlindedBlock.Message.Body == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") @@ -130,16 +142,19 @@ func (v *VersionedSignedBlindedProposal) ParentRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.ParentRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.ParentRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.ParentRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -153,16 +168,19 @@ func (v *VersionedSignedBlindedProposal) StateRoot() (phase0.Root, error) { if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.StateRoot, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.StateRoot, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.StateRoot, nil default: return phase0.Root{}, errors.New("unsupported version") @@ -176,16 +194,19 @@ func (v *VersionedSignedBlindedProposal) AttesterSlashings() ([]*phase0.Attester if v.Bellatrix == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.AttesterSlashings, nil case spec.DataVersionCapella: if v.Capella == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.AttesterSlashings, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil || v.Deneb.SignedBlindedBlock.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.AttesterSlashings, nil default: return nil, errors.New("unknown version") @@ -199,16 +220,19 @@ func (v *VersionedSignedBlindedProposal) ProposerSlashings() ([]*phase0.Proposer if v.Bellatrix == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ProposerSlashings, nil case spec.DataVersionCapella: if v.Capella == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.ProposerSlashings, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil || v.Deneb.SignedBlindedBlock.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.ProposerSlashings, nil default: return nil, errors.New("unknown version") @@ -222,16 +246,19 @@ func (v *VersionedSignedBlindedProposal) ProposerIndex() (phase0.ValidatorIndex, if v.Bellatrix == nil || v.Bellatrix.Message == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.ProposerIndex, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.ProposerIndex, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil { return 0, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.ProposerIndex, nil default: return 0, errors.New("unknown version") @@ -245,16 +272,19 @@ func (v *VersionedSignedBlindedProposal) ExecutionBlockHash() (phase0.Hash32, er if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayloadHeader == nil { return phase0.Hash32{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ExecutionPayloadHeader.BlockHash, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayloadHeader == nil { return phase0.Hash32{}, errors.New("no capella block") } + return v.Capella.Message.Body.ExecutionPayloadHeader.BlockHash, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil || v.Deneb.SignedBlindedBlock.Message.Body == nil || v.Deneb.SignedBlindedBlock.Message.Body.ExecutionPayloadHeader == nil { return phase0.Hash32{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.ExecutionPayloadHeader.BlockHash, nil default: return phase0.Hash32{}, errors.New("unknown version") @@ -268,16 +298,19 @@ func (v *VersionedSignedBlindedProposal) ExecutionBlockNumber() (uint64, error) if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ExecutionPayloadHeader.BlockNumber, nil case spec.DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.Body.ExecutionPayloadHeader.BlockNumber, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil || v.Deneb.SignedBlindedBlock.Message == nil || v.Deneb.SignedBlindedBlock.Message.Body == nil || v.Deneb.SignedBlindedBlock.Message.Body.ExecutionPayloadHeader == nil { return 0, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Message.Body.ExecutionPayloadHeader.BlockNumber, nil default: return 0, errors.New("unknown version") @@ -291,16 +324,19 @@ func (v *VersionedSignedBlindedProposal) Signature() (phase0.BLSSignature, error if v.Bellatrix == nil { return phase0.BLSSignature{}, errors.New("no bellatrix block") } + return v.Bellatrix.Signature, nil case spec.DataVersionCapella: if v.Capella == nil { return phase0.BLSSignature{}, errors.New("no capella block") } + return v.Capella.Signature, nil case spec.DataVersionDeneb: if v.Deneb == nil || v.Deneb.SignedBlindedBlock == nil { return phase0.BLSSignature{}, errors.New("no deneb block") } + return v.Deneb.SignedBlindedBlock.Signature, nil default: return phase0.BLSSignature{}, errors.New("unknown version") diff --git a/api/versionedsignedproposal.go b/api/versionedsignedproposal.go index c8e2696e..63e18473 100644 --- a/api/versionedsignedproposal.go +++ b/api/versionedsignedproposal.go @@ -39,26 +39,31 @@ func (v *VersionedSignedProposal) String() string { if v.Phase0 == nil { return "" } + return v.Phase0.String() case spec.DataVersionAltair: if v.Altair == nil { return "" } + return v.Altair.String() case spec.DataVersionBellatrix: if v.Bellatrix == nil { return "" } + return v.Bellatrix.String() case spec.DataVersionCapella: if v.Capella == nil { return "" } + return v.Capella.String() case spec.DataVersionDeneb: if v.Deneb == nil { return "" } + return v.Deneb.String() default: return "unsupported version" diff --git a/api/versionedsignedvalidatorregistration.go b/api/versionedsignedvalidatorregistration.go index 497ba12c..0133c10b 100644 --- a/api/versionedsignedvalidatorregistration.go +++ b/api/versionedsignedvalidatorregistration.go @@ -36,6 +36,7 @@ func (v *VersionedSignedValidatorRegistration) FeeRecipient() (bellatrix.Executi if v.V1 == nil { return bellatrix.ExecutionAddress{}, errors.New("no validator registration") } + return v.V1.Message.FeeRecipient, nil default: return bellatrix.ExecutionAddress{}, errors.New("unsupported version") @@ -49,6 +50,7 @@ func (v *VersionedSignedValidatorRegistration) GasLimit() (uint64, error) { if v.V1 == nil { return 0, errors.New("no validator registration") } + return v.V1.Message.GasLimit, nil default: return 0, errors.New("unsupported version") @@ -62,6 +64,7 @@ func (v *VersionedSignedValidatorRegistration) Timestamp() (time.Time, error) { if v.V1 == nil { return time.Time{}, errors.New("no validator registration") } + return v.V1.Message.Timestamp, nil default: return time.Time{}, errors.New("unsupported version") @@ -75,6 +78,7 @@ func (v *VersionedSignedValidatorRegistration) PubKey() (phase0.BLSPubKey, error if v.V1 == nil { return phase0.BLSPubKey{}, errors.New("no validator registration") } + return v.V1.Message.Pubkey, nil default: return phase0.BLSPubKey{}, errors.New("unsupported version") @@ -88,6 +92,7 @@ func (v *VersionedSignedValidatorRegistration) Root() (phase0.Root, error) { if v.V1 == nil { return phase0.Root{}, errors.New("no V1 registration") } + return v.V1.Message.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") diff --git a/api/versionedvalidatorregistration.go b/api/versionedvalidatorregistration.go index e6d6d07f..f70461ff 100644 --- a/api/versionedvalidatorregistration.go +++ b/api/versionedvalidatorregistration.go @@ -41,6 +41,7 @@ func (v *VersionedValidatorRegistration) FeeRecipient() (bellatrix.ExecutionAddr if v.V1 == nil { return bellatrix.ExecutionAddress{}, errors.New("no validator registration") } + return v.V1.FeeRecipient, nil default: return bellatrix.ExecutionAddress{}, errors.New("unsupported version") @@ -54,6 +55,7 @@ func (v *VersionedValidatorRegistration) GasLimit() (uint64, error) { if v.V1 == nil { return 0, errors.New("no validator registration") } + return v.V1.GasLimit, nil default: return 0, errors.New("unsupported version") @@ -67,6 +69,7 @@ func (v *VersionedValidatorRegistration) Timestamp() (time.Time, error) { if v.V1 == nil { return time.Time{}, errors.New("no validator registration") } + return v.V1.Timestamp, nil default: return time.Time{}, errors.New("unsupported version") @@ -80,6 +83,7 @@ func (v *VersionedValidatorRegistration) PubKey() (phase0.BLSPubKey, error) { if v.V1 == nil { return phase0.BLSPubKey{}, errors.New("no validator registration") } + return v.V1.Pubkey, nil default: return phase0.BLSPubKey{}, errors.New("unsupported version") @@ -93,6 +97,7 @@ func (v *VersionedValidatorRegistration) Root() (phase0.Root, error) { if v.V1 == nil { return phase0.Root{}, errors.New("no V1 registration") } + return v.V1.HashTreeRoot() default: return phase0.Root{}, errors.New("unsupported version") diff --git a/auto/service.go b/auto/service.go index 92cabd89..06920648 100644 --- a/auto/service.go +++ b/auto/service.go @@ -60,5 +60,6 @@ func tryHTTP(ctx context.Context, parameters *parameters) (client.Service, error if err != nil { return nil, errors.Wrap(err, "failed when trying to open connection with standard API") } + return client, nil } diff --git a/codecs/json.go b/codecs/json.go index 2c8da374..c7742856 100644 --- a/codecs/json.go +++ b/codecs/json.go @@ -45,6 +45,7 @@ func RawJSON(b any, input []byte) (map[string]json.RawMessage, error) { if tags[i] == "allowempty" { // This can be omitted. emptyAllowed = true + break } } diff --git a/http/contenttype.go b/http/contenttype.go index d7000332..b43b2646 100644 --- a/http/contenttype.go +++ b/http/contenttype.go @@ -55,6 +55,7 @@ func (c *ContentType) UnmarshalJSON(input []byte) error { *c = ContentTypeUnknown err = fmt.Errorf("unrecognised content type %s", string(input)) } + return err } @@ -63,6 +64,7 @@ func (c ContentType) String() string { if int(c) >= len(contentTypeStrings) { return contentTypeStrings[0] } + return contentTypeStrings[c] } diff --git a/http/depositcontract.go b/http/depositcontract.go index 08422cf0..9e275091 100644 --- a/http/depositcontract.go +++ b/http/depositcontract.go @@ -26,6 +26,7 @@ func (s *Service) DepositContract(ctx context.Context) (*api.Response[*apiv1.Dep s.depositContractMutex.RLock() if s.depositContract != nil { defer s.depositContractMutex.RUnlock() + return &api.Response[*apiv1.DepositContract]{ Data: s.depositContract, Metadata: map[string]any{}, diff --git a/http/domain.go b/http/domain.go index 9aba9ce9..4af498d2 100644 --- a/http/domain.go +++ b/http/domain.go @@ -33,7 +33,7 @@ func (s *Service) Domain(ctx context.Context, domainType phase0.DomainType, epoc } // GenesisDomain returns the domain for the given domain type at genesis. -// N.B. this is not always the same as the the domain at epoch 0. It is possible +// N.B. this is not always the same as the domain at epoch 0. It is possible // for a chain's fork schedule to have multiple forks at genesis. In this situation, // GenesisDomain() will return the first, and Domain() will return the last. func (s *Service) GenesisDomain(ctx context.Context, domainType phase0.DomainType) (phase0.Domain, error) { @@ -84,6 +84,7 @@ func (s *Service) domain(ctx context.Context, var domain phase0.Domain copy(domain[:], domainType[:]) copy(domain[4:], root[:]) + return domain, nil } @@ -105,6 +106,7 @@ func (s *Service) forkAtEpoch(ctx context.Context, epoch phase0.Epoch) (*phase0. } currentFork = response.Data[i] } + return currentFork, nil } diff --git a/http/events.go b/http/events.go index 2768a0c2..299cf6b9 100644 --- a/http/events.go +++ b/http/events.go @@ -78,6 +78,7 @@ func (s *Service) Events(ctx context.Context, topics []string, handler client.Ev log.Trace().Msg("Events stream disconnected") case <-ctx.Done(): log.Debug().Msg("Context done") + return } } @@ -92,10 +93,12 @@ func (s *Service) handleEvent(ctx context.Context, msg *sse.Event, handler clien if handler == nil { log.Debug().Msg("No handler supplied; ignoring") + return } if msg == nil { log.Debug().Msg("No message supplied; ignoring") + return } @@ -108,6 +111,7 @@ func (s *Service) handleEvent(ctx context.Context, msg *sse.Event, handler clien err := json.Unmarshal(msg.Data, headEvent) if err != nil { log.Error().Err(err).RawJSON("data", msg.Data).Msg("Failed to parse head event") + return } event.Data = headEvent @@ -116,6 +120,7 @@ func (s *Service) handleEvent(ctx context.Context, msg *sse.Event, handler clien err := json.Unmarshal(msg.Data, blockEvent) if err != nil { log.Error().Err(err).RawJSON("data", msg.Data).Msg("Failed to parse block event") + return } event.Data = blockEvent @@ -124,6 +129,7 @@ func (s *Service) handleEvent(ctx context.Context, msg *sse.Event, handler clien err := json.Unmarshal(msg.Data, attestation) if err != nil { log.Error().Err(err).RawJSON("data", msg.Data).Msg("Failed to parse attestation") + return } event.Data = attestation @@ -132,6 +138,7 @@ func (s *Service) handleEvent(ctx context.Context, msg *sse.Event, handler clien err := json.Unmarshal(msg.Data, voluntaryExit) if err != nil { log.Error().Err(err).RawJSON("data", msg.Data).Msg("Failed to parse voluntary exit") + return } event.Data = voluntaryExit @@ -140,6 +147,7 @@ func (s *Service) handleEvent(ctx context.Context, msg *sse.Event, handler clien err := json.Unmarshal(msg.Data, finalizedCheckpointEvent) if err != nil { log.Error().Err(err).RawJSON("data", msg.Data).Msg("Failed to parse finalized checkpoint event") + return } event.Data = finalizedCheckpointEvent @@ -148,6 +156,7 @@ func (s *Service) handleEvent(ctx context.Context, msg *sse.Event, handler clien err := json.Unmarshal(msg.Data, chainReorgEvent) if err != nil { log.Error().Err(err).RawJSON("data", msg.Data).Msg("Failed to parse chain reorg event") + return } event.Data = chainReorgEvent @@ -156,6 +165,7 @@ func (s *Service) handleEvent(ctx context.Context, msg *sse.Event, handler clien err := json.Unmarshal(msg.Data, contributionAndProofEvent) if err != nil { log.Error().Err(err).RawJSON("data", msg.Data).Msg("Failed to parse contribution and proof event") + return } event.Data = contributionAndProofEvent @@ -164,6 +174,7 @@ func (s *Service) handleEvent(ctx context.Context, msg *sse.Event, handler clien err := json.Unmarshal(msg.Data, payloadAttributesEvent) if err != nil { log.Error().Err(err).RawJSON("data", msg.Data).Msg("Failed to parse payload attributes event") + return } event.Data = payloadAttributesEvent @@ -172,6 +183,7 @@ func (s *Service) handleEvent(ctx context.Context, msg *sse.Event, handler clien return default: log.Warn().Str("topic", string(msg.Event)).Msg("Received message with unhandled topic; ignoring") + return } handler(event) diff --git a/http/forkschedule.go b/http/forkschedule.go index 2b1ec91a..8c1bbf24 100644 --- a/http/forkschedule.go +++ b/http/forkschedule.go @@ -26,6 +26,7 @@ func (s *Service) ForkSchedule(ctx context.Context) (*api.Response[[]*phase0.For s.forkScheduleMutex.RLock() if s.forkSchedule != nil { defer s.forkScheduleMutex.RUnlock() + return &api.Response[[]*phase0.Fork]{ Data: s.forkSchedule, Metadata: make(map[string]any), diff --git a/http/genesis.go b/http/genesis.go index 7580aa4f..1c48f99f 100644 --- a/http/genesis.go +++ b/http/genesis.go @@ -31,6 +31,7 @@ func (s *Service) Genesis(ctx context.Context) (*api.Response[*apiv1.Genesis], e s.genesisMutex.RLock() if s.genesis != nil { defer s.genesisMutex.RUnlock() + return &api.Response[*apiv1.Genesis]{ Data: s.genesis, Metadata: make(map[string]any), diff --git a/http/genesistime.go b/http/genesistime.go index 6cd95011..a9b3af14 100644 --- a/http/genesistime.go +++ b/http/genesistime.go @@ -26,5 +26,6 @@ func (s *Service) GenesisTime(ctx context.Context) (time.Time, error) { if err != nil { return time.Time{}, errors.Wrap(err, "failed to obtain genesis") } + return response.Data.GenesisTime, nil } diff --git a/http/http.go b/http/http.go index 28320713..e7ce5219 100644 --- a/http/http.go +++ b/http/http.go @@ -48,6 +48,7 @@ func (s *Service) get(ctx context.Context, endpoint string) (io.Reader, error) { req, err := http.NewRequestWithContext(opCtx, http.MethodGet, url.String(), nil) if err != nil { cancel() + return nil, errors.Wrap(err, "failed to create GET request") } s.addExtraHeaders(req) @@ -56,6 +57,7 @@ func (s *Service) get(ctx context.Context, endpoint string) (io.Reader, error) { resp, err := s.client.Do(req) if err != nil { cancel() + return nil, errors.Wrap(err, "failed to call GET endpoint") } defer resp.Body.Close() @@ -63,12 +65,14 @@ func (s *Service) get(ctx context.Context, endpoint string) (io.Reader, error) { if resp.StatusCode == http.StatusNotFound { // Nothing found. This is not an error, so we return nil on both counts. cancel() + return nil, nil } data, err := io.ReadAll(resp.Body) if err != nil { cancel() + return nil, errors.Wrap(err, "failed to read GET response") } @@ -76,6 +80,7 @@ func (s *Service) get(ctx context.Context, endpoint string) (io.Reader, error) { if statusFamily != 2 { cancel() log.Trace().Int("status_code", resp.StatusCode).Str("data", string(data)).Msg("GET failed") + return nil, &api.Error{ Method: http.MethodGet, StatusCode: resp.StatusCode, @@ -113,6 +118,7 @@ func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io req, err := http.NewRequestWithContext(opCtx, http.MethodPost, url.String(), body) if err != nil { cancel() + return nil, errors.Wrap(err, "failed to create POST request") } s.addExtraHeaders(req) @@ -125,6 +131,7 @@ func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io resp, err := s.client.Do(req) if err != nil { cancel() + return nil, errors.Wrap(err, "failed to call POST endpoint") } defer resp.Body.Close() @@ -132,6 +139,7 @@ func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io data, err := io.ReadAll(resp.Body) if err != nil { cancel() + return nil, errors.Wrap(err, "failed to read POST response") } @@ -139,6 +147,7 @@ func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io if statusFamily != 2 { cancel() log.Trace().Int("status_code", resp.StatusCode).Str("data", string(data)).Msg("POST failed") + return nil, &api.Error{ Method: http.MethodPost, StatusCode: resp.StatusCode, @@ -186,6 +195,7 @@ func (s *Service) post2(ctx context.Context, req, err := http.NewRequestWithContext(opCtx, http.MethodPost, url.String(), body) if err != nil { cancel() + return nil, errors.Wrap(err, "failed to create POST request") } s.addExtraHeaders(req) @@ -202,6 +212,7 @@ func (s *Service) post2(ctx context.Context, resp, err := s.client.Do(req) if err != nil { cancel() + return nil, errors.Wrap(err, "failed to call POST endpoint") } defer resp.Body.Close() @@ -209,6 +220,7 @@ func (s *Service) post2(ctx context.Context, data, err := io.ReadAll(resp.Body) if err != nil { cancel() + return nil, errors.Wrap(err, "failed to read POST response") } @@ -216,6 +228,7 @@ func (s *Service) post2(ctx context.Context, if statusFamily != 2 { cancel() log.Trace().Int("status_code", resp.StatusCode).Str("data", string(data)).Msg("POST failed") + return nil, &api.Error{ Method: http.MethodPost, StatusCode: resp.StatusCode, @@ -269,6 +282,7 @@ func (s *Service) get2(ctx context.Context, endpoint string) (*httpResponse, err req, err := http.NewRequestWithContext(opCtx, http.MethodGet, url.String(), nil) if err != nil { cancel() + return nil, errors.Wrap(err, "failed to create GET request") } s.addExtraHeaders(req) @@ -284,6 +298,7 @@ func (s *Service) get2(ctx context.Context, endpoint string) (*httpResponse, err resp, err := s.client.Do(req) if err != nil { span.RecordError(errors.New("Request failed")) + return nil, errors.Wrap(err, "failed to call GET endpoint") } defer resp.Body.Close() @@ -298,6 +313,7 @@ func (s *Service) get2(ctx context.Context, endpoint string) (*httpResponse, err // Nothing returned. This is not considered an error. span.AddEvent("Received empty response") log.Trace().Msg("Endpoint returned no content") + return res, nil } @@ -309,6 +325,7 @@ func (s *Service) get2(ctx context.Context, endpoint string) (*httpResponse, err if err != nil { span.RecordError(err) log.Warn().Err(err).Msg("Failed to read body") + return nil, errors.Wrap(err, "failed to read body") } @@ -317,6 +334,7 @@ func (s *Service) get2(ctx context.Context, endpoint string) (*httpResponse, err span.SetStatus(codes.Error, fmt.Sprintf("Status code %d", resp.StatusCode)) trimmedResponse := bytes.ReplaceAll(bytes.ReplaceAll(res.body, []byte{0x0a}, []byte{}), []byte{0x0d}, []byte{}) log.Debug().Int("status_code", resp.StatusCode).RawJSON("response", trimmedResponse).Msg("GET failed") + return nil, &api.Error{ Method: http.MethodGet, StatusCode: resp.StatusCode, @@ -354,6 +372,7 @@ func populateConsensusVersion(res *httpResponse, resp *http.Response) error { return errors.Wrap(err, "no consensus version header and failed to parse response") } res.consensusVersion = metadata.Version + return nil } if len(respConsensusVersions) != 1 { diff --git a/http/nodeversion.go b/http/nodeversion.go index 26340829..025a7afe 100644 --- a/http/nodeversion.go +++ b/http/nodeversion.go @@ -29,6 +29,7 @@ func (s *Service) NodeVersion(ctx context.Context) (*api.Response[string], error s.nodeVersionMutex.RLock() if s.nodeVersion != "" { defer s.nodeVersionMutex.RUnlock() + return &api.Response[string]{ Data: s.nodeVersion, Metadata: make(map[string]any), diff --git a/http/proposal.go b/http/proposal.go index c67cf0af..d713d376 100644 --- a/http/proposal.go +++ b/http/proposal.go @@ -30,8 +30,6 @@ import ( ) // Proposal fetches a potential beacon block for signing. -// -//nolint:gocyclo func (s *Service) Proposal(ctx context.Context, opts *api.ProposalOpts, ) ( diff --git a/http/spec.go b/http/spec.go index a30a944d..a7752d24 100644 --- a/http/spec.go +++ b/http/spec.go @@ -30,6 +30,7 @@ func (s *Service) Spec(ctx context.Context) (*api.Response[map[string]any], erro s.specMutex.RLock() if s.spec != nil { defer s.specMutex.RUnlock() + return &api.Response[map[string]any]{ Data: s.spec, Metadata: make(map[string]any), @@ -67,6 +68,7 @@ func (s *Service) Spec(ctx context.Context) (*api.Response[map[string]any], erro var domainType phase0.DomainType copy(domainType[:], byteVal) config[k] = domainType + continue } } @@ -78,6 +80,7 @@ func (s *Service) Spec(ctx context.Context) (*api.Response[map[string]any], erro var version phase0.Version copy(version[:], byteVal) config[k] = version + continue } } @@ -87,6 +90,7 @@ func (s *Service) Spec(ctx context.Context) (*api.Response[map[string]any], erro byteVal, err := hex.DecodeString(strings.TrimPrefix(v, "0x")) if err == nil { config[k] = byteVal + continue } } @@ -96,6 +100,7 @@ func (s *Service) Spec(ctx context.Context) (*api.Response[map[string]any], erro intVal, err := strconv.ParseInt(v, 10, 64) if err == nil && intVal != 0 { config[k] = time.Unix(intVal, 0) + continue } } @@ -105,6 +110,7 @@ func (s *Service) Spec(ctx context.Context) (*api.Response[map[string]any], erro intVal, err := strconv.ParseUint(v, 10, 64) if err == nil && intVal != 0 { config[k] = time.Duration(intVal) * time.Second + continue } } @@ -112,11 +118,13 @@ func (s *Service) Spec(ctx context.Context) (*api.Response[map[string]any], erro // Handle integers. if v == "0" { config[k] = uint64(0) + continue } intVal, err := strconv.ParseUint(v, 10, 64) if err == nil && intVal != 0 { config[k] = intVal + continue } diff --git a/http/targetaggregatorspercommittee.go b/http/targetaggregatorspercommittee.go index 507ce927..6d3135a1 100644 --- a/http/targetaggregatorspercommittee.go +++ b/http/targetaggregatorspercommittee.go @@ -23,5 +23,6 @@ func (s *Service) TargetAggregatorsPerCommittee(ctx context.Context) (uint64, er if err != nil { return 0, err } + return response.Data["TARGET_AGGREGATORS_PER_COMMITTEE"].(uint64), nil } diff --git a/http/validators.go b/http/validators.go index cb46f58f..45925183 100644 --- a/http/validators.go +++ b/http/validators.go @@ -58,7 +58,7 @@ func (s *Service) indexChunkSize(ctx context.Context) int { return s.userIndexChunkSize } - nodeClient := "" + var nodeClient string response, err := s.NodeClient(ctx) if err == nil { nodeClient = response.Data @@ -87,7 +87,7 @@ func (s *Service) pubKeyChunkSize(ctx context.Context) int { return s.userPubKeyChunkSize } - nodeClient := "" + var nodeClient string response, err := s.NodeClient(ctx) if err == nil { nodeClient = response.Data diff --git a/mock/beaconblockroot.go b/mock/beaconblockroot.go index 9f9222ef..142e45ff 100644 --- a/mock/beaconblockroot.go +++ b/mock/beaconblockroot.go @@ -31,6 +31,7 @@ func (s *Service) BeaconBlockRoot(_ context.Context, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, }) + return &api.Response[*phase0.Root]{ Data: &root, Metadata: make(map[string]any), diff --git a/mock/beaconstateroot.go b/mock/beaconstateroot.go index 173657c3..0a0c1f3d 100644 --- a/mock/beaconstateroot.go +++ b/mock/beaconstateroot.go @@ -23,6 +23,7 @@ import ( // BeaconStateRoot fetches a beacon state's root given a state ID. func (s *Service) BeaconStateRoot(_ context.Context, _ *api.BeaconStateRootOpts) (*api.Response[*phase0.Root], error) { data := phase0.Root{} + return &api.Response[*phase0.Root]{ Data: &data, Metadata: make(map[string]any), diff --git a/mock/domain.go b/mock/domain.go index 8412b74a..9da532ef 100644 --- a/mock/domain.go +++ b/mock/domain.go @@ -33,7 +33,7 @@ func (s *Service) Domain(ctx context.Context, domainType phase0.DomainType, epoc } // GenesisDomain returns the domain for the given domain type at genesis. -// N.B. this is not always the same as the the domain at epoch 0. It is possible +// N.B. this is not always the same as the domain at epoch 0. It is possible // for a chain's fork schedule to have multiple forks at genesis. In this situation, // GenesisDomain() will return the first, and Domain() will return the last. func (s *Service) GenesisDomain(ctx context.Context, domainType phase0.DomainType) (phase0.Domain, error) { @@ -84,6 +84,7 @@ func (s *Service) domain(ctx context.Context, var domain phase0.Domain copy(domain[:], domainType[:]) copy(domain[4:], root[:]) + return domain, nil } @@ -105,6 +106,7 @@ func (s *Service) forkAtEpoch(ctx context.Context, epoch phase0.Epoch) (*phase0. } currentFork = response.Data[i] } + return currentFork, nil } diff --git a/mock/genesistime.go b/mock/genesistime.go index 0ead50ad..c9b06413 100644 --- a/mock/genesistime.go +++ b/mock/genesistime.go @@ -24,5 +24,6 @@ func (s *Service) GenesisTime(ctx context.Context) (time.Time, error) { if err != nil { return time.Time{}, err } + return genesisResponse.Data.GenesisTime, nil } diff --git a/multi/aggregateattestation.go b/multi/aggregateattestation.go index 7a3426e0..0f6d3c20 100644 --- a/multi/aggregateattestation.go +++ b/multi/aggregateattestation.go @@ -33,13 +33,12 @@ func (s *Service) AggregateAttestation(ctx context.Context, if err != nil { return nil, err } + return aggregate, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*phase0.Attestation]), nil } diff --git a/multi/attestationdata.go b/multi/attestationdata.go index 738fbbd1..ce9f627e 100644 --- a/multi/attestationdata.go +++ b/multi/attestationdata.go @@ -33,13 +33,12 @@ func (s *Service) AttestationData(ctx context.Context, if err != nil { return nil, err } + return attestationData, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*phase0.AttestationData]), nil } diff --git a/multi/attestationpool.go b/multi/attestationpool.go index 05e015f5..46bc2f3f 100644 --- a/multi/attestationpool.go +++ b/multi/attestationpool.go @@ -33,13 +33,12 @@ func (s *Service) AttestationPool(ctx context.Context, if err != nil { return nil, err } + return attestationPool, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[[]*phase0.Attestation]), nil } diff --git a/multi/attesterduties.go b/multi/attesterduties.go index b83f945e..3483af80 100644 --- a/multi/attesterduties.go +++ b/multi/attesterduties.go @@ -34,13 +34,12 @@ func (s *Service) AttesterDuties(ctx context.Context, if err != nil { return nil, err } + return block, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[[]*apiv1.AttesterDuty]), nil } diff --git a/multi/beaconblockheader.go b/multi/beaconblockheader.go index 4ab6a6ad..ceb255bf 100644 --- a/multi/beaconblockheader.go +++ b/multi/beaconblockheader.go @@ -33,13 +33,12 @@ func (s *Service) BeaconBlockHeader(ctx context.Context, if err != nil { return nil, err } + return beaconBlockHeader, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*apiv1.BeaconBlockHeader]), nil } diff --git a/multi/beaconblockroot.go b/multi/beaconblockroot.go index 36b53aa7..98bdbb1c 100644 --- a/multi/beaconblockroot.go +++ b/multi/beaconblockroot.go @@ -33,13 +33,12 @@ func (s *Service) BeaconBlockRoot(ctx context.Context, if err != nil { return nil, err } + return root, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*phase0.Root]), nil } diff --git a/multi/beaconcommittees.go b/multi/beaconcommittees.go index 822ba3c5..d6b1eae0 100644 --- a/multi/beaconcommittees.go +++ b/multi/beaconcommittees.go @@ -33,13 +33,12 @@ func (s *Service) BeaconCommittees(ctx context.Context, if err != nil { return nil, err } + return beaconCommittees, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[[]*apiv1.BeaconCommittee]), nil } diff --git a/multi/beaconstate.go b/multi/beaconstate.go index 0c79127f..91c718bb 100644 --- a/multi/beaconstate.go +++ b/multi/beaconstate.go @@ -28,13 +28,12 @@ func (s *Service) BeaconState(ctx context.Context, opts *api.BeaconStateOpts) (* if err != nil { return nil, err } + return beaconState, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*spec.VersionedBeaconState]), nil } diff --git a/multi/blindedproposal.go b/multi/blindedproposal.go index ad5106be..7bf04342 100644 --- a/multi/blindedproposal.go +++ b/multi/blindedproposal.go @@ -32,13 +32,12 @@ func (s *Service) BlindedProposal(ctx context.Context, if err != nil { return nil, err } + return block, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*api.VersionedBlindedProposal]), nil } diff --git a/multi/blobsidecars.go b/multi/blobsidecars.go index a95661a7..941fe4fb 100644 --- a/multi/blobsidecars.go +++ b/multi/blobsidecars.go @@ -28,6 +28,7 @@ func (s *Service) BlobSidecars(ctx context.Context, opts *api.BlobSidecarsOpts) if err != nil { return nil, err } + return blobSidecars, nil }, nil) if err != nil { @@ -36,5 +37,6 @@ func (s *Service) BlobSidecars(ctx context.Context, opts *api.BlobSidecarsOpts) if res == nil { return nil, nil } + return res.([]*deneb.BlobSidecar), nil } diff --git a/multi/client.go b/multi/client.go index 9ba44204..58b87360 100644 --- a/multi/client.go +++ b/multi/client.go @@ -34,6 +34,7 @@ func (s *Service) monitor(ctx context.Context) { select { case <-ctx.Done(): log.Trace().Msg("Context done; monitor stopping") + return case <-time.After(30 * time.Second): s.recheck(ctx) @@ -122,12 +123,14 @@ func ping(ctx context.Context, client consensusclient.Service) bool { provider, isProvider := client.(consensusclient.NodeSyncingProvider) if !isProvider { log.Debug().Str("provider", client.Address()).Msg("Client does not provide sync state") + return false } response, err := provider.NodeSyncing(ctx) if err != nil { log.Warn().Err(err).Msg("Failed to obtain sync state from node") + return false } @@ -179,6 +182,7 @@ func (s *Service) doCall(ctx context.Context, call callFunc, errHandler errHandl log.Debug().Str("client", client.Name()).Str("address", client.Address()).Err(err).Msg("Deactivating client on error") // Failed with this client; try the next. s.deactivateClient(ctx, client) + continue } @@ -188,10 +192,13 @@ func (s *Service) doCall(ctx context.Context, call callFunc, errHandler errHandl if res == nil { // No response from this client; try the next. err = errors.New("empty response") + continue } + return res, nil } + return nil, err } diff --git a/multi/depositcontract.go b/multi/depositcontract.go index 9def6032..8a8f3ba3 100644 --- a/multi/depositcontract.go +++ b/multi/depositcontract.go @@ -28,13 +28,12 @@ func (s *Service) DepositContract(ctx context.Context) (*api.Response[*apiv1.Dep if err != nil { return nil, err } + return aggregate, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*apiv1.DepositContract]), nil } diff --git a/multi/domain.go b/multi/domain.go index 68188e8f..7aab8d85 100644 --- a/multi/domain.go +++ b/multi/domain.go @@ -41,11 +41,13 @@ func (s *Service) Domain(ctx context.Context, if bytes.Equal(domain[:], emptyDomain[:]) { return nil, errors.New("empty domain not a valid response") } + return domain, nil }, nil) if err != nil { return phase0.Domain{}, err } + return res.(phase0.Domain), nil } @@ -64,10 +66,12 @@ func (s *Service) GenesisDomain(ctx context.Context, if bytes.Equal(domain[:], emptyDomain[:]) { return nil, errors.New("empty domain not a valid response") } + return domain, nil }, nil) if err != nil { return phase0.Domain{}, err } + return res.(phase0.Domain), nil } diff --git a/multi/events.go b/multi/events.go index 8f73a23b..9c94dbe6 100644 --- a/multi/events.go +++ b/multi/events.go @@ -51,6 +51,7 @@ func (s *Service) Events(ctx context.Context, } if err := client.(consensusclient.EventsProvider).Events(ctx, topics, ah.handleEvent); err != nil { inactiveClients = append(inactiveClients, client) + continue } log.Trace().Str("address", ah.address).Strs("topics", topics).Msg("Events handler active") @@ -69,11 +70,13 @@ func (s *Service) Events(ctx context.Context, provider, isProvider := c.(consensusclient.NodeSyncingProvider) if !isProvider { ah.log.Error().Str("address", ah.address).Strs("topics", topics).Msg("Not a node syncing provider") + return } syncResponse, err := provider.NodeSyncing(ctx) if err != nil { ah.log.Error().Str("address", ah.address).Strs("topics", topics).Err(err).Msg("Failed to obtain sync state from node") + return } if !syncResponse.Data.IsSyncing { @@ -81,6 +84,7 @@ func (s *Service) Events(ctx context.Context, if err := c.(consensusclient.EventsProvider).Events(ctx, topics, ah.handleEvent); err != nil { ah.log.Error().Str("address", ah.address).Strs("topics", topics).Err(err).Msg("Failed to set up events handler") } + // Return either way. return } diff --git a/multi/farfutureepoch.go b/multi/farfutureepoch.go index afa7b67e..6ed1efc5 100644 --- a/multi/farfutureepoch.go +++ b/multi/farfutureepoch.go @@ -31,10 +31,12 @@ func (s *Service) FarFutureEpoch(ctx context.Context) (phase0.Epoch, error) { if epoch == 0 { return nil, errors.New("zero epoch not a valid response") } + return epoch, nil }, nil) if err != nil { return 0, err } + return res.(phase0.Epoch), nil } diff --git a/multi/finality.go b/multi/finality.go index d6ba8fa5..54bb0eb8 100644 --- a/multi/finality.go +++ b/multi/finality.go @@ -28,13 +28,12 @@ func (s *Service) Finality(ctx context.Context, opts *api.FinalityOpts) (*api.Re if err != nil { return nil, err } + return finality, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*apiv1.Finality]), nil } diff --git a/multi/fork.go b/multi/fork.go index 4b07c668..060377a3 100644 --- a/multi/fork.go +++ b/multi/fork.go @@ -33,14 +33,12 @@ func (s *Service) Fork(ctx context.Context, if err != nil { return nil, err } + return fork, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } return res.(*api.Response[*phase0.Fork]), nil } diff --git a/multi/forkschedule.go b/multi/forkschedule.go index 9879f080..1fc7112d 100644 --- a/multi/forkschedule.go +++ b/multi/forkschedule.go @@ -28,13 +28,12 @@ func (s *Service) ForkSchedule(ctx context.Context) (*api.Response[[]*phase0.For if err != nil { return nil, err } + return forkSchedule, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[[]*phase0.Fork]), nil } diff --git a/multi/genesis.go b/multi/genesis.go index dbd08db6..af881d4f 100644 --- a/multi/genesis.go +++ b/multi/genesis.go @@ -28,13 +28,12 @@ func (s *Service) Genesis(ctx context.Context) (*api.Response[*apiv1.Genesis], e if err != nil { return nil, err } + return genesis, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*apiv1.Genesis]), nil } diff --git a/multi/genesistime.go b/multi/genesistime.go index 331ca055..9a063c34 100644 --- a/multi/genesistime.go +++ b/multi/genesistime.go @@ -31,10 +31,12 @@ func (s *Service) GenesisTime(ctx context.Context) (time.Time, error) { if genesisTime.IsZero() { return nil, errors.New("zero genesis time not a valid response") } + return genesisTime, nil }, nil) if err != nil { return time.Time{}, err } + return res.(time.Time), nil } diff --git a/multi/metrics.go b/multi/metrics.go index a82d3017..ad87afb2 100644 --- a/multi/metrics.go +++ b/multi/metrics.go @@ -38,6 +38,7 @@ func registerMetrics(ctx context.Context, monitor metrics.Service) error { if monitor.Presenter() == "prometheus" { return registerPrometheusMetrics(ctx) } + return nil } @@ -45,7 +46,7 @@ func registerPrometheusMetrics(_ context.Context) error { providersMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: "consensusclient", Subsystem: "multi", - Name: "providers_total", + Name: "providers", Help: "Number of providers", }, []string{"state"}) if err := prometheus.Register(providersMetric); err != nil { diff --git a/multi/nodesyncing.go b/multi/nodesyncing.go index f0b1c14f..3451fcd1 100644 --- a/multi/nodesyncing.go +++ b/multi/nodesyncing.go @@ -28,13 +28,12 @@ func (s *Service) NodeSyncing(ctx context.Context) (*api.Response[*apiv1.SyncSta if err != nil { return nil, err } + return nodeSyncing, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*apiv1.SyncState]), nil } diff --git a/multi/nodeversion.go b/multi/nodeversion.go index b9667aff..cb5cf4cb 100644 --- a/multi/nodeversion.go +++ b/multi/nodeversion.go @@ -27,14 +27,12 @@ func (s *Service) NodeVersion(ctx context.Context) (*api.Response[string], error if err != nil { return nil, err } + return aggregate, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } return res.(*api.Response[string]), nil } diff --git a/multi/proposal.go b/multi/proposal.go index a16a1766..5290e234 100644 --- a/multi/proposal.go +++ b/multi/proposal.go @@ -32,13 +32,12 @@ func (s *Service) Proposal(ctx context.Context, if err != nil { return nil, err } + return block, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*api.VersionedProposal]), nil } diff --git a/multi/proposerduties.go b/multi/proposerduties.go index 6a8852c4..afcafc43 100644 --- a/multi/proposerduties.go +++ b/multi/proposerduties.go @@ -34,13 +34,12 @@ func (s *Service) ProposerDuties(ctx context.Context, if err != nil { return nil, err } + return block, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[[]*apiv1.ProposerDuty]), nil } diff --git a/multi/service.go b/multi/service.go index 460f2a2a..7ebb6e6d 100644 --- a/multi/service.go +++ b/multi/service.go @@ -76,6 +76,7 @@ func New(ctx context.Context, params ...Parameter) (consensusclient.Service, err ) if err != nil { log.Error().Str("provider", address).Msg("Provider not present; dropping from rotation") + continue } if ping(ctx, client) { @@ -117,5 +118,6 @@ func (s *Service) Address() string { if len(s.activeClients) > 0 { return s.activeClients[0].Address() } + return "none" } diff --git a/multi/signedbeaconblock.go b/multi/signedbeaconblock.go index f50e7099..fd1a0b9e 100644 --- a/multi/signedbeaconblock.go +++ b/multi/signedbeaconblock.go @@ -33,13 +33,12 @@ func (s *Service) SignedBeaconBlock(ctx context.Context, if err != nil { return nil, err } + return block, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*spec.VersionedSignedBeaconBlock]), nil } diff --git a/multi/slotduration.go b/multi/slotduration.go index 556e5dd0..9b6bc067 100644 --- a/multi/slotduration.go +++ b/multi/slotduration.go @@ -31,10 +31,12 @@ func (s *Service) SlotDuration(ctx context.Context) (time.Duration, error) { if duration == 0 { return nil, errors.New("zero duration not a valid response") } + return duration, nil }, nil) if err != nil { return 0, err } + return res.(time.Duration), nil } diff --git a/multi/slotsperepoch.go b/multi/slotsperepoch.go index 49332293..20c0989d 100644 --- a/multi/slotsperepoch.go +++ b/multi/slotsperepoch.go @@ -30,10 +30,12 @@ func (s *Service) SlotsPerEpoch(ctx context.Context) (uint64, error) { if slotsPerEpoch == 0 { return nil, errors.New("zero value not a valid response") } + return slotsPerEpoch, nil }, nil) if err != nil { return 0, err } + return res.(uint64), nil } diff --git a/multi/spec.go b/multi/spec.go index c1e17471..22b6ba2a 100644 --- a/multi/spec.go +++ b/multi/spec.go @@ -27,13 +27,12 @@ func (s *Service) Spec(ctx context.Context) (*api.Response[map[string]any], erro if err != nil { return nil, err } + return aggregate, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[map[string]any]), nil } diff --git a/multi/stateroot.go b/multi/stateroot.go index ca1fa024..2fa62f52 100644 --- a/multi/stateroot.go +++ b/multi/stateroot.go @@ -33,13 +33,12 @@ func (s *Service) BeaconStateRoot(ctx context.Context, if err != nil { return nil, err } + return stateRoot, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*phase0.Root]), nil } diff --git a/multi/submitaggregateattestations.go b/multi/submitaggregateattestations.go index 36200216..1010a5f8 100644 --- a/multi/submitaggregateattestations.go +++ b/multi/submitaggregateattestations.go @@ -29,7 +29,9 @@ func (s *Service) SubmitAggregateAttestations(ctx context.Context, if err != nil { return nil, err } + return true, nil }, nil) + return err } diff --git a/multi/submitattestations.go b/multi/submitattestations.go index b7494d75..c0a3ec68 100644 --- a/multi/submitattestations.go +++ b/multi/submitattestations.go @@ -30,6 +30,7 @@ func (s *Service) SubmitAttestations(ctx context.Context, if err != nil { return nil, err } + return true, nil }, func(ctx context.Context, client consensusclient.Service, err error) (bool, error) { // We have received an error, decide if it requires us to fail over or not. @@ -41,17 +42,21 @@ func (s *Service) SubmitAttestations(ctx context.Context, // an existing attestation, but either way it is not a failover-worthy error. log := s.log.With().Logger() log.Trace().Msg("Lighthouse rejected submission as it already knew about it") + return false /* failover */, err case provider == "lighthouse" && strings.Contains(err.Error(), "UnknownHeadBlock"): // Lighthouse rejects an attestation for a block that is not its current head. We assume that // the request is valid and it is the node that it is somehow out of sync, so failover. log := s.log.With().Logger() log.Trace().Err(err).Msg("Lighthouse rejected submission as it did not know about the relevant head block") + return true /* failover */, err default: // Any other error should result in a failover. + return true /* failover */, err } }) + return err } diff --git a/multi/submitbeaconblock.go b/multi/submitbeaconblock.go index 87d68a45..b7c3455c 100644 --- a/multi/submitbeaconblock.go +++ b/multi/submitbeaconblock.go @@ -29,7 +29,9 @@ func (s *Service) SubmitBeaconBlock(ctx context.Context, block *spec.VersionedSi if err != nil { return nil, err } + return true, nil }, nil) + return err } diff --git a/multi/submitbeaconcommitteesubscriptions.go b/multi/submitbeaconcommitteesubscriptions.go index d42c1893..324b182d 100644 --- a/multi/submitbeaconcommitteesubscriptions.go +++ b/multi/submitbeaconcommitteesubscriptions.go @@ -29,7 +29,9 @@ func (s *Service) SubmitBeaconCommitteeSubscriptions(ctx context.Context, if err != nil { return nil, err } + return true, nil }, nil) + return err } diff --git a/multi/submitblindedbeaconblock.go b/multi/submitblindedbeaconblock.go index 52f1ffdd..9b1a71c0 100644 --- a/multi/submitblindedbeaconblock.go +++ b/multi/submitblindedbeaconblock.go @@ -29,7 +29,9 @@ func (s *Service) SubmitBlindedBeaconBlock(ctx context.Context, block *api.Versi if err != nil { return nil, err } + return true, nil }, nil) + return err } diff --git a/multi/submitproposal.go b/multi/submitproposal.go index 0f33bbac..1717c16e 100644 --- a/multi/submitproposal.go +++ b/multi/submitproposal.go @@ -27,7 +27,9 @@ func (s *Service) SubmitProposal(ctx context.Context, proposal *api.VersionedSig if err != nil { return nil, err } + return true, nil }, nil) + return err } diff --git a/multi/submitproposalpreparations.go b/multi/submitproposalpreparations.go index 2f6aebe6..9f9cd55b 100644 --- a/multi/submitproposalpreparations.go +++ b/multi/submitproposalpreparations.go @@ -30,7 +30,9 @@ func (s *Service) SubmitProposalPreparations(ctx context.Context, if err != nil { return nil, err } + return true, nil }, nil) + return err } diff --git a/multi/submitsynccommitteecontributions.go b/multi/submitsynccommitteecontributions.go index 76077dc4..f2af9117 100644 --- a/multi/submitsynccommitteecontributions.go +++ b/multi/submitsynccommitteecontributions.go @@ -29,7 +29,9 @@ func (s *Service) SubmitSyncCommitteeContributions(ctx context.Context, if err != nil { return nil, err } + return true, nil }, nil) + return err } diff --git a/multi/submitsynccommitteemessages.go b/multi/submitsynccommitteemessages.go index d50dc549..2948ab63 100644 --- a/multi/submitsynccommitteemessages.go +++ b/multi/submitsynccommitteemessages.go @@ -29,7 +29,9 @@ func (s *Service) SubmitSyncCommitteeMessages(ctx context.Context, if err != nil { return nil, err } + return true, nil }, nil) + return err } diff --git a/multi/submitsynccommitteesubscriptions.go b/multi/submitsynccommitteesubscriptions.go index cd0a89fa..c23c119b 100644 --- a/multi/submitsynccommitteesubscriptions.go +++ b/multi/submitsynccommitteesubscriptions.go @@ -29,7 +29,9 @@ func (s *Service) SubmitSyncCommitteeSubscriptions(ctx context.Context, if err != nil { return nil, err } + return true, nil }, nil) + return err } diff --git a/multi/submitvalidatorregistrations.go b/multi/submitvalidatorregistrations.go index efd2f946..bed43ad2 100644 --- a/multi/submitvalidatorregistrations.go +++ b/multi/submitvalidatorregistrations.go @@ -27,7 +27,9 @@ func (s *Service) SubmitValidatorRegistrations(ctx context.Context, registration if err != nil { return nil, err } + return true, nil }, nil) + return err } diff --git a/multi/submitvoluntaryexit.go b/multi/submitvoluntaryexit.go index 039dc365..0f1c72b5 100644 --- a/multi/submitvoluntaryexit.go +++ b/multi/submitvoluntaryexit.go @@ -27,7 +27,9 @@ func (s *Service) SubmitVoluntaryExit(ctx context.Context, voluntaryExit *phase0 if err != nil { return nil, err } + return true, nil }, nil) + return err } diff --git a/multi/synccommitteecontribution.go b/multi/synccommitteecontribution.go index b64d7479..4486bfb8 100644 --- a/multi/synccommitteecontribution.go +++ b/multi/synccommitteecontribution.go @@ -33,13 +33,12 @@ func (s *Service) SyncCommitteeContribution(ctx context.Context, if err != nil { return nil, err } + return block, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*altair.SyncCommitteeContribution]), nil } diff --git a/multi/synccommitteeduties.go b/multi/synccommitteeduties.go index 05ced7dc..3324fdfc 100644 --- a/multi/synccommitteeduties.go +++ b/multi/synccommitteeduties.go @@ -34,13 +34,12 @@ func (s *Service) SyncCommitteeDuties(ctx context.Context, if err != nil { return nil, err } + return response, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[[]*apiv1.SyncCommitteeDuty]), nil } diff --git a/multi/synccommittees.go b/multi/synccommittees.go index f167d6c0..36b4ca5a 100644 --- a/multi/synccommittees.go +++ b/multi/synccommittees.go @@ -28,13 +28,12 @@ func (s *Service) SyncCommittee(ctx context.Context, opts *api.SyncCommitteeOpts if err != nil { return nil, err } + return block, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[*apiv1.SyncCommittee]), nil } diff --git a/multi/targetaggregatorspercommittee.go b/multi/targetaggregatorspercommittee.go index 932a6c7e..05d21658 100644 --- a/multi/targetaggregatorspercommittee.go +++ b/multi/targetaggregatorspercommittee.go @@ -30,10 +30,12 @@ func (s *Service) TargetAggregatorsPerCommittee(ctx context.Context) (uint64, er if aggregators == 0 { return nil, errors.New("zero value not a valid response") } + return aggregators, nil }, nil) if err != nil { return 0, err } + return res.(uint64), nil } diff --git a/multi/validatorbalances.go b/multi/validatorbalances.go index 05c100a2..90f6503b 100644 --- a/multi/validatorbalances.go +++ b/multi/validatorbalances.go @@ -33,13 +33,12 @@ func (s *Service) ValidatorBalances(ctx context.Context, if err != nil { return nil, err } + return block, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[map[phase0.ValidatorIndex]phase0.Gwei]), nil } diff --git a/multi/validators.go b/multi/validators.go index 6a5dfba0..33cfeddd 100644 --- a/multi/validators.go +++ b/multi/validators.go @@ -34,13 +34,12 @@ func (s *Service) Validators(ctx context.Context, if err != nil { return nil, err } + return block, nil }, nil) if err != nil { return nil, err } - if res == nil { - return nil, nil - } + return res.(*api.Response[map[phase0.ValidatorIndex]*apiv1.Validator]), nil } diff --git a/multi/voluntaryexitpool.go b/multi/voluntaryexitpool.go index d2bcb45e..b9d6acbc 100644 --- a/multi/voluntaryexitpool.go +++ b/multi/voluntaryexitpool.go @@ -27,6 +27,7 @@ func (s *Service) VoluntaryExitPool(ctx context.Context) ([]*phase0.SignedVolunt if err != nil { return nil, err } + return voluntaryExitPool, nil }, nil) if err != nil { @@ -35,5 +36,6 @@ func (s *Service) VoluntaryExitPool(ctx context.Context) ([]*phase0.SignedVolunt if res == nil { return nil, nil } + return res.([]*phase0.SignedVoluntaryExit), nil } diff --git a/service.go b/service.go index ae21a025..df87784e 100644 --- a/service.go +++ b/service.go @@ -395,7 +395,7 @@ type DomainProvider interface { Domain(ctx context.Context, domainType phase0.DomainType, epoch phase0.Epoch) (phase0.Domain, error) // GenesisDomain returns the domain for the given domain type at genesis. - // N.B. this is not always the same as the the domain at epoch 0. It is possible + // N.B. this is not always the same as the domain at epoch 0. It is possible // for a chain's fork schedule to have multiple forks at genesis. In this situation, // GenesisDomain() will return the first, and Domain() will return the last. GenesisDomain(ctx context.Context, domainType phase0.DomainType) (phase0.Domain, error) diff --git a/spec/altair/beaconblock.go b/spec/altair/beaconblock.go index ee7bfac2..04fd0fd0 100644 --- a/spec/altair/beaconblock.go +++ b/spec/altair/beaconblock.go @@ -70,6 +70,7 @@ func (b *BeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &beaconBlockJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&beaconBlockJSON) } @@ -132,6 +133,7 @@ func (b *BeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -142,6 +144,7 @@ func (b *BeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &beaconBlockJSON); err != nil { return err } + return b.unpack(&beaconBlockJSON) } @@ -151,5 +154,6 @@ func (b *BeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/altair/beaconblockbody.go b/spec/altair/beaconblockbody.go index 710209e0..c3eef0b0 100644 --- a/spec/altair/beaconblockbody.go +++ b/spec/altair/beaconblockbody.go @@ -85,6 +85,7 @@ func (b *BeaconBlockBody) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &beaconBlockBodyJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&beaconBlockBodyJSON) } @@ -159,6 +160,7 @@ func (b *BeaconBlockBody) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -169,6 +171,7 @@ func (b *BeaconBlockBody) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &beaconBlockBodyJSON); err != nil { return err } + return b.unpack(&beaconBlockBodyJSON) } @@ -178,5 +181,6 @@ func (b *BeaconBlockBody) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/altair/beaconstate.go b/spec/altair/beaconstate.go index 4063a841..28b74742 100644 --- a/spec/altair/beaconstate.go +++ b/spec/altair/beaconstate.go @@ -149,6 +149,7 @@ func (s *BeaconState) MarshalJSON() ([]byte, error) { for i := range s.InactivityScores { inactivityScores[i] = fmt.Sprintf("%d", s.InactivityScores[i]) } + return json.Marshal(&beaconStateJSON{ GenesisTime: fmt.Sprintf("%d", s.GenesisTime), GenesisValidatorsRoot: fmt.Sprintf("%#x", s.GenesisValidatorsRoot), @@ -183,11 +184,13 @@ func (s *BeaconState) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&data) } // unpack unpacks JSON data in to a spec representation. -// nolint:gocyclo +// +//nolint:gocyclo func (s *BeaconState) unpack(data *beaconStateJSON) error { if data.GenesisTime == "" { return errors.New("genesis time missing") @@ -445,6 +448,7 @@ func (s *BeaconState) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -455,6 +459,7 @@ func (s *BeaconState) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } @@ -464,5 +469,6 @@ func (s *BeaconState) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/altair/contributionandproof.go b/spec/altair/contributionandproof.go index 8ca09687..0b2ce2a0 100644 --- a/spec/altair/contributionandproof.go +++ b/spec/altair/contributionandproof.go @@ -62,6 +62,7 @@ func (a *ContributionAndProof) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &contributionAndProofJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return a.unpack(&contributionAndProofJSON) } @@ -103,6 +104,7 @@ func (a *ContributionAndProof) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -113,6 +115,7 @@ func (a *ContributionAndProof) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &contributionAndProofJSON); err != nil { return err } + return a.unpack(&contributionAndProofJSON) } @@ -122,5 +125,6 @@ func (a *ContributionAndProof) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/altair/signedbeaconblock.go b/spec/altair/signedbeaconblock.go index d39ab962..2caa79d2 100644 --- a/spec/altair/signedbeaconblock.go +++ b/spec/altair/signedbeaconblock.go @@ -57,6 +57,7 @@ func (s *SignedBeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &signedBeaconBlockJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&signedBeaconBlockJSON) } @@ -89,6 +90,7 @@ func (s *SignedBeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -99,6 +101,7 @@ func (s *SignedBeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &signedBeaconBlockJSON); err != nil { return err } + return s.unpack(&signedBeaconBlockJSON) } @@ -108,5 +111,6 @@ func (s *SignedBeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/altair/signedcontributionandproof.go b/spec/altair/signedcontributionandproof.go index c0df300a..91ab45f7 100644 --- a/spec/altair/signedcontributionandproof.go +++ b/spec/altair/signedcontributionandproof.go @@ -57,6 +57,7 @@ func (s *SignedContributionAndProof) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &signedContributionAndProofJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&signedContributionAndProofJSON) } @@ -89,6 +90,7 @@ func (s *SignedContributionAndProof) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -99,6 +101,7 @@ func (s *SignedContributionAndProof) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &signedContributionAndProofJSON); err != nil { return err } + return s.unpack(&signedContributionAndProofJSON) } @@ -108,5 +111,6 @@ func (s *SignedContributionAndProof) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/altair/syncaggregate.go b/spec/altair/syncaggregate.go index 2106fd9c..d8e8d2ea 100644 --- a/spec/altair/syncaggregate.go +++ b/spec/altair/syncaggregate.go @@ -58,6 +58,7 @@ func (s *SyncAggregate) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &syncAggregateJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&syncAggregateJSON) } @@ -104,6 +105,7 @@ func (s *SyncAggregate) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -114,6 +116,7 @@ func (s *SyncAggregate) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &syncAggregateJSON); err != nil { return err } + return s.unpack(&syncAggregateJSON) } @@ -123,5 +126,6 @@ func (s *SyncAggregate) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/altair/synccommittee.go b/spec/altair/synccommittee.go index 011d7acb..0cec1a3e 100644 --- a/spec/altair/synccommittee.go +++ b/spec/altair/synccommittee.go @@ -65,6 +65,7 @@ func (s *SyncCommittee) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &syncCommitteeJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&syncCommitteeJSON) } @@ -113,6 +114,7 @@ func (s *SyncCommittee) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -123,6 +125,7 @@ func (s *SyncCommittee) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &syncCommitteeJSON); err != nil { return err } + return s.unpack(&syncCommitteeJSON) } @@ -132,5 +135,6 @@ func (s *SyncCommittee) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/altair/synccommitteecontribution.go b/spec/altair/synccommitteecontribution.go index 83c94a99..d2c56039 100644 --- a/spec/altair/synccommitteecontribution.go +++ b/spec/altair/synccommitteecontribution.go @@ -72,6 +72,7 @@ func (s *SyncCommitteeContribution) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &syncCommitteeContributionJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&syncCommitteeContributionJSON) } @@ -136,6 +137,7 @@ func (s *SyncCommitteeContribution) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -146,6 +148,7 @@ func (s *SyncCommitteeContribution) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &syncCommitteeContributionJSON); err != nil { return err } + return s.unpack(&syncCommitteeContributionJSON) } @@ -155,5 +158,6 @@ func (s *SyncCommitteeContribution) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/altair/synccommitteemessage.go b/spec/altair/synccommitteemessage.go index aa754aec..04fae5ee 100644 --- a/spec/altair/synccommitteemessage.go +++ b/spec/altair/synccommitteemessage.go @@ -66,6 +66,7 @@ func (s *SyncCommitteeMessage) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &syncCommitteeMessageJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&syncCommitteeMessageJSON) } @@ -123,6 +124,7 @@ func (s *SyncCommitteeMessage) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -133,6 +135,7 @@ func (s *SyncCommitteeMessage) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &syncCommitteeMessageJSON); err != nil { return err } + return s.unpack(&syncCommitteeMessageJSON) } @@ -142,5 +145,6 @@ func (s *SyncCommitteeMessage) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/bellatrix/beaconblock.go b/spec/bellatrix/beaconblock.go index 9089d14a..d4275a80 100644 --- a/spec/bellatrix/beaconblock.go +++ b/spec/bellatrix/beaconblock.go @@ -70,6 +70,7 @@ func (b *BeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } @@ -132,6 +133,7 @@ func (b *BeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -142,6 +144,7 @@ func (b *BeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } @@ -151,5 +154,6 @@ func (b *BeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/bellatrix/beaconblockbody.go b/spec/bellatrix/beaconblockbody.go index 9532be25..be4091b2 100644 --- a/spec/bellatrix/beaconblockbody.go +++ b/spec/bellatrix/beaconblockbody.go @@ -90,6 +90,7 @@ func (b *BeaconBlockBody) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } @@ -169,6 +170,7 @@ func (b *BeaconBlockBody) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -179,6 +181,7 @@ func (b *BeaconBlockBody) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } @@ -188,5 +191,6 @@ func (b *BeaconBlockBody) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/bellatrix/beaconstate.go b/spec/bellatrix/beaconstate.go index 64e9db6f..8f580b9b 100644 --- a/spec/bellatrix/beaconstate.go +++ b/spec/bellatrix/beaconstate.go @@ -153,6 +153,7 @@ func (s *BeaconState) MarshalJSON() ([]byte, error) { for i := range s.InactivityScores { inactivityScores[i] = fmt.Sprintf("%d", s.InactivityScores[i]) } + return json.Marshal(&beaconStateJSON{ GenesisTime: fmt.Sprintf("%d", s.GenesisTime), GenesisValidatorsRoot: fmt.Sprintf("%#x", s.GenesisValidatorsRoot), @@ -188,11 +189,13 @@ func (s *BeaconState) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&data) } // unpack unpacks JSON data in to a spec representation. -// nolint:gocyclo +// +//nolint:gocyclo func (s *BeaconState) unpack(data *beaconStateJSON) error { var err error @@ -452,6 +455,7 @@ func (s *BeaconState) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -462,6 +466,7 @@ func (s *BeaconState) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } @@ -471,5 +476,6 @@ func (s *BeaconState) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/bellatrix/executionpayload.go b/spec/bellatrix/executionpayload.go index 3976ea3e..1af66500 100644 --- a/spec/bellatrix/executionpayload.go +++ b/spec/bellatrix/executionpayload.go @@ -125,10 +125,11 @@ func (e *ExecutionPayload) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return e.unpack(&data) } -// nolint:gocyclo +//nolint:gocyclo func (e *ExecutionPayload) unpack(data *executionPayloadJSON) error { if data.ParentHash == "" { return errors.New("parent hash missing") @@ -359,6 +360,7 @@ func (e *ExecutionPayload) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -369,6 +371,7 @@ func (e *ExecutionPayload) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return e.unpack(&data) } @@ -378,5 +381,6 @@ func (e *ExecutionPayload) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/bellatrix/executionpayloadheader.go b/spec/bellatrix/executionpayloadheader.go index 01006ae7..e83e6b46 100644 --- a/spec/bellatrix/executionpayloadheader.go +++ b/spec/bellatrix/executionpayloadheader.go @@ -120,10 +120,11 @@ func (e *ExecutionPayloadHeader) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return e.unpack(&data) } -// nolint:gocyclo +//nolint:gocyclo func (e *ExecutionPayloadHeader) unpack(data *executionPayloadHeaderJSON) error { if data.ParentHash == "" { return errors.New("parent hash missing") @@ -345,6 +346,7 @@ func (e *ExecutionPayloadHeader) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -355,6 +357,7 @@ func (e *ExecutionPayloadHeader) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return e.unpack(&data) } @@ -364,5 +367,6 @@ func (e *ExecutionPayloadHeader) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/bellatrix/signedbeaconblock.go b/spec/bellatrix/signedbeaconblock.go index 72a56129..4405501b 100644 --- a/spec/bellatrix/signedbeaconblock.go +++ b/spec/bellatrix/signedbeaconblock.go @@ -57,6 +57,7 @@ func (s *SignedBeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&data) } @@ -89,6 +90,7 @@ func (s *SignedBeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -99,6 +101,7 @@ func (s *SignedBeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } @@ -108,5 +111,6 @@ func (s *SignedBeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/builderversion.go b/spec/builderversion.go index 887ec769..e9bcfa5f 100644 --- a/spec/builderversion.go +++ b/spec/builderversion.go @@ -44,6 +44,7 @@ func (d *BuilderVersion) UnmarshalJSON(input []byte) error { default: err = fmt.Errorf("unrecognised response version %s", string(input)) } + return err } @@ -52,5 +53,6 @@ func (d BuilderVersion) String() string { if int(d) >= len(responseBuilderVersionStrings) { return "unknown" } + return responseBuilderVersionStrings[d] } diff --git a/spec/capella/beaconblock.go b/spec/capella/beaconblock.go index e4f46dd6..6bc988d0 100644 --- a/spec/capella/beaconblock.go +++ b/spec/capella/beaconblock.go @@ -70,6 +70,7 @@ func (b *BeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } @@ -132,6 +133,7 @@ func (b *BeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -142,6 +144,7 @@ func (b *BeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } @@ -151,5 +154,6 @@ func (b *BeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/capella/beaconblockbody.go b/spec/capella/beaconblockbody.go index 54713f02..08cfcd1c 100644 --- a/spec/capella/beaconblockbody.go +++ b/spec/capella/beaconblockbody.go @@ -94,6 +94,7 @@ func (b *BeaconBlockBody) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } @@ -175,6 +176,7 @@ func (b *BeaconBlockBody) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -185,6 +187,7 @@ func (b *BeaconBlockBody) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } @@ -194,5 +197,6 @@ func (b *BeaconBlockBody) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/capella/beaconstate.go b/spec/capella/beaconstate.go index f0f68706..db439c9e 100644 --- a/spec/capella/beaconstate.go +++ b/spec/capella/beaconstate.go @@ -60,5 +60,6 @@ func (s *BeaconState) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/capella/beaconstate_json.go b/spec/capella/beaconstate_json.go index bfa9d091..f4f71350 100644 --- a/spec/capella/beaconstate_json.go +++ b/spec/capella/beaconstate_json.go @@ -95,6 +95,7 @@ func (s *BeaconState) MarshalJSON() ([]byte, error) { for i := range s.InactivityScores { inactivityScores[i] = fmt.Sprintf("%d", s.InactivityScores[i]) } + return json.Marshal(&beaconStateJSON{ GenesisTime: fmt.Sprintf("%d", s.GenesisTime), GenesisValidatorsRoot: fmt.Sprintf("%#x", s.GenesisValidatorsRoot), @@ -133,11 +134,13 @@ func (s *BeaconState) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&data) } // unpack unpacks JSON data in to a spec representation. -// nolint:gocyclo +// +//nolint:gocyclo func (s *BeaconState) unpack(data *beaconStateJSON) error { var err error @@ -338,7 +341,7 @@ func (s *BeaconState) unpack(data *beaconStateJSON) error { } s.NextWithdrawalIndex = WithdrawalIndex(nextWithdrawalIndex) if data.NextWithdrawalValidatorIndex == "" { - return errors.New("next validator validator index missing") + return errors.New("next withdrawal validator index missing") } nextWithdrawalValidatorIndex, err := strconv.ParseUint(data.NextWithdrawalValidatorIndex, 10, 64) if err != nil { diff --git a/spec/capella/beaconstate_yaml.go b/spec/capella/beaconstate_yaml.go index 5a6152e4..6f8c5f96 100644 --- a/spec/capella/beaconstate_yaml.go +++ b/spec/capella/beaconstate_yaml.go @@ -121,6 +121,7 @@ func (s *BeaconState) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -131,5 +132,6 @@ func (s *BeaconState) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } diff --git a/spec/capella/blstoexecutionchange.go b/spec/capella/blstoexecutionchange.go index ea356b6c..bc423bb2 100644 --- a/spec/capella/blstoexecutionchange.go +++ b/spec/capella/blstoexecutionchange.go @@ -64,6 +64,7 @@ func (b *BLSToExecutionChange) UnmarshalJSON(input []byte) error { if err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&data) } @@ -114,6 +115,7 @@ func (b *BLSToExecutionChange) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -124,6 +126,7 @@ func (b *BLSToExecutionChange) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return b.unpack(&data) } @@ -133,5 +136,6 @@ func (b *BLSToExecutionChange) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/capella/executionpayload.go b/spec/capella/executionpayload.go index 8375fe60..e22c5a95 100644 --- a/spec/capella/executionpayload.go +++ b/spec/capella/executionpayload.go @@ -130,10 +130,11 @@ func (e *ExecutionPayload) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return e.unpack(&data) } -// nolint:gocyclo +//nolint:gocyclo func (e *ExecutionPayload) unpack(data *executionPayloadJSON) error { if data.ParentHash == "" { return errors.New("parent hash missing") @@ -370,6 +371,7 @@ func (e *ExecutionPayload) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -380,6 +382,7 @@ func (e *ExecutionPayload) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return e.unpack(&data) } @@ -389,5 +392,6 @@ func (e *ExecutionPayload) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/capella/executionpayloadheader.go b/spec/capella/executionpayloadheader.go index 1eda4704..e6fc8f67 100644 --- a/spec/capella/executionpayloadheader.go +++ b/spec/capella/executionpayloadheader.go @@ -125,10 +125,11 @@ func (e *ExecutionPayloadHeader) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return e.unpack(&data) } -// nolint:gocyclo +//nolint:gocyclo func (e *ExecutionPayloadHeader) unpack(data *executionPayloadHeaderJSON) error { if data.ParentHash == "" { return errors.New("parent hash missing") @@ -363,6 +364,7 @@ func (e *ExecutionPayloadHeader) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -373,6 +375,7 @@ func (e *ExecutionPayloadHeader) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return e.unpack(&data) } @@ -382,5 +385,6 @@ func (e *ExecutionPayloadHeader) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/capella/historicalsummary.go b/spec/capella/historicalsummary.go index 6833ddd9..315222bf 100644 --- a/spec/capella/historicalsummary.go +++ b/spec/capella/historicalsummary.go @@ -32,5 +32,6 @@ func (h *HistoricalSummary) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/capella/historicalsummary_json.go b/spec/capella/historicalsummary_json.go index c640d9a8..f54026d0 100644 --- a/spec/capella/historicalsummary_json.go +++ b/spec/capella/historicalsummary_json.go @@ -43,6 +43,7 @@ func (h *HistoricalSummary) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return h.unpack(&data) } diff --git a/spec/capella/historicalsummary_yaml.go b/spec/capella/historicalsummary_yaml.go index 1cd74877..77ea8046 100644 --- a/spec/capella/historicalsummary_yaml.go +++ b/spec/capella/historicalsummary_yaml.go @@ -35,6 +35,7 @@ func (h *HistoricalSummary) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -45,5 +46,6 @@ func (h *HistoricalSummary) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return h.unpack(&data) } diff --git a/spec/capella/signedbeaconblock.go b/spec/capella/signedbeaconblock.go index b5a86448..2c64037b 100644 --- a/spec/capella/signedbeaconblock.go +++ b/spec/capella/signedbeaconblock.go @@ -57,6 +57,7 @@ func (s *SignedBeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&data) } @@ -89,6 +90,7 @@ func (s *SignedBeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -99,6 +101,7 @@ func (s *SignedBeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } @@ -108,5 +111,6 @@ func (s *SignedBeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/capella/signedblstoexecutionchange.go b/spec/capella/signedblstoexecutionchange.go index 43c34c15..345f39b4 100644 --- a/spec/capella/signedblstoexecutionchange.go +++ b/spec/capella/signedblstoexecutionchange.go @@ -57,6 +57,7 @@ func (s *SignedBLSToExecutionChange) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&data) } @@ -90,6 +91,7 @@ func (s *SignedBLSToExecutionChange) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -100,6 +102,7 @@ func (s *SignedBLSToExecutionChange) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } @@ -109,5 +112,6 @@ func (s *SignedBLSToExecutionChange) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/capella/withdrawal.go b/spec/capella/withdrawal.go index fdb72cd0..23d2051a 100644 --- a/spec/capella/withdrawal.go +++ b/spec/capella/withdrawal.go @@ -68,6 +68,7 @@ func (w *Withdrawal) UnmarshalJSON(input []byte) error { if err != nil { return errors.Wrap(err, "invalid JSON") } + return w.unpack(&data) } @@ -125,6 +126,7 @@ func (w *Withdrawal) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -135,6 +137,7 @@ func (w *Withdrawal) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return w.unpack(&data) } @@ -144,5 +147,6 @@ func (w *Withdrawal) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/dataversion.go b/spec/dataversion.go index 1afcfe6c..ef09d06e 100644 --- a/spec/dataversion.go +++ b/spec/dataversion.go @@ -67,6 +67,7 @@ func (d *DataVersion) UnmarshalJSON(input []byte) error { default: err = fmt.Errorf("unrecognised data version %s", string(input)) } + return err } @@ -75,5 +76,6 @@ func (d DataVersion) String() string { if int(d) >= len(dataVersionStrings) { return "unknown" } + return dataVersionStrings[d] } diff --git a/spec/deneb/beaconblock.go b/spec/deneb/beaconblock.go index 606bc2ef..554f47f5 100644 --- a/spec/deneb/beaconblock.go +++ b/spec/deneb/beaconblock.go @@ -35,5 +35,6 @@ func (b *BeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/deneb/beaconblock_yaml.go b/spec/deneb/beaconblock_yaml.go index adca9269..5e9736f4 100644 --- a/spec/deneb/beaconblock_yaml.go +++ b/spec/deneb/beaconblock_yaml.go @@ -42,6 +42,7 @@ func (b *BeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } diff --git a/spec/deneb/beaconblockbody.go b/spec/deneb/beaconblockbody.go index 8a459239..5ed035da 100644 --- a/spec/deneb/beaconblockbody.go +++ b/spec/deneb/beaconblockbody.go @@ -44,5 +44,6 @@ func (b *BeaconBlockBody) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/deneb/beaconblockbody_yaml.go b/spec/deneb/beaconblockbody_yaml.go index f5a0c558..aeff351b 100644 --- a/spec/deneb/beaconblockbody_yaml.go +++ b/spec/deneb/beaconblockbody_yaml.go @@ -65,6 +65,7 @@ func (b *BeaconBlockBody) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } diff --git a/spec/deneb/beaconstate.go b/spec/deneb/beaconstate.go index 39d86c24..460abb92 100644 --- a/spec/deneb/beaconstate.go +++ b/spec/deneb/beaconstate.go @@ -61,5 +61,6 @@ func (b *BeaconState) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/deneb/beaconstate_json.go b/spec/deneb/beaconstate_json.go index 3f3410a0..d80cef7a 100644 --- a/spec/deneb/beaconstate_json.go +++ b/spec/deneb/beaconstate_json.go @@ -86,6 +86,7 @@ func (b *BeaconState) MarshalJSON() ([]byte, error) { for i := range b.InactivityScores { inactivityScores[i] = fmt.Sprintf("%d", b.InactivityScores[i]) } + return json.Marshal(&beaconStateJSON{ GenesisTime: fmt.Sprintf("%d", b.GenesisTime), GenesisValidatorsRoot: b.GenesisValidatorsRoot, diff --git a/spec/deneb/beaconstate_yaml.go b/spec/deneb/beaconstate_yaml.go index b00b2993..d33b6a76 100644 --- a/spec/deneb/beaconstate_yaml.go +++ b/spec/deneb/beaconstate_yaml.go @@ -92,6 +92,7 @@ func (b *BeaconState) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } diff --git a/spec/deneb/blobidentifier.go b/spec/deneb/blobidentifier.go index 2bfd9f6e..dab2bf66 100644 --- a/spec/deneb/blobidentifier.go +++ b/spec/deneb/blobidentifier.go @@ -32,5 +32,6 @@ func (b *BlobIdentifier) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/deneb/blobindex.go b/spec/deneb/blobindex.go index 7c74a6cd..450a966b 100644 --- a/spec/deneb/blobindex.go +++ b/spec/deneb/blobindex.go @@ -51,5 +51,6 @@ func (b *BlobIndex) MarshalJSON() ([]byte, error) { if b == nil { return nil, errors.New("value nil") } + return []byte(fmt.Sprintf(`"%d"`, *b)), nil } diff --git a/spec/deneb/blobsidecar.go b/spec/deneb/blobsidecar.go index 0b07ab99..5dd28e73 100644 --- a/spec/deneb/blobsidecar.go +++ b/spec/deneb/blobsidecar.go @@ -38,5 +38,6 @@ func (b *BlobSidecar) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/deneb/blobsidecar_yaml.go b/spec/deneb/blobsidecar_yaml.go index 32a1a016..499b18c6 100644 --- a/spec/deneb/blobsidecar_yaml.go +++ b/spec/deneb/blobsidecar_yaml.go @@ -49,6 +49,7 @@ func (b *BlobSidecar) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } diff --git a/spec/deneb/executionpayload.go b/spec/deneb/executionpayload.go index 50494022..e49cb437 100644 --- a/spec/deneb/executionpayload.go +++ b/spec/deneb/executionpayload.go @@ -50,5 +50,6 @@ func (e *ExecutionPayload) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/deneb/executionpayload_yaml.go b/spec/deneb/executionpayload_yaml.go index c2fd25fe..a397202a 100644 --- a/spec/deneb/executionpayload_yaml.go +++ b/spec/deneb/executionpayload_yaml.go @@ -78,6 +78,7 @@ func (e *ExecutionPayload) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } diff --git a/spec/deneb/executionpayloadheader.go b/spec/deneb/executionpayloadheader.go index f5fb9a4b..6a8ad7c4 100644 --- a/spec/deneb/executionpayloadheader.go +++ b/spec/deneb/executionpayloadheader.go @@ -49,5 +49,6 @@ func (e *ExecutionPayloadHeader) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/deneb/signedbeaconblock.go b/spec/deneb/signedbeaconblock.go index 0fb42f27..4907121b 100644 --- a/spec/deneb/signedbeaconblock.go +++ b/spec/deneb/signedbeaconblock.go @@ -32,5 +32,6 @@ func (s *SignedBeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/deneb/signedbeaconblock_json.go b/spec/deneb/signedbeaconblock_json.go index 1fe4ee1a..6dee7c2a 100644 --- a/spec/deneb/signedbeaconblock_json.go +++ b/spec/deneb/signedbeaconblock_json.go @@ -43,6 +43,7 @@ func (s *SignedBeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &data); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&data) } diff --git a/spec/deneb/signedbeaconblock_yaml.go b/spec/deneb/signedbeaconblock_yaml.go index 03670e7b..d1dbb6bc 100644 --- a/spec/deneb/signedbeaconblock_yaml.go +++ b/spec/deneb/signedbeaconblock_yaml.go @@ -35,6 +35,7 @@ func (s *SignedBeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -45,5 +46,6 @@ func (s *SignedBeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } diff --git a/spec/deneb/signedblobsidecar.go b/spec/deneb/signedblobsidecar.go index ab4d13df..08ccd0ad 100644 --- a/spec/deneb/signedblobsidecar.go +++ b/spec/deneb/signedblobsidecar.go @@ -32,5 +32,6 @@ func (s *SignedBlobSidecar) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/deneb/signedblobsidecar_yaml.go b/spec/deneb/signedblobsidecar_yaml.go index 1ace9b40..4a3bf136 100644 --- a/spec/deneb/signedblobsidecar_yaml.go +++ b/spec/deneb/signedblobsidecar_yaml.go @@ -37,6 +37,7 @@ func (s *SignedBlobSidecar) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } diff --git a/spec/deneb/versionedhash.go b/spec/deneb/versionedhash.go index e373dc56..22f6719d 100644 --- a/spec/deneb/versionedhash.go +++ b/spec/deneb/versionedhash.go @@ -81,6 +81,7 @@ func (h *VersionedHash) MarshalJSON() ([]byte, error) { if h == nil { return nil, errors.New("value nil") } + return []byte(fmt.Sprintf(`"%#x"`, h)), nil } @@ -117,5 +118,6 @@ func (h *VersionedHash) MarshalYAML() ([]byte, error) { if h == nil { return nil, errors.New("value nil") } + return []byte(fmt.Sprintf(`'%#x'`, h)), nil } diff --git a/spec/phase0/aggregateandproof.go b/spec/phase0/aggregateandproof.go index 68ed6672..b5f7b4bb 100644 --- a/spec/phase0/aggregateandproof.go +++ b/spec/phase0/aggregateandproof.go @@ -61,6 +61,7 @@ func (a *AggregateAndProof) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &aggregateAndProofJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return a.unpack(&aggregateAndProofJSON) } @@ -102,6 +103,7 @@ func (a *AggregateAndProof) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -112,6 +114,7 @@ func (a *AggregateAndProof) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &aggregateAndProofJSON); err != nil { return err } + return a.unpack(&aggregateAndProofJSON) } @@ -121,5 +124,6 @@ func (a *AggregateAndProof) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/attestation.go b/spec/phase0/attestation.go index df5742a5..e87cdf38 100644 --- a/spec/phase0/attestation.go +++ b/spec/phase0/attestation.go @@ -62,6 +62,7 @@ func (a *Attestation) UnmarshalJSON(input []byte) error { if err != nil { return errors.Wrap(err, "invalid JSON") } + return a.unpack(&attestationJSON) } @@ -102,6 +103,7 @@ func (a *Attestation) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -112,6 +114,7 @@ func (a *Attestation) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &attestationJSON); err != nil { return err } + return a.unpack(&attestationJSON) } @@ -121,5 +124,6 @@ func (a *Attestation) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/attestationdata.go b/spec/phase0/attestationdata.go index fe8530a1..9b45a4c0 100644 --- a/spec/phase0/attestationdata.go +++ b/spec/phase0/attestationdata.go @@ -69,6 +69,7 @@ func (a *AttestationData) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &attestationDataJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return a.unpack(&attestationDataJSON) } @@ -124,6 +125,7 @@ func (a *AttestationData) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -134,6 +136,7 @@ func (a *AttestationData) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &attestationDataJSON); err != nil { return err } + return a.unpack(&attestationDataJSON) } @@ -143,5 +146,6 @@ func (a *AttestationData) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/attesterslashing.go b/spec/phase0/attesterslashing.go index 7427a582..6d6811e3 100644 --- a/spec/phase0/attesterslashing.go +++ b/spec/phase0/attesterslashing.go @@ -54,6 +54,7 @@ func (a *AttesterSlashing) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &attesterSlashingJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return a.unpack(&attesterSlashingJSON) } @@ -79,6 +80,7 @@ func (a *AttesterSlashing) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -89,6 +91,7 @@ func (a *AttesterSlashing) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &attesterSlashingJSON); err != nil { return err } + return a.unpack(&attesterSlashingJSON) } @@ -97,5 +100,6 @@ func (a *AttesterSlashing) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/beaconblock.go b/spec/phase0/beaconblock.go index 5af5a05b..b8f73a13 100644 --- a/spec/phase0/beaconblock.go +++ b/spec/phase0/beaconblock.go @@ -69,6 +69,7 @@ func (b *BeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &beaconBlockJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&beaconBlockJSON) } @@ -131,6 +132,7 @@ func (b *BeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -141,6 +143,7 @@ func (b *BeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &beaconBlockJSON); err != nil { return err } + return b.unpack(&beaconBlockJSON) } @@ -150,5 +153,6 @@ func (b *BeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/beaconblockbody.go b/spec/phase0/beaconblockbody.go index 6a6b199a..556730d7 100644 --- a/spec/phase0/beaconblockbody.go +++ b/spec/phase0/beaconblockbody.go @@ -80,6 +80,7 @@ func (b *BeaconBlockBody) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &beaconBlockBodyJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&beaconBlockBodyJSON) } @@ -149,6 +150,7 @@ func (b *BeaconBlockBody) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -159,6 +161,7 @@ func (b *BeaconBlockBody) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &beaconBlockBodyJSON); err != nil { return err } + return b.unpack(&beaconBlockBodyJSON) } @@ -168,5 +171,6 @@ func (b *BeaconBlockBody) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/beaconblockheader.go b/spec/phase0/beaconblockheader.go index cb167c19..aee43f98 100644 --- a/spec/phase0/beaconblockheader.go +++ b/spec/phase0/beaconblockheader.go @@ -69,6 +69,7 @@ func (b *BeaconBlockHeader) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &beaconBlockHeaderJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return b.unpack(&beaconBlockHeaderJSON) } @@ -138,6 +139,7 @@ func (b *BeaconBlockHeader) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -148,6 +150,7 @@ func (b *BeaconBlockHeader) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &beaconBlockHeaderJSON); err != nil { return err } + return b.unpack(&beaconBlockHeaderJSON) } @@ -157,5 +160,6 @@ func (b *BeaconBlockHeader) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/beaconstate.go b/spec/phase0/beaconstate.go index 12cdbe1a..975edb68 100644 --- a/spec/phase0/beaconstate.go +++ b/spec/phase0/beaconstate.go @@ -127,6 +127,7 @@ func (s *BeaconState) MarshalJSON() ([]byte, error) { for i := range s.Slashings { slashings[i] = fmt.Sprintf("%d", s.Slashings[i]) } + return json.Marshal(&beaconStateJSON{ GenesisTime: fmt.Sprintf("%d", s.GenesisTime), GenesisValidatorsRoot: fmt.Sprintf("%#x", s.GenesisValidatorsRoot), @@ -164,7 +165,7 @@ func (s *BeaconState) UnmarshalJSON(input []byte) error { return s.unpack(&data) } -// nolint:gocyclo +//nolint:gocyclo func (s *BeaconState) unpack(data *beaconStateJSON) error { var err error @@ -350,6 +351,7 @@ func (s *BeaconState) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -360,6 +362,7 @@ func (s *BeaconState) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &data); err != nil { return err } + return s.unpack(&data) } @@ -369,5 +372,6 @@ func (s *BeaconState) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/checkpoint.go b/spec/phase0/checkpoint.go index 4c0854fd..0bc1e5d9 100644 --- a/spec/phase0/checkpoint.go +++ b/spec/phase0/checkpoint.go @@ -58,6 +58,7 @@ func (c *Checkpoint) UnmarshalJSON(input []byte) error { if err != nil { return errors.Wrap(err, "invalid JSON") } + return c.unpack(&checkpointJSON) } @@ -94,6 +95,7 @@ func (c *Checkpoint) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -104,6 +106,7 @@ func (c *Checkpoint) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &checkpointJSON); err != nil { return err } + return c.unpack(&checkpointJSON) } @@ -113,5 +116,6 @@ func (c *Checkpoint) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/deposit.go b/spec/phase0/deposit.go index f1bfc02f..0402af59 100644 --- a/spec/phase0/deposit.go +++ b/spec/phase0/deposit.go @@ -48,6 +48,7 @@ func (d *Deposit) MarshalJSON() ([]byte, error) { for i := range d.Proof { proof[i] = fmt.Sprintf("%#x", d.Proof[i]) } + return json.Marshal(&depositJSON{ Proof: proof, Data: d.Data, @@ -60,6 +61,7 @@ func (d *Deposit) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &depositJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return d.unpack(&depositJSON) } @@ -104,6 +106,7 @@ func (d *Deposit) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -114,6 +117,7 @@ func (d *Deposit) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &depositJSON); err != nil { return err } + return d.unpack(&depositJSON) } @@ -123,5 +127,6 @@ func (d *Deposit) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/depositdata.go b/spec/phase0/depositdata.go index 7c0f7d32..7e877cea 100644 --- a/spec/phase0/depositdata.go +++ b/spec/phase0/depositdata.go @@ -65,6 +65,7 @@ func (d *DepositData) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &depositDataJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return d.unpack(&depositDataJSON) } @@ -123,6 +124,7 @@ func (d *DepositData) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -133,6 +135,7 @@ func (d *DepositData) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &depositDataJSON); err != nil { return err } + return d.unpack(&depositDataJSON) } @@ -142,5 +145,6 @@ func (d *DepositData) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/depositmessage.go b/spec/phase0/depositmessage.go index 44db9287..de2c988b 100644 --- a/spec/phase0/depositmessage.go +++ b/spec/phase0/depositmessage.go @@ -61,6 +61,7 @@ func (d *DepositMessage) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &depositMessageJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return d.unpack(&depositMessageJSON) } @@ -107,6 +108,7 @@ func (d *DepositMessage) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -117,6 +119,7 @@ func (d *DepositMessage) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &depositMessageJSON); err != nil { return err } + return d.unpack(&depositMessageJSON) } @@ -126,5 +129,6 @@ func (d *DepositMessage) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/eth1data.go b/spec/phase0/eth1data.go index e9e4e266..afaec80a 100644 --- a/spec/phase0/eth1data.go +++ b/spec/phase0/eth1data.go @@ -62,6 +62,7 @@ func (e *ETH1Data) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, ð1DataJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return e.unpack(ð1DataJSON) } @@ -106,6 +107,7 @@ func (e *ETH1Data) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -116,6 +118,7 @@ func (e *ETH1Data) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, ð1DataJSON); err != nil { return err } + return e.unpack(ð1DataJSON) } @@ -125,5 +128,6 @@ func (e *ETH1Data) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/fork.go b/spec/phase0/fork.go index ea0835d4..8123d576 100644 --- a/spec/phase0/fork.go +++ b/spec/phase0/fork.go @@ -64,6 +64,7 @@ func (f *Fork) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &forkJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return f.unpack(&forkJSON) } @@ -112,6 +113,7 @@ func (f *Fork) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -122,6 +124,7 @@ func (f *Fork) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &forkJSON); err != nil { return err } + return f.unpack(&forkJSON) } @@ -131,5 +134,6 @@ func (f *Fork) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/forkdata.go b/spec/phase0/forkdata.go index b054a436..96ac1b30 100644 --- a/spec/phase0/forkdata.go +++ b/spec/phase0/forkdata.go @@ -58,6 +58,7 @@ func (f *ForkData) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &forkDataJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return f.unpack(&forkDataJSON) } @@ -97,6 +98,7 @@ func (f *ForkData) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -107,6 +109,7 @@ func (f *ForkData) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &forkDataJSON); err != nil { return err } + return f.unpack(&forkDataJSON) } @@ -116,5 +119,6 @@ func (f *ForkData) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/indexedattestation.go b/spec/phase0/indexedattestation.go index f0d24983..a3455cb4 100644 --- a/spec/phase0/indexedattestation.go +++ b/spec/phase0/indexedattestation.go @@ -53,6 +53,7 @@ func (i *IndexedAttestation) MarshalJSON() ([]byte, error) { for j := range i.AttestingIndices { attestingIndices[j] = fmt.Sprintf("%d", i.AttestingIndices[j]) } + return json.Marshal(&indexedAttestationJSON{ AttestingIndices: attestingIndices, Data: i.Data, @@ -66,6 +67,7 @@ func (i *IndexedAttestation) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &indexedAttestationJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return i.unpack(&indexedAttestationJSON) } @@ -113,6 +115,7 @@ func (i *IndexedAttestation) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -123,6 +126,7 @@ func (i *IndexedAttestation) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &indexedAttestationJSON); err != nil { return err } + return i.unpack(&indexedAttestationJSON) } @@ -132,5 +136,6 @@ func (i *IndexedAttestation) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/pendingattestation.go b/spec/phase0/pendingattestation.go index 4ce9f786..e088fd01 100644 --- a/spec/phase0/pendingattestation.go +++ b/spec/phase0/pendingattestation.go @@ -66,6 +66,7 @@ func (p *PendingAttestation) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &pendingAttestationJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return p.unpack(&pendingAttestationJSON) } @@ -112,6 +113,7 @@ func (p *PendingAttestation) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -122,6 +124,7 @@ func (p *PendingAttestation) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &pendingAttestationJSON); err != nil { return err } + return p.unpack(&pendingAttestationJSON) } @@ -131,5 +134,6 @@ func (p *PendingAttestation) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/proposerslashing.go b/spec/phase0/proposerslashing.go index 0f7f80f8..887c8bd3 100644 --- a/spec/phase0/proposerslashing.go +++ b/spec/phase0/proposerslashing.go @@ -54,6 +54,7 @@ func (p *ProposerSlashing) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &proposerSlashingJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return p.unpack(&proposerSlashingJSON) } @@ -79,6 +80,7 @@ func (p *ProposerSlashing) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -89,6 +91,7 @@ func (p *ProposerSlashing) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &proposerSlashingJSON); err != nil { return err } + return p.unpack(&proposerSlashingJSON) } @@ -98,5 +101,6 @@ func (p *ProposerSlashing) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/signedaggregateandproof.go b/spec/phase0/signedaggregateandproof.go index 1b525b71..ab1d4e06 100644 --- a/spec/phase0/signedaggregateandproof.go +++ b/spec/phase0/signedaggregateandproof.go @@ -56,6 +56,7 @@ func (s *SignedAggregateAndProof) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &signedAggregateAndProofJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&signedAggregateAndProofJSON) } @@ -88,6 +89,7 @@ func (s *SignedAggregateAndProof) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -98,6 +100,7 @@ func (s *SignedAggregateAndProof) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &signedAggregateAndProofJSON); err != nil { return err } + return s.unpack(&signedAggregateAndProofJSON) } @@ -107,5 +110,6 @@ func (s *SignedAggregateAndProof) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/signedbeaconblock.go b/spec/phase0/signedbeaconblock.go index e9deced0..b26465a7 100644 --- a/spec/phase0/signedbeaconblock.go +++ b/spec/phase0/signedbeaconblock.go @@ -56,6 +56,7 @@ func (s *SignedBeaconBlock) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &signedBeaconBlockJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&signedBeaconBlockJSON) } @@ -88,6 +89,7 @@ func (s *SignedBeaconBlock) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -98,6 +100,7 @@ func (s *SignedBeaconBlock) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &signedBeaconBlockJSON); err != nil { return err } + return s.unpack(&signedBeaconBlockJSON) } @@ -107,5 +110,6 @@ func (s *SignedBeaconBlock) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/signedbeaconblockheader.go b/spec/phase0/signedbeaconblockheader.go index a3619d9f..b55a52a9 100644 --- a/spec/phase0/signedbeaconblockheader.go +++ b/spec/phase0/signedbeaconblockheader.go @@ -56,6 +56,7 @@ func (s *SignedBeaconBlockHeader) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &signedBeaconBlockHeaderJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&signedBeaconBlockHeaderJSON) } @@ -85,6 +86,7 @@ func (s *SignedBeaconBlockHeader) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -95,6 +97,7 @@ func (s *SignedBeaconBlockHeader) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &signedBeaconBlockHeaderJSON); err != nil { return err } + return s.unpack(&signedBeaconBlockHeaderJSON) } @@ -104,5 +107,6 @@ func (s *SignedBeaconBlockHeader) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/signedvoluntaryexit.go b/spec/phase0/signedvoluntaryexit.go index dfbfd78a..f91bdf54 100644 --- a/spec/phase0/signedvoluntaryexit.go +++ b/spec/phase0/signedvoluntaryexit.go @@ -56,6 +56,7 @@ func (s *SignedVoluntaryExit) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &signedVoluntaryExitJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&signedVoluntaryExitJSON) } @@ -85,6 +86,7 @@ func (s *SignedVoluntaryExit) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -95,6 +97,7 @@ func (s *SignedVoluntaryExit) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &signedVoluntaryExitJSON); err != nil { return err } + return s.unpack(&signedVoluntaryExitJSON) } @@ -104,5 +107,6 @@ func (s *SignedVoluntaryExit) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/signingdata.go b/spec/phase0/signingdata.go index dbb0f884..c0e35fa2 100644 --- a/spec/phase0/signingdata.go +++ b/spec/phase0/signingdata.go @@ -56,6 +56,7 @@ func (s *SigningData) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &signingDataJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return s.unpack(&signingDataJSON) } @@ -95,6 +96,7 @@ func (s *SigningData) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -105,6 +107,7 @@ func (s *SigningData) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &signingDataJSON); err != nil { return err } + return s.unpack(&signingDataJSON) } @@ -114,5 +117,6 @@ func (s *SigningData) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/validator.go b/spec/phase0/validator.go index 1f244c13..21172bb1 100644 --- a/spec/phase0/validator.go +++ b/spec/phase0/validator.go @@ -81,6 +81,7 @@ func (v *Validator) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &validatorJSON); err != nil { return errors.Wrap(err, "invalid JSON") } + return v.unpack(&validatorJSON) } @@ -166,6 +167,7 @@ func (v *Validator) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -176,6 +178,7 @@ func (v *Validator) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &validatorJSON); err != nil { return err } + return v.unpack(&validatorJSON) } @@ -185,5 +188,6 @@ func (v *Validator) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/phase0/voluntaryexit.go b/spec/phase0/voluntaryexit.go index c0d33fc3..4b254efa 100644 --- a/spec/phase0/voluntaryexit.go +++ b/spec/phase0/voluntaryexit.go @@ -56,6 +56,7 @@ func (v *VoluntaryExit) UnmarshalJSON(input []byte) error { if err != nil { return errors.Wrap(err, "invalid JSON") } + return v.unpack(&voluntaryExitJSON) } @@ -89,6 +90,7 @@ func (v *VoluntaryExit) MarshalYAML() ([]byte, error) { if err != nil { return nil, err } + return bytes.ReplaceAll(yamlBytes, []byte(`"`), []byte(`'`)), nil } @@ -99,6 +101,7 @@ func (v *VoluntaryExit) UnmarshalYAML(input []byte) error { if err := yaml.Unmarshal(input, &voluntaryExitJSON); err != nil { return err } + return v.unpack(&voluntaryExitJSON) } @@ -108,5 +111,6 @@ func (v *VoluntaryExit) String() string { if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/spec/versionedbeaconblock.go b/spec/versionedbeaconblock.go index 5a0d9994..2a14f9ed 100644 --- a/spec/versionedbeaconblock.go +++ b/spec/versionedbeaconblock.go @@ -45,26 +45,31 @@ func (v *VersionedBeaconBlock) Slot() (phase0.Slot, error) { if v.Phase0 == nil { return 0, errors.New("no phase0 block") } + return v.Phase0.Slot, nil case DataVersionAltair: if v.Altair == nil { return 0, errors.New("no altair block") } + return v.Altair.Slot, nil case DataVersionBellatrix: if v.Bellatrix == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Slot, nil case DataVersionCapella: if v.Capella == nil { return 0, errors.New("no capella block") } + return v.Capella.Slot, nil case DataVersionDeneb: if v.Deneb == nil { return 0, errors.New("no deneb block contents") } + return v.Deneb.Slot, nil default: return 0, errors.New("unknown version") @@ -81,6 +86,7 @@ func (v *VersionedBeaconBlock) RandaoReveal() (phase0.BLSSignature, error) { if v.Phase0.Body == nil { return phase0.BLSSignature{}, errors.New("no phase0 block body") } + return v.Phase0.Body.RANDAOReveal, nil case DataVersionAltair: if v.Altair == nil { @@ -89,6 +95,7 @@ func (v *VersionedBeaconBlock) RandaoReveal() (phase0.BLSSignature, error) { if v.Altair.Body == nil { return phase0.BLSSignature{}, errors.New("no altair block body") } + return v.Altair.Body.RANDAOReveal, nil case DataVersionBellatrix: if v.Bellatrix == nil { @@ -97,6 +104,7 @@ func (v *VersionedBeaconBlock) RandaoReveal() (phase0.BLSSignature, error) { if v.Bellatrix.Body == nil { return phase0.BLSSignature{}, errors.New("no bellatrix block body") } + return v.Bellatrix.Body.RANDAOReveal, nil case DataVersionCapella: if v.Capella == nil { @@ -105,6 +113,7 @@ func (v *VersionedBeaconBlock) RandaoReveal() (phase0.BLSSignature, error) { if v.Capella.Body == nil { return phase0.BLSSignature{}, errors.New("no capella block body") } + return v.Capella.Body.RANDAOReveal, nil case DataVersionDeneb: if v.Deneb == nil { @@ -113,6 +122,7 @@ func (v *VersionedBeaconBlock) RandaoReveal() (phase0.BLSSignature, error) { if v.Deneb.Body == nil { return phase0.BLSSignature{}, errors.New("no deneb block body") } + return v.Deneb.Body.RANDAOReveal, nil default: return phase0.BLSSignature{}, errors.New("unknown version") @@ -129,6 +139,7 @@ func (v *VersionedBeaconBlock) Graffiti() ([32]byte, error) { if v.Phase0.Body == nil { return [32]byte{}, errors.New("no phase0 block body") } + return v.Phase0.Body.Graffiti, nil case DataVersionAltair: if v.Altair == nil { @@ -137,6 +148,7 @@ func (v *VersionedBeaconBlock) Graffiti() ([32]byte, error) { if v.Altair.Body == nil { return [32]byte{}, errors.New("no altair block body") } + return v.Altair.Body.Graffiti, nil case DataVersionBellatrix: if v.Bellatrix == nil { @@ -145,6 +157,7 @@ func (v *VersionedBeaconBlock) Graffiti() ([32]byte, error) { if v.Bellatrix.Body == nil { return [32]byte{}, errors.New("no bellatrix block body") } + return v.Bellatrix.Body.Graffiti, nil case DataVersionCapella: if v.Capella == nil { @@ -153,6 +166,7 @@ func (v *VersionedBeaconBlock) Graffiti() ([32]byte, error) { if v.Capella.Body == nil { return [32]byte{}, errors.New("no capella block body") } + return v.Capella.Body.Graffiti, nil case DataVersionDeneb: if v.Deneb == nil { @@ -161,6 +175,7 @@ func (v *VersionedBeaconBlock) Graffiti() ([32]byte, error) { if v.Deneb.Body == nil { return [32]byte{}, errors.New("no deneb block body") } + return v.Deneb.Body.Graffiti, nil default: return [32]byte{}, errors.New("unknown version") @@ -174,26 +189,31 @@ func (v *VersionedBeaconBlock) ProposerIndex() (phase0.ValidatorIndex, error) { if v.Phase0 == nil { return 0, errors.New("no phase0 block") } + return v.Phase0.ProposerIndex, nil case DataVersionAltair: if v.Altair == nil { return 0, errors.New("no altair block") } + return v.Altair.ProposerIndex, nil case DataVersionBellatrix: if v.Bellatrix == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.ProposerIndex, nil case DataVersionCapella: if v.Capella == nil { return 0, errors.New("no capella block") } + return v.Capella.ProposerIndex, nil case DataVersionDeneb: if v.Deneb == nil { return 0, errors.New("no deneb block contents") } + return v.Deneb.ProposerIndex, nil default: return 0, errors.New("unknown version") @@ -207,26 +227,31 @@ func (v *VersionedBeaconBlock) Root() (phase0.Root, error) { if v.Phase0 == nil { return phase0.Root{}, errors.New("no phase0 block") } + return v.Phase0.HashTreeRoot() case DataVersionAltair: if v.Altair == nil { return phase0.Root{}, errors.New("no altair block") } + return v.Altair.HashTreeRoot() case DataVersionBellatrix: if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.HashTreeRoot() case DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.HashTreeRoot() case DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block contents") } + return v.Deneb.HashTreeRoot() default: return phase0.Root{}, errors.New("unknown version") @@ -240,26 +265,31 @@ func (v *VersionedBeaconBlock) BodyRoot() (phase0.Root, error) { if v.Phase0 == nil { return phase0.Root{}, errors.New("no phase0 block") } + return v.Phase0.Body.HashTreeRoot() case DataVersionAltair: if v.Altair == nil { return phase0.Root{}, errors.New("no altair block") } + return v.Altair.Body.HashTreeRoot() case DataVersionBellatrix: if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Body.HashTreeRoot() case DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Body.HashTreeRoot() case DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block contents") } + return v.Deneb.Body.HashTreeRoot() default: return phase0.Root{}, errors.New("unknown version") @@ -273,26 +303,31 @@ func (v *VersionedBeaconBlock) ParentRoot() (phase0.Root, error) { if v.Phase0 == nil { return phase0.Root{}, errors.New("no phase0 block") } + return v.Phase0.ParentRoot, nil case DataVersionAltair: if v.Altair == nil { return phase0.Root{}, errors.New("no altair block") } + return v.Altair.ParentRoot, nil case DataVersionBellatrix: if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.ParentRoot, nil case DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.ParentRoot, nil case DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block contents") } + return v.Deneb.ParentRoot, nil default: return phase0.Root{}, errors.New("unknown version") @@ -306,26 +341,31 @@ func (v *VersionedBeaconBlock) StateRoot() (phase0.Root, error) { if v.Phase0 == nil { return phase0.Root{}, errors.New("no phase0 block") } + return v.Phase0.StateRoot, nil case DataVersionAltair: if v.Altair == nil { return phase0.Root{}, errors.New("no altair block") } + return v.Altair.StateRoot, nil case DataVersionBellatrix: if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.StateRoot, nil case DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.StateRoot, nil case DataVersionDeneb: if v.Deneb == nil { return phase0.Root{}, errors.New("no deneb block contents") } + return v.Deneb.StateRoot, nil default: return phase0.Root{}, errors.New("unknown version") @@ -339,26 +379,31 @@ func (v *VersionedBeaconBlock) Attestations() ([]*phase0.Attestation, error) { if v.Phase0 == nil || v.Phase0.Body == nil { return nil, errors.New("no phase0 block") } + return v.Phase0.Body.Attestations, nil case DataVersionAltair: if v.Altair == nil || v.Altair.Body == nil { return nil, errors.New("no altair block") } + return v.Altair.Body.Attestations, nil case DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Body.Attestations, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Body.Attestations, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Body.Attestations, nil default: return nil, errors.New("unknown version") @@ -372,26 +417,31 @@ func (v *VersionedBeaconBlock) AttesterSlashings() ([]*phase0.AttesterSlashing, if v.Phase0 == nil || v.Phase0.Body == nil { return nil, errors.New("no phase0 block") } + return v.Phase0.Body.AttesterSlashings, nil case DataVersionAltair: if v.Altair == nil || v.Altair.Body == nil { return nil, errors.New("no altair block") } + return v.Altair.Body.AttesterSlashings, nil case DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Body.AttesterSlashings, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Body.AttesterSlashings, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Body.AttesterSlashings, nil default: return nil, errors.New("unknown version") @@ -405,26 +455,31 @@ func (v *VersionedBeaconBlock) ProposerSlashings() ([]*phase0.ProposerSlashing, if v.Phase0 == nil || v.Phase0.Body == nil { return nil, errors.New("no phase0 block") } + return v.Phase0.Body.ProposerSlashings, nil case DataVersionAltair: if v.Altair == nil || v.Altair.Body == nil { return nil, errors.New("no altair block") } + return v.Altair.Body.ProposerSlashings, nil case DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Body.ProposerSlashings, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Body.ProposerSlashings, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Body.ProposerSlashings, nil default: return nil, errors.New("unknown version") @@ -438,26 +493,31 @@ func (v *VersionedBeaconBlock) String() string { if v.Phase0 == nil { return "" } + return v.Phase0.String() case DataVersionAltair: if v.Altair == nil { return "" } + return v.Altair.String() case DataVersionBellatrix: if v.Bellatrix == nil { return "" } + return v.Bellatrix.String() case DataVersionCapella: if v.Capella == nil { return "" } + return v.Capella.String() case DataVersionDeneb: if v.Deneb == nil { return "" } + return v.Deneb.String() default: return "unknown version" diff --git a/spec/versionedbeaconblockbody.go b/spec/versionedbeaconblockbody.go index a23a5a53..ae7fbf3e 100644 --- a/spec/versionedbeaconblockbody.go +++ b/spec/versionedbeaconblockbody.go @@ -38,26 +38,31 @@ func (v *VersionedBeaconBlockBody) String() string { if v.Phase0 == nil { return "" } + return v.Phase0.String() case DataVersionAltair: if v.Altair == nil { return "" } + return v.Altair.String() case DataVersionBellatrix: if v.Bellatrix == nil { return "" } + return v.Bellatrix.String() case DataVersionCapella: if v.Capella == nil { return "" } + return v.Capella.String() case DataVersionDeneb: if v.Deneb == nil { return "" } + return v.Deneb.String() default: return "unknown version" diff --git a/spec/versionedbeaconstate.go b/spec/versionedbeaconstate.go index 3aaaf14f..22c8c87b 100644 --- a/spec/versionedbeaconstate.go +++ b/spec/versionedbeaconstate.go @@ -45,26 +45,31 @@ func (v *VersionedBeaconState) Slot() (phase0.Slot, error) { if v.Phase0 == nil { return 0, errors.New("no Phase0 state") } + return v.Phase0.Slot, nil case DataVersionAltair: if v.Altair == nil { return 0, errors.New("no Altair state") } + return v.Altair.Slot, nil case DataVersionBellatrix: if v.Bellatrix == nil { return 0, errors.New("no Bellatrix state") } + return v.Bellatrix.Slot, nil case DataVersionCapella: if v.Capella == nil { return 0, errors.New("no Capella state") } + return v.Capella.Slot, nil case DataVersionDeneb: if v.Deneb == nil { return 0, errors.New("no Deneb state") } + return v.Deneb.Slot, nil default: return 0, errors.New("unknown version") @@ -80,11 +85,13 @@ func (v *VersionedBeaconState) NextWithdrawalValidatorIndex() (phase0.ValidatorI if v.Capella == nil { return 0, errors.New("no Capella state") } + return v.Capella.NextWithdrawalValidatorIndex, nil case DataVersionDeneb: if v.Deneb == nil { return 0, errors.New("no Deneb state") } + return v.Deneb.NextWithdrawalValidatorIndex, nil default: return 0, errors.New("unknown version") @@ -98,26 +105,31 @@ func (v *VersionedBeaconState) Validators() ([]*phase0.Validator, error) { if v.Phase0 == nil { return nil, errors.New("no Phase0 state") } + return v.Phase0.Validators, nil case DataVersionAltair: if v.Altair == nil { return nil, errors.New("no Altair state") } + return v.Altair.Validators, nil case DataVersionBellatrix: if v.Bellatrix == nil { return nil, errors.New("no Bellatrix state") } + return v.Bellatrix.Validators, nil case DataVersionCapella: if v.Capella == nil { return nil, errors.New("no Capella state") } + return v.Capella.Validators, nil case DataVersionDeneb: if v.Deneb == nil { return nil, errors.New("no Deneb state") } + return v.Deneb.Validators, nil default: return nil, errors.New("unknown version") @@ -131,26 +143,31 @@ func (v *VersionedBeaconState) ValidatorBalances() ([]phase0.Gwei, error) { if v.Phase0 == nil { return nil, errors.New("no Phase0 state") } + return v.Phase0.Balances, nil case DataVersionAltair: if v.Altair == nil { return nil, errors.New("no Altair state") } + return v.Altair.Balances, nil case DataVersionBellatrix: if v.Bellatrix == nil { return nil, errors.New("no Bellatrix state") } + return v.Bellatrix.Balances, nil case DataVersionCapella: if v.Capella == nil { return nil, errors.New("no Capella state") } + return v.Capella.Balances, nil case DataVersionDeneb: if v.Deneb == nil { return nil, errors.New("no Deneb state") } + return v.Deneb.Balances, nil default: return nil, errors.New("unknown version") @@ -164,26 +181,31 @@ func (v *VersionedBeaconState) String() string { if v.Phase0 == nil { return "" } + return v.Phase0.String() case DataVersionAltair: if v.Altair == nil { return "" } + return v.Altair.String() case DataVersionBellatrix: if v.Bellatrix == nil { return "" } + return v.Bellatrix.String() case DataVersionCapella: if v.Capella == nil { return "" } + return v.Capella.String() case DataVersionDeneb: if v.Deneb == nil { return "" } + return v.Deneb.String() default: return "unknown version" diff --git a/spec/versionedsignedbeaconblock.go b/spec/versionedsignedbeaconblock.go index 8cdf167c..148d91f8 100644 --- a/spec/versionedsignedbeaconblock.go +++ b/spec/versionedsignedbeaconblock.go @@ -40,26 +40,31 @@ func (v *VersionedSignedBeaconBlock) Slot() (phase0.Slot, error) { if v.Phase0 == nil || v.Phase0.Message == nil { return 0, errors.New("no phase0 block") } + return v.Phase0.Message.Slot, nil case DataVersionAltair: if v.Altair == nil || v.Altair.Message == nil { return 0, errors.New("no altair block") } + return v.Altair.Message.Slot, nil case DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Message == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Slot, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.Slot, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil { return 0, errors.New("no denb block") } + return v.Deneb.Message.Slot, nil default: return 0, errors.New("unknown version") @@ -73,26 +78,31 @@ func (v *VersionedSignedBeaconBlock) ProposerIndex() (phase0.ValidatorIndex, err if v.Phase0 == nil { return 0, errors.New("no phase0 block") } + return v.Phase0.Message.ProposerIndex, nil case DataVersionAltair: if v.Altair == nil { return 0, errors.New("no altair block") } + return v.Altair.Message.ProposerIndex, nil case DataVersionBellatrix: if v.Bellatrix == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.ProposerIndex, nil case DataVersionCapella: if v.Capella == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.ProposerIndex, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil { return 0, errors.New("no deneb block") } + return v.Deneb.Message.ProposerIndex, nil default: return 0, errors.New("unknown version") @@ -106,16 +116,19 @@ func (v *VersionedSignedBeaconBlock) ExecutionBlockHash() (phase0.Hash32, error) if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayload == nil { return phase0.Hash32{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ExecutionPayload.BlockHash, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayload == nil { return phase0.Hash32{}, errors.New("no capella block") } + return v.Capella.Message.Body.ExecutionPayload.BlockHash, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil || v.Deneb.Message.Body.ExecutionPayload == nil { return phase0.Hash32{}, errors.New("no denb block") } + return v.Deneb.Message.Body.ExecutionPayload.BlockHash, nil default: return phase0.Hash32{}, errors.New("unknown version") @@ -129,22 +142,26 @@ func (v *VersionedSignedBeaconBlock) ExecutionBlockNumber() (uint64, error) { if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayload == nil { return 0, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ExecutionPayload.BlockNumber, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayload == nil { return 0, errors.New("no capella block") } + return v.Capella.Message.Body.ExecutionPayload.BlockNumber, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil || v.Deneb.Message.Body.ExecutionPayload == nil { return 0, errors.New("no deneb block") } + return v.Deneb.Message.Body.ExecutionPayload.BlockNumber, nil default: return 0, errors.New("unknown version") } } +// ExecutionTransactions returs the execution payload transactions for the block. func (v *VersionedSignedBeaconBlock) ExecutionTransactions() ([]bellatrix.Transaction, error) { switch v.Version { case DataVersionPhase0: @@ -155,48 +172,57 @@ func (v *VersionedSignedBeaconBlock) ExecutionTransactions() ([]bellatrix.Transa if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil || v.Bellatrix.Message.Body.ExecutionPayload == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ExecutionPayload.Transactions, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayload == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.ExecutionPayload.Transactions, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil || v.Deneb.Message.Body.ExecutionPayload == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.ExecutionPayload.Transactions, nil default: return nil, errors.New("unknown version") } } +// Graffiti returns the graffiti for the block. func (v *VersionedSignedBeaconBlock) Graffiti() ([32]byte, error) { switch v.Version { case DataVersionPhase0: if v.Phase0 == nil || v.Phase0.Message == nil || v.Phase0.Message.Body == nil { return [32]byte{}, errors.New("no phase0 block") } + return v.Phase0.Message.Body.Graffiti, nil case DataVersionAltair: if v.Altair == nil || v.Altair.Message == nil || v.Altair.Message.Body == nil { return [32]byte{}, errors.New("no altair block") } + return v.Altair.Message.Body.Graffiti, nil case DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return [32]byte{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.Graffiti, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayload == nil { return [32]byte{}, errors.New("no capella block") } + return v.Capella.Message.Body.Graffiti, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil || v.Deneb.Message.Body.ExecutionPayload == nil { return [32]byte{}, errors.New("no deneb block") } + return v.Deneb.Message.Body.Graffiti, nil default: return [32]byte{}, errors.New("unknown version") @@ -210,26 +236,31 @@ func (v *VersionedSignedBeaconBlock) Attestations() ([]*phase0.Attestation, erro if v.Phase0 == nil || v.Phase0.Message == nil || v.Phase0.Message.Body == nil { return nil, errors.New("no phase0 block") } + return v.Phase0.Message.Body.Attestations, nil case DataVersionAltair: if v.Altair == nil || v.Altair.Message == nil || v.Altair.Message.Body == nil { return nil, errors.New("no altair block") } + return v.Altair.Message.Body.Attestations, nil case DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.Attestations, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.Attestations, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.Attestations, nil default: return nil, errors.New("unknown version") @@ -243,26 +274,31 @@ func (v *VersionedSignedBeaconBlock) Root() (phase0.Root, error) { if v.Phase0 == nil { return phase0.Root{}, errors.New("no phase0 block") } + return v.Phase0.Message.HashTreeRoot() case DataVersionAltair: if v.Altair == nil { return phase0.Root{}, errors.New("no altair block") } + return v.Altair.Message.HashTreeRoot() case DataVersionBellatrix: if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.HashTreeRoot() case DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.HashTreeRoot() case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Message.HashTreeRoot() default: return phase0.Root{}, errors.New("unknown version") @@ -276,26 +312,31 @@ func (v *VersionedSignedBeaconBlock) BodyRoot() (phase0.Root, error) { if v.Phase0 == nil { return phase0.Root{}, errors.New("no phase0 block") } + return v.Phase0.Message.Body.HashTreeRoot() case DataVersionAltair: if v.Altair == nil { return phase0.Root{}, errors.New("no altair block") } + return v.Altair.Message.Body.HashTreeRoot() case DataVersionBellatrix: if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.HashTreeRoot() case DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.Body.HashTreeRoot() case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Message.Body.HashTreeRoot() default: return phase0.Root{}, errors.New("unknown version") @@ -309,26 +350,31 @@ func (v *VersionedSignedBeaconBlock) ParentRoot() (phase0.Root, error) { if v.Phase0 == nil { return phase0.Root{}, errors.New("no phase0 block") } + return v.Phase0.Message.ParentRoot, nil case DataVersionAltair: if v.Altair == nil { return phase0.Root{}, errors.New("no altair block") } + return v.Altair.Message.ParentRoot, nil case DataVersionBellatrix: if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.ParentRoot, nil case DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.ParentRoot, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Message.ParentRoot, nil default: return phase0.Root{}, errors.New("unknown version") @@ -342,26 +388,31 @@ func (v *VersionedSignedBeaconBlock) StateRoot() (phase0.Root, error) { if v.Phase0 == nil { return phase0.Root{}, errors.New("no phase0 block") } + return v.Phase0.Message.StateRoot, nil case DataVersionAltair: if v.Altair == nil { return phase0.Root{}, errors.New("no altair block") } + return v.Altair.Message.StateRoot, nil case DataVersionBellatrix: if v.Bellatrix == nil { return phase0.Root{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.StateRoot, nil case DataVersionCapella: if v.Capella == nil { return phase0.Root{}, errors.New("no capella block") } + return v.Capella.Message.StateRoot, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil { return phase0.Root{}, errors.New("no deneb block") } + return v.Deneb.Message.StateRoot, nil default: return phase0.Root{}, errors.New("unknown version") @@ -375,26 +426,31 @@ func (v *VersionedSignedBeaconBlock) RandaoReveal() (phase0.BLSSignature, error) if v.Phase0 == nil || v.Phase0.Message == nil || v.Phase0.Message.Body == nil { return phase0.BLSSignature{}, errors.New("no phase0 block") } + return v.Phase0.Message.Body.RANDAOReveal, nil case DataVersionAltair: if v.Altair == nil || v.Altair.Message == nil || v.Altair.Message.Body == nil { return phase0.BLSSignature{}, errors.New("no altair block") } + return v.Altair.Message.Body.RANDAOReveal, nil case DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return phase0.BLSSignature{}, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.RANDAOReveal, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return phase0.BLSSignature{}, errors.New("no capella block") } + return v.Capella.Message.Body.RANDAOReveal, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return phase0.BLSSignature{}, errors.New("no deneb block") } + return v.Deneb.Message.Body.RANDAOReveal, nil default: return phase0.BLSSignature{}, errors.New("unknown version") @@ -408,26 +464,31 @@ func (v *VersionedSignedBeaconBlock) ETH1Data() (*phase0.ETH1Data, error) { if v.Phase0 == nil || v.Phase0.Message == nil || v.Phase0.Message.Body == nil { return nil, errors.New("no phase0 block") } + return v.Phase0.Message.Body.ETH1Data, nil case DataVersionAltair: if v.Altair == nil || v.Altair.Message == nil || v.Altair.Message.Body == nil { return nil, errors.New("no altair block") } + return v.Altair.Message.Body.ETH1Data, nil case DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ETH1Data, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.ETH1Data, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.ETH1Data, nil default: return nil, errors.New("unknown version") @@ -441,26 +502,31 @@ func (v *VersionedSignedBeaconBlock) Deposits() ([]*phase0.Deposit, error) { if v.Phase0 == nil || v.Phase0.Message == nil || v.Phase0.Message.Body == nil { return nil, errors.New("no phase0 block") } + return v.Phase0.Message.Body.Deposits, nil case DataVersionAltair: if v.Altair == nil || v.Altair.Message == nil || v.Altair.Message.Body == nil { return nil, errors.New("no altair block") } + return v.Altair.Message.Body.Deposits, nil case DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.Deposits, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.Deposits, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.Deposits, nil default: return nil, errors.New("unknown version") @@ -474,26 +540,31 @@ func (v *VersionedSignedBeaconBlock) VoluntaryExits() ([]*phase0.SignedVoluntary if v.Phase0 == nil || v.Phase0.Message == nil || v.Phase0.Message.Body == nil { return nil, errors.New("no phase0 block") } + return v.Phase0.Message.Body.VoluntaryExits, nil case DataVersionAltair: if v.Altair == nil || v.Altair.Message == nil || v.Altair.Message.Body == nil { return nil, errors.New("no altair block") } + return v.Altair.Message.Body.VoluntaryExits, nil case DataVersionBellatrix: if v.Bellatrix == nil || v.Bellatrix.Message == nil || v.Bellatrix.Message.Body == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.VoluntaryExits, nil case DataVersionCapella: if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.VoluntaryExits, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.VoluntaryExits, nil default: return nil, errors.New("unknown version") @@ -507,26 +578,31 @@ func (v *VersionedSignedBeaconBlock) AttesterSlashings() ([]*phase0.AttesterSlas if v.Phase0 == nil { return nil, errors.New("no phase0 block") } + return v.Phase0.Message.Body.AttesterSlashings, nil case DataVersionAltair: if v.Altair == nil { return nil, errors.New("no altair block") } + return v.Altair.Message.Body.AttesterSlashings, nil case DataVersionBellatrix: if v.Bellatrix == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.AttesterSlashings, nil case DataVersionCapella: if v.Capella == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.AttesterSlashings, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.AttesterSlashings, nil default: return nil, errors.New("unknown version") @@ -540,26 +616,31 @@ func (v *VersionedSignedBeaconBlock) ProposerSlashings() ([]*phase0.ProposerSlas if v.Phase0 == nil { return nil, errors.New("no phase0 block") } + return v.Phase0.Message.Body.ProposerSlashings, nil case DataVersionAltair: if v.Altair == nil { return nil, errors.New("no altair block") } + return v.Altair.Message.Body.ProposerSlashings, nil case DataVersionBellatrix: if v.Bellatrix == nil { return nil, errors.New("no bellatrix block") } + return v.Bellatrix.Message.Body.ProposerSlashings, nil case DataVersionCapella: if v.Capella == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.ProposerSlashings, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.ProposerSlashings, nil default: return nil, errors.New("unknown version") @@ -575,21 +656,25 @@ func (v *VersionedSignedBeaconBlock) SyncAggregate() (*altair.SyncAggregate, err 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 || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.SyncAggregate, nil default: return nil, errors.New("unknown version") @@ -609,11 +694,13 @@ func (v *VersionedSignedBeaconBlock) BLSToExecutionChanges() ([]*capella.SignedB if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.BLSToExecutionChanges, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.BLSToExecutionChanges, nil default: return nil, errors.New("unknown version") @@ -633,11 +720,13 @@ func (v *VersionedSignedBeaconBlock) Withdrawals() ([]*capella.Withdrawal, error if v.Capella == nil || v.Capella.Message == nil || v.Capella.Message.Body == nil || v.Capella.Message.Body.ExecutionPayload == nil { return nil, errors.New("no capella block") } + return v.Capella.Message.Body.ExecutionPayload.Withdrawals, nil case DataVersionDeneb: if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil || v.Deneb.Message.Body.ExecutionPayload == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.ExecutionPayload.Withdrawals, nil default: return nil, errors.New("unknown version") @@ -657,6 +746,7 @@ func (v *VersionedSignedBeaconBlock) BlobKzgCommitments() ([]deneb.KzgCommitment if v.Deneb == nil || v.Deneb.Message == nil || v.Deneb.Message.Body == nil { return nil, errors.New("no deneb block") } + return v.Deneb.Message.Body.BlobKzgCommitments, nil default: return nil, errors.New("unknown version") @@ -670,26 +760,31 @@ func (v *VersionedSignedBeaconBlock) String() string { if v.Phase0 == nil { return "" } + return v.Phase0.String() case DataVersionAltair: if v.Altair == nil { return "" } + return v.Altair.String() case DataVersionBellatrix: if v.Bellatrix == nil { return "" } + return v.Bellatrix.String() case DataVersionCapella: if v.Capella == nil { return "" } + return v.Capella.String() case DataVersionDeneb: if v.Deneb == nil { return "" } + return v.Deneb.String() default: return "unknown version" diff --git a/testclients/erroring.go b/testclients/erroring.go index 584f3a87..194ee67a 100644 --- a/testclients/erroring.go +++ b/testclients/erroring.go @@ -59,12 +59,14 @@ func NewErroring(_ context.Context, // Name returns the name of the client implementation. func (s *Erroring) Name() string { nextName := s.next.Name() + return fmt.Sprintf("erroring(%v,%s)", s.errorRate, nextName) } // Address returns the address of the client. func (s *Erroring) Address() string { nextAddress := s.next.Address() + return fmt.Sprintf("erroring:%v,%s", s.errorRate, nextAddress) } @@ -75,6 +77,7 @@ func (s *Erroring) maybeError(_ context.Context) error { if roll < s.errorRate { return errors.New("error") } + return nil } @@ -786,7 +789,7 @@ func (s *Erroring) BeaconStateRoot(ctx context.Context, return next.BeaconStateRoot(ctx, opts) } -// Fork fetches the node's current fork choice context. +// ForkChoice fetches the node's current fork choice context. func (s *Erroring) ForkChoice(ctx context.Context) (*api.Response[*apiv1.ForkChoice], error) { if err := s.maybeError(ctx); err != nil { return nil, err diff --git a/testclients/sleepy.go b/testclients/sleepy.go index 0a696961..2461328f 100644 --- a/testclients/sleepy.go +++ b/testclients/sleepy.go @@ -60,12 +60,14 @@ func NewSleepy(_ context.Context, // Name returns the name of the client implementation. func (s *Sleepy) Name() string { nextName := s.next.Name() + return fmt.Sprintf("sleepy(%v,%v,%s)", s.minSleep, s.maxSleep, nextName) } // Address returns the address of the client. func (s *Sleepy) Address() string { nextAddress := s.next.Address() + return fmt.Sprintf("sleepy:%v,%v,%s", s.minSleep, s.maxSleep, nextAddress) }