Skip to content

Commit

Permalink
feat: parse ssz payloads from auction-api
Browse files Browse the repository at this point in the history
  • Loading branch information
blombern authored and alextes committed May 1, 2024
1 parent f0763d4 commit f219233
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions datastore/auction_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ import (
"net/url"

builderApi "github.com/attestantio/go-builder-client/api"
builderApiDeneb "github.com/attestantio/go-builder-client/api/deneb"
"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/flashbots/mev-boost-relay/common"
"github.com/pkg/errors"
)

const API_ROOT = "http://turbo-auction-api"

var ErrFailedToParsePayload = errors.New("failed to parse payload")

func GetPayloadContents(slot uint64, proposerPubkey, blockHash string) (*builderApi.VersionedSubmitBlindedBlockResponse, error) {
queryParams := url.Values{}
queryParams.Add("slot", fmt.Sprintf("%d", slot))
Expand All @@ -38,13 +44,29 @@ func GetPayloadContents(slot uint64, proposerPubkey, blockHash string) (*builder
return nil, err
}

payload := new(builderApi.VersionedSubmitBlindedBlockResponse)
err = json.Unmarshal(body, &payload)
if err != nil {
return nil, err
// Try to parse deneb contents
denebPayloadContents := new(builderApiDeneb.ExecutionPayloadAndBlobsBundle)
err = denebPayloadContents.UnmarshalSSZ([]byte(body))

if err == nil {
return &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionDeneb,
Deneb: denebPayloadContents,
}, nil
}

// Try to parse capella payload
capellaPayload := new(capella.ExecutionPayload)
err = capellaPayload.UnmarshalSSZ([]byte(body))

if err == nil {
return &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionCapella,
Capella: capellaPayload,
}, nil
}

return payload, nil
return nil, ErrFailedToParsePayload
}

func GetBidTrace(slot uint64, proposerPubkey, blockHash string) (*common.BidTraceV2, error) {
Expand Down

0 comments on commit f219233

Please sign in to comment.