Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caplin: Update BlobSidecars Beacon API endpoint to the latest specs #10576

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading