Skip to content

Commit

Permalink
chore(mev-boost): unmarshal json builder bid with proof
Browse files Browse the repository at this point in the history
  • Loading branch information
namn-grg committed Oct 8, 2024
1 parent 8674eae commit a920bdd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mev-boost/server/mock_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (m *mockRelay) defaultHandleGetHeaderWithProofs(w http.ResponseWriter) {
"0xe28385e7bd68df656cd0042b74b69c3104b5356ed1f20eb69f1f925df47a3ab7",
"0xe28385e7bd68df656cd0042b74b69c3104b5356ed1f20eb69f1f925df47a3ab7",
"0x8a1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249",
spec.DataVersionCapella,
spec.DataVersionDeneb,
nil,
)

Expand Down
63 changes: 63 additions & 0 deletions mev-boost/server/proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,69 @@ func (v *VersionedSignedBuilderBidWithProofs) MarshalJSON() ([]byte, error) {
return nil, fmt.Errorf("unknown data version %d", v.Version)
}

func (v *VersionedSignedBuilderBidWithProofs) UnmarshalJSON(data []byte) error {
var err error

// Try Deneb
var deneb struct {
Message *builderApiDeneb.BuilderBid `json:"message"`
Signature phase0.BLSSignature `json:"signature"`
Proofs *InclusionProof `json:"proofs"`
}
err = json.Unmarshal(data, &deneb)
if err == nil && deneb.Message != nil {
v.Proofs = deneb.Proofs

v.VersionedSignedBuilderBid = &builderSpec.VersionedSignedBuilderBid{}
v.Deneb = &builderApiDeneb.SignedBuilderBid{
Message: deneb.Message,
Signature: deneb.Signature,
}
v.Version = consensusSpec.DataVersionDeneb
return nil
}

// Try Capella
var capella struct {
Message *builderApiCapella.BuilderBid `json:"message"`
Signature phase0.BLSSignature `json:"signature"`
Proofs *InclusionProof `json:"proofs"`
}
err = json.Unmarshal(data, &capella)
if err == nil && capella.Message != nil {
v.Proofs = capella.Proofs

v.VersionedSignedBuilderBid = &builderSpec.VersionedSignedBuilderBid{}
v.Capella = &builderApiCapella.SignedBuilderBid{
Message: capella.Message,
Signature: capella.Signature,
}
v.Version = consensusSpec.DataVersionCapella
return nil
}

// Try Bellatrix
var bellatrix struct {
Message *builderApiBellatrix.BuilderBid `json:"message"`
Signature phase0.BLSSignature `json:"signature"`
Proofs *InclusionProof `json:"proofs"`
}
err = json.Unmarshal(data, &bellatrix)
if err == nil && bellatrix.Message != nil {
v.Proofs = bellatrix.Proofs

v.VersionedSignedBuilderBid = &builderSpec.VersionedSignedBuilderBid{}
v.Bellatrix = &builderApiBellatrix.SignedBuilderBid{
Message: bellatrix.Message,
Signature: bellatrix.Signature,
}
v.Version = consensusSpec.DataVersionBellatrix
return nil
}

return fmt.Errorf("failed to unmarshal VersionedSignedBuilderBidWithProofs: %v", err)
}

func (v *VersionedSignedBuilderBidWithProofs) String() string {
return JSONStringify(v)
}
Expand Down

0 comments on commit a920bdd

Please sign in to comment.