From ee48aecbe6fe068da13284be544614572e884eb7 Mon Sep 17 00:00:00 2001 From: Giulio Date: Fri, 31 May 2024 16:27:44 +0200 Subject: [PATCH 1/2] save --- cl/beacon/beaconhttp/args.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cl/beacon/beaconhttp/args.go b/cl/beacon/beaconhttp/args.go index 1701620b074..5bbb115171a 100644 --- a/cl/beacon/beaconhttp/args.go +++ b/cl/beacon/beaconhttp/args.go @@ -5,6 +5,7 @@ import ( "net/http" "regexp" "strconv" + "strings" "github.com/go-chi/chi/v5" "github.com/ledgerwatch/erigon-lib/common" @@ -168,9 +169,13 @@ func Uint64FromQueryParams(r *http.Request, name string) (*uint64, error) { // decode a list of strings from the query params func StringListFromQueryParams(r *http.Request, name string) ([]string, error) { - str := r.URL.Query().Get(name) - if str == "" { + values := r.URL.Query()[name] + if len(values) == 0 { return nil, nil } + + // Combine all values into a single string, separating by comma + str := strings.Join(values, ",") + return regexp.MustCompile(`\s*,\s*`).Split(str, -1), nil } From 645051b7b6c14ecdffa3b4c89a9c9d9c5fc98e95 Mon Sep 17 00:00:00 2001 From: Giulio Date: Fri, 31 May 2024 16:40:39 +0200 Subject: [PATCH 2/2] save --- cl/beacon/handler/blobs.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/cl/beacon/handler/blobs.go b/cl/beacon/handler/blobs.go index 18e11a98633..8b006ec4d4a 100644 --- a/cl/beacon/handler/blobs.go +++ b/cl/beacon/handler/blobs.go @@ -3,6 +3,7 @@ package handler import ( "fmt" "net/http" + "strconv" "github.com/ledgerwatch/erigon/cl/beacon/beaconhttp" "github.com/ledgerwatch/erigon/cl/cltypes" @@ -51,13 +52,33 @@ func (a *ApiHandler) GetEthV1BeaconBlobSidecars(w http.ResponseWriter, r *http.R if err != nil { return nil, err } - + strIdxs, err := beaconhttp.StringListFromQueryParams(r, "indices") + if err != nil { + return nil, err + } resp := solid.NewStaticListSSZ[*cltypes.BlobSidecar](696969, blobSidecarSSZLenght) if !found { return beaconhttp.NewBeaconResponse(resp), nil } - for _, v := range out { - resp.Append(v) + if len(strIdxs) == 0 { + for _, v := range out { + resp.Append(v) + } + } else { + included := make(map[uint64]struct{}) + for _, idx := range strIdxs { + i, err := strconv.ParseUint(idx, 10, 64) + if err != nil { + return nil, err + } + included[i] = struct{}{} + } + for _, v := range out { + if _, ok := included[v.Index]; ok { + resp.Append(v) + } + } } + return beaconhttp.NewBeaconResponse(resp), nil }