Skip to content

Commit 4b3c511

Browse files
authored
POST version of GetValidators and GetValidatorBalances (#13199)
* POST versions of GetValidators and GetValidatorBalances * post statuses * balances test * group params * test error cases
1 parent 8902ad3 commit 4b3c511

File tree

4 files changed

+319
-53
lines changed

4 files changed

+319
-53
lines changed

beacon-chain/rpc/eth/beacon/handlers_validator.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package beacon
22

33
import (
4+
"encoding/json"
45
"fmt"
6+
"io"
57
"net/http"
68
"strconv"
79
"strings"
@@ -49,7 +51,32 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
4951
}
5052
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
5153

52-
rawIds := r.URL.Query()["id"]
54+
var req GetValidatorsRequest
55+
if r.Method == http.MethodPost {
56+
err = json.NewDecoder(r.Body).Decode(&req)
57+
switch {
58+
case err == io.EOF:
59+
http2.HandleError(w, "No data submitted", http.StatusBadRequest)
60+
return
61+
case err != nil:
62+
http2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
63+
return
64+
}
65+
}
66+
67+
var statuses []string
68+
var rawIds []string
69+
if r.Method == http.MethodGet {
70+
rawIds = r.URL.Query()["id"]
71+
statuses = r.URL.Query()["status"]
72+
} else {
73+
rawIds = req.Ids
74+
statuses = req.Statuses
75+
}
76+
for i, ss := range statuses {
77+
statuses[i] = strings.ToLower(ss)
78+
}
79+
5380
ids, ok := decodeIds(w, st, rawIds, true /* ignore unknown */)
5481
if !ok {
5582
return
@@ -72,11 +99,6 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
7299
epoch := slots.ToEpoch(st.Slot())
73100
allBalances := st.Balances()
74101

75-
statuses := r.URL.Query()["status"]
76-
for i, ss := range statuses {
77-
statuses[i] = strings.ToLower(ss)
78-
}
79-
80102
// Exit early if no matching validators were found or we don't want to further filter validators by status.
81103
if len(readOnlyVals) == 0 || len(statuses) == 0 {
82104
containers := make([]*ValidatorContainer, len(readOnlyVals))
@@ -234,7 +256,21 @@ func (bs *Server) GetValidatorBalances(w http.ResponseWriter, r *http.Request) {
234256
}
235257
isFinalized := bs.FinalizationFetcher.IsFinalized(ctx, blockRoot)
236258

237-
rawIds := r.URL.Query()["id"]
259+
var rawIds []string
260+
if r.Method == http.MethodGet {
261+
rawIds = r.URL.Query()["id"]
262+
} else {
263+
err = json.NewDecoder(r.Body).Decode(&rawIds)
264+
switch {
265+
case err == io.EOF:
266+
http2.HandleError(w, "No data submitted", http.StatusBadRequest)
267+
return
268+
case err != nil:
269+
http2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
270+
return
271+
}
272+
}
273+
238274
ids, ok := decodeIds(w, st, rawIds, true /* ignore unknown */)
239275
if !ok {
240276
return

0 commit comments

Comments
 (0)