Skip to content

Commit

Permalink
Add BlockHash() to versioned signed beacon block
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Jul 20, 2023
1 parent dfcc05c commit 8208134
Showing 1 changed file with 23 additions and 0 deletions.
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) {
}
}

// BlockHash returns the block hash of the beacon block.
func (v *VersionedSignedBeaconBlock) BlockHash() (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

0 comments on commit 8208134

Please sign in to comment.