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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to return blobbers by ids #2458

Merged
merged 6 commits into from May 31, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions code/go/0chain.net/smartcontract/storagesc/handler.go
Expand Up @@ -2188,6 +2188,7 @@ func (srh *StorageRestHandler) getBlobbers(w http.ResponseWriter, r *http.Reques

values := r.URL.Query()
active := values.Get("active")
idsStr := values.Get("blobber_ids")
edb := srh.GetQueryStateContext().GetEventDB()
if edb == nil {
common.Respond(w, r, nil, common.NewErrInternal("no db connection"))
Expand All @@ -2197,6 +2198,25 @@ func (srh *StorageRestHandler) getBlobbers(w http.ResponseWriter, r *http.Reques
var blobbers []event.Blobber
if active == "true" {
blobbers, err = edb.GetActiveBlobbers(limit)
} else if idsStr != "" {
var blobber_ids []string
err = json.Unmarshal([]byte(idsStr), &blobber_ids)
if err != nil {
common.Respond(w, r, nil, errors.New("blobber ids list is malformed"))
return
}

if len(blobber_ids) == 0 {
common.Respond(w, r, nil, errors.New("blobber ids list is empty"))
return
}

if len(blobber_ids) > common2.MaxQueryLimit {
common.Respond(w, r, nil, errors.New(fmt.Sprintf("too many ids, cannot exceed %d", common2.MaxQueryLimit)))
return
}

blobbers, err = edb.GetBlobbersFromIDs(blobber_ids)
} else {
blobbers, err = edb.GetBlobbers(limit)
}
Expand Down