Skip to content

Commit

Permalink
Merge pull request #63 from avalonche/add-versioned-signed-beacon-blo…
Browse files Browse the repository at this point in the history
…ck-helper

Add ExecutionBlockHash() to versioned signed beacon block
  • Loading branch information
mcdee authored Jul 28, 2023
2 parents f4117cf + f3a83af commit bc2888a
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) {
}
}

// 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

0 comments on commit bc2888a

Please sign in to comment.