From 91c9a241729e66559e02ae7c2b9b049e50c608a3 Mon Sep 17 00:00:00 2001 From: avalonche Date: Thu, 20 Jul 2023 16:11:27 +1000 Subject: [PATCH 1/2] Add BlockHash() to versioned signed beacon block --- spec/versionedsignedbeaconblock.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/versionedsignedbeaconblock.go b/spec/versionedsignedbeaconblock.go index 77676820..dfbe678f 100644 --- a/spec/versionedsignedbeaconblock.go +++ b/spec/versionedsignedbeaconblock.go @@ -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 { From f3a83af47918e8899c1404760b544777749eaa86 Mon Sep 17 00:00:00 2001 From: avalonche Date: Sat, 29 Jul 2023 02:02:20 +1000 Subject: [PATCH 2/2] renaming --- spec/versionedsignedbeaconblock.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/versionedsignedbeaconblock.go b/spec/versionedsignedbeaconblock.go index dfbe678f..afdd4a90 100644 --- a/spec/versionedsignedbeaconblock.go +++ b/spec/versionedsignedbeaconblock.go @@ -66,8 +66,8 @@ func (v *VersionedSignedBeaconBlock) Slot() (phase0.Slot, error) { } } -// BlockHash returns the block hash of the beacon block. -func (v *VersionedSignedBeaconBlock) BlockHash() (phase0.Hash32, 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 {