diff --git a/go.mod b/go.mod index 938b0b1..f930a78 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/attestantio/go-eth2-client v0.21.9 github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9 github.com/creasty/defaults v1.6.0 - github.com/ethpandaops/beacon v0.42.1-0.20241023053323-d1834c10e236 + github.com/ethpandaops/beacon v0.42.1-0.20241024060031-8e0b4cd9bc1f github.com/ethpandaops/ethwallclock v0.2.0 github.com/go-co-op/gocron v1.18.0 github.com/julienschmidt/httprouter v1.3.0 diff --git a/go.sum b/go.sum index afb5b45..7e85571 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1 github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= github.com/ethereum/go-ethereum v1.14.10 h1:kC24WjYeRjDy86LVo6MfF5Xs7nnUu+XG4AjaYIaZYko= github.com/ethereum/go-ethereum v1.14.10/go.mod h1:+l/fr42Mma+xBnhefL/+z11/hcmJ2egl+ScIVPjhc7E= -github.com/ethpandaops/beacon v0.42.1-0.20241023053323-d1834c10e236 h1:f9W5dVimoPqaf3tuOdc6CdBr9e+Ot1hTqBRfsfurAek= -github.com/ethpandaops/beacon v0.42.1-0.20241023053323-d1834c10e236/go.mod h1:hKfalJGsF4BuWPwcGCX/4fdQR31zDJVaTLWwrkfNTzw= +github.com/ethpandaops/beacon v0.42.1-0.20241024060031-8e0b4cd9bc1f h1:RWIj9+8C2AW6VUXNguXgDPgXZ0UKAi52rIuO/05mq+I= +github.com/ethpandaops/beacon v0.42.1-0.20241024060031-8e0b4cd9bc1f/go.mod h1:hKfalJGsF4BuWPwcGCX/4fdQR31zDJVaTLWwrkfNTzw= github.com/ethpandaops/ethwallclock v0.2.0 h1:EeFKtZ7v6TAdn/oAh0xaPujD7N4amjBxrWIByraUfLM= github.com/ethpandaops/ethwallclock v0.2.0/go.mod h1:y0Cu+mhGLlem19vnAV2x0hpFS5KZ7oOi2SWYayv9l24= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= diff --git a/pkg/api/handler.go b/pkg/api/handler.go index 8eebe92..6e0831f 100644 --- a/pkg/api/handler.go +++ b/pkg/api/handler.go @@ -744,7 +744,7 @@ func (h *Handler) handleEthV1BeaconLightClientUpdates(ctx context.Context, r *ht return NewBadRequestResponse(nil), fmt.Errorf("invalid count: %w", err) } - updates, version, err := h.eth.LightClientUpdates(ctx, startPeriodInt, countInt) + updates, _, err := h.eth.LightClientUpdates(ctx, startPeriodInt, countInt) if err != nil { return NewInternalServerErrorResponse(nil), err } @@ -755,7 +755,7 @@ func (h *Handler) handleEthV1BeaconLightClientUpdates(ctx context.Context, r *ht }, }) - rsp.ExtraData["version"] = version + rsp.IsMultipleResponses = true return rsp, nil } diff --git a/pkg/api/response.go b/pkg/api/response.go index 6af580b..6fa59f2 100644 --- a/pkg/api/response.go +++ b/pkg/api/response.go @@ -10,10 +10,11 @@ type ContentTypeResolver func() ([]byte, error) type ContentTypeResolvers map[ContentType]ContentTypeResolver type HTTPResponse struct { - resolvers ContentTypeResolvers - StatusCode int `json:"status_code"` - Headers map[string]string `json:"headers"` - ExtraData map[string]interface{} + resolvers ContentTypeResolvers + StatusCode int `json:"status_code"` + Headers map[string]string `json:"headers"` + ExtraData map[string]interface{} + IsMultipleResponses bool } type jsonResponse struct { Data json.RawMessage `json:"data"` @@ -22,6 +23,9 @@ type jsonResponse struct { Version string `json:"version,omitempty"` } +// multipleJSONResponse is a wrapper for multiple json responses. +type multipleJSONResponse []jsonResponse + func (r HTTPResponse) MarshalAs(contentType ContentType) ([]byte, error) { if _, exists := r.resolvers[contentType]; !exists { return nil, fmt.Errorf("unsupported content-type: %s", contentType.String()) @@ -31,6 +35,10 @@ func (r HTTPResponse) MarshalAs(contentType ContentType) ([]byte, error) { return r.resolvers[contentType]() } + if r.IsMultipleResponses { + return r.buildWrappedJSONResponses() + } + return r.buildWrappedJSONResponse() } @@ -110,3 +118,12 @@ func (r *HTTPResponse) buildWrappedJSONResponse() ([]byte, error) { return json.Marshal(rsp) } + +func (r *HTTPResponse) buildWrappedJSONResponses() ([]byte, error) { + data, err := r.resolvers[ContentTypeJSON]() + if err != nil { + return nil, err + } + + return data, nil +} diff --git a/pkg/service/eth/eth.go b/pkg/service/eth/eth.go index 44faf57..5f20db6 100644 --- a/pkg/service/eth/eth.go +++ b/pkg/service/eth/eth.go @@ -690,15 +690,5 @@ func (h *Handler) LightClientUpdates(ctx context.Context, startPeriod, count int return nil, "", err } - v, ok := rsp.Metadata["version"] - if !ok { - return nil, "", fmt.Errorf("version not found") - } - - ver, ok := v.(string) - if !ok { - return nil, "", fmt.Errorf("version is not a string") - } - - return rsp.Data, ver, nil + return rsp.Data, "", nil }