Skip to content

Commit

Permalink
use marshaller from original builder
Browse files Browse the repository at this point in the history
  • Loading branch information
jinmel committed Sep 9, 2024
1 parent 3e4dd7e commit 7423f5c
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,54 @@ type denebVersionedExecutionPayloadJSON struct {
Data *deneb.ExecutionPayload `json:"data"`
}

func (v *VersionedExecutionPayload) MarshalJSON() ([]byte, error) {
version := &versionJSON{
Version: v.Version,
}
switch v.Version {
case spec.DataVersionBellatrix:
if v.Bellatrix == nil {
return nil, errors.New("no bellatrix data")
}
data := &bellatrixVersionedExecutionPayloadJSON{
Data: v.Bellatrix,
}
payload := struct {
*versionJSON
*bellatrixVersionedExecutionPayloadJSON
}{version, data}

return json.Marshal(payload)
case spec.DataVersionCapella:
if v.Capella == nil {
return nil, errors.New("no capella data")
}
data := &capellaVersionedExecutionPayloadJSON{
Data: v.Capella,
}
payload := struct {
*versionJSON
*capellaVersionedExecutionPayloadJSON
}{version, data}

return json.Marshal(payload)
case spec.DataVersionDeneb:
if v.Deneb == nil {
return nil, errors.New("no deneb data")
}
data := &denebVersionedExecutionPayloadJSON{
Data: v.Deneb,
}
payload := struct {
*versionJSON
*denebVersionedExecutionPayloadJSON
}{version, data}
return json.Marshal(payload)
default:
return nil, fmt.Errorf("unsupported data version %v", v.Version)
}
}

// BuilderArgs is a struct that contains all the arguments needed to create a new Builder
type BuilderArgs struct {
sk *bls.SecretKey
Expand Down Expand Up @@ -268,10 +316,8 @@ func (b *Builder) handleGetPayload(w http.ResponseWriter, req *http.Request) {
}

versionedExecutionPayload := &VersionedExecutionPayload{
Version: bestSubmission.Version,
Bellatrix: nil,
Capella: nil,
Deneb: bestSubmission.Deneb.ExecutionPayload,
Version: bestSubmission.Version,
Deneb: bestSubmission.Deneb.ExecutionPayload,
}

w.Header().Set("Content-Type", "application/json")
Expand Down

0 comments on commit 7423f5c

Please sign in to comment.