From f219233e341a0c51c03d7e07c54ee6b6181fcf99 Mon Sep 17 00:00:00 2001 From: Niclas Blomberg Date: Mon, 12 Feb 2024 18:59:59 +0100 Subject: [PATCH] feat: parse ssz payloads from auction-api --- datastore/auction_api.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/datastore/auction_api.go b/datastore/auction_api.go index 6f29ce24..be62d09f 100644 --- a/datastore/auction_api.go +++ b/datastore/auction_api.go @@ -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)) @@ -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) {