Skip to content

Commit

Permalink
Merge pull request #94 from avalonche/add-proposal-functions
Browse files Browse the repository at this point in the history
Add helper functions for signed proposal
  • Loading branch information
mcdee authored Nov 22, 2023
2 parents de3582f + f072b1d commit 677e489
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions api/versionedsignedproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,42 @@ func (v *VersionedSignedProposal) Slot() (phase0.Slot, error) {
}
}

// ExecutionBlockHash returns the hash of the execution payload.
func (v *VersionedSignedProposal) ExecutionBlockHash() (phase0.Hash32, error) {
switch v.Version {
case spec.DataVersionBellatrix:
if v.Bellatrix == nil ||
v.Bellatrix.Message == nil ||
v.Bellatrix.Message.Body == nil ||
v.Bellatrix.Message.Body.ExecutionPayload == nil {
return phase0.Hash32{}, ErrDataMissing
}

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{}, ErrDataMissing
}

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{}, ErrDataMissing
}

return v.Deneb.SignedBlock.Message.Body.ExecutionPayload.BlockHash, nil
default:
return phase0.Hash32{}, ErrUnsupportedVersion
}
}

// String returns a string version of the structure.
func (v *VersionedSignedProposal) String() string {
switch v.Version {
Expand Down

0 comments on commit 677e489

Please sign in to comment.