Skip to content

Commit

Permalink
Caplin: Update BlobSidecars Beacon API endpoint to the latest specs (#…
Browse files Browse the repository at this point in the history
…10580)

Cherry pick PR #10576 into the release branch

Co-authored-by: Giulio rebuffo <[email protected]>
  • Loading branch information
yperbasis and Giulio2002 authored May 31, 2024
1 parent 2e3d061 commit b29d137
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
9 changes: 7 additions & 2 deletions cl/beacon/beaconhttp/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"regexp"
"strconv"
"strings"

"github.com/go-chi/chi/v5"
"github.com/ledgerwatch/erigon-lib/common"
Expand Down Expand Up @@ -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
}
27 changes: 24 additions & 3 deletions cl/beacon/handler/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"fmt"
"net/http"
"strconv"

"github.com/ledgerwatch/erigon/cl/beacon/beaconhttp"
"github.com/ledgerwatch/erigon/cl/cltypes"
Expand Down Expand Up @@ -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
}

0 comments on commit b29d137

Please sign in to comment.