Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add BlockHash() to versioned signed beacon block #63

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions spec/versionedsignedbeaconblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ func (v *VersionedSignedBeaconBlock) Slot() (phase0.Slot, error) {
}
}

// ExecutionBlockHash returns the block hash of the beacon block.
func (v *VersionedSignedBeaconBlock) ExecutionBlockHash() (phase0.Hash32, error) {
switch v.Version {
case DataVersionBellatrix:
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.Bellatrix.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.Bellatrix.Message.Body.ExecutionPayload.BlockHash, nil
default:
return phase0.Hash32{}, errors.New("unknown version")
}
}

// Attestations returns the attestations of the beacon block.
func (v *VersionedSignedBeaconBlock) Attestations() ([]*phase0.Attestation, error) {
switch v.Version {
Expand Down