Skip to content

Commit b29d137

Browse files
Caplin: Update BlobSidecars Beacon API endpoint to the latest specs (#10580)
Cherry pick PR #10576 into the release branch Co-authored-by: Giulio rebuffo <[email protected]>
1 parent 2e3d061 commit b29d137

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

cl/beacon/beaconhttp/args.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
"regexp"
77
"strconv"
8+
"strings"
89

910
"github.com/go-chi/chi/v5"
1011
"github.com/ledgerwatch/erigon-lib/common"
@@ -168,9 +169,13 @@ func Uint64FromQueryParams(r *http.Request, name string) (*uint64, error) {
168169

169170
// decode a list of strings from the query params
170171
func StringListFromQueryParams(r *http.Request, name string) ([]string, error) {
171-
str := r.URL.Query().Get(name)
172-
if str == "" {
172+
values := r.URL.Query()[name]
173+
if len(values) == 0 {
173174
return nil, nil
174175
}
176+
177+
// Combine all values into a single string, separating by comma
178+
str := strings.Join(values, ",")
179+
175180
return regexp.MustCompile(`\s*,\s*`).Split(str, -1), nil
176181
}

cl/beacon/handler/blobs.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package handler
33
import (
44
"fmt"
55
"net/http"
6+
"strconv"
67

78
"github.com/ledgerwatch/erigon/cl/beacon/beaconhttp"
89
"github.com/ledgerwatch/erigon/cl/cltypes"
@@ -51,13 +52,33 @@ func (a *ApiHandler) GetEthV1BeaconBlobSidecars(w http.ResponseWriter, r *http.R
5152
if err != nil {
5253
return nil, err
5354
}
54-
55+
strIdxs, err := beaconhttp.StringListFromQueryParams(r, "indices")
56+
if err != nil {
57+
return nil, err
58+
}
5559
resp := solid.NewStaticListSSZ[*cltypes.BlobSidecar](696969, blobSidecarSSZLenght)
5660
if !found {
5761
return beaconhttp.NewBeaconResponse(resp), nil
5862
}
59-
for _, v := range out {
60-
resp.Append(v)
63+
if len(strIdxs) == 0 {
64+
for _, v := range out {
65+
resp.Append(v)
66+
}
67+
} else {
68+
included := make(map[uint64]struct{})
69+
for _, idx := range strIdxs {
70+
i, err := strconv.ParseUint(idx, 10, 64)
71+
if err != nil {
72+
return nil, err
73+
}
74+
included[i] = struct{}{}
75+
}
76+
for _, v := range out {
77+
if _, ok := included[v.Index]; ok {
78+
resp.Append(v)
79+
}
80+
}
6181
}
82+
6283
return beaconhttp.NewBeaconResponse(resp), nil
6384
}

0 commit comments

Comments
 (0)