Skip to content

Commit

Permalink
Merge pull request #22 from XWJACK/master
Browse files Browse the repository at this point in the history
Adapt to the latest request method
  • Loading branch information
danyalprout authored May 15, 2024
2 parents 2143b8a + 3b7dab4 commit 824e1a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
18 changes: 9 additions & 9 deletions api/service/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (a *API) blobSidecarHandler(w http.ResponseWriter, r *http.Request) {

blobSidecars := result.BlobSidecars

filteredBlobSidecars, err := filterBlobs(blobSidecars.Data, r.URL.Query().Get("indices"))
filteredBlobSidecars, err := filterBlobs(blobSidecars.Data, r.URL.Query()["indices"])
if err != nil {
err.write(w)
return
Expand Down Expand Up @@ -217,18 +217,18 @@ func (a *API) blobSidecarHandler(w http.ResponseWriter, r *http.Request) {

// filterBlobs filters the blobs based on the indices query provided.
// If no indices are provided, all blobs are returned. If invalid indices are provided, an error is returned.
func filterBlobs(blobs []*deneb.BlobSidecar, indices string) ([]*deneb.BlobSidecar, *httpError) {
if indices == "" {
return blobs, nil
}

splits := strings.Split(indices, ",")
if len(splits) == 0 {
func filterBlobs(blobs []*deneb.BlobSidecar, _indices []string) ([]*deneb.BlobSidecar, *httpError) {
var indices []string
if len(_indices) == 0 {
return blobs, nil
} else if len(_indices) == 1 {
indices = strings.Split(_indices[0], ",")
} else {
indices = _indices
}

indicesMap := map[deneb.BlobIndex]struct{}{}
for _, index := range splits {
for _, index := range indices {
parsedInt, err := strconv.ParseUint(index, 10, 64)
if err != nil {
return nil, newIndicesError(index)
Expand Down
8 changes: 8 additions & 0 deletions api/service/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ func TestAPIService(t *testing.T) {
},
},
},
{
name: "multi indices",
path: "/eth/v1/beacon/blob_sidecars/1234?indices=0&indices=1",
status: 200,
expected: &storage.BlobSidecars{
Data: blockTwo.BlobSidecars.Data,
},
},
{
name: "only index out of bounds returns empty array",
path: "/eth/v1/beacon/blob_sidecars/1234?indices=3",
Expand Down

0 comments on commit 824e1a6

Please sign in to comment.