prysm-pulse/validator/client/beacon-api/state_validators.go
Manu NALEPA 0a5c65e29c
Add REST implementation for Validator's ValidatorIndex (#11712)
* Add GetAttestationData

* Add tests

* Add many more tests and refactor

* Fix logic

* Address PR comments

* Address PR comments

* Add jsonRestHandler and decouple http logic from rest of the code

* Add buildURL tests

* Remove handlers_test.go

* Improve tests

* Implement `ValidatorIndex` of `beaconApiValidatorClient` using Beacon API

* Implement getStateValidators

* `validatorIndex`: Use `getStateValidators`

Co-authored-by: Patrice Vignola <vignola.patrice@gmail.com>
2022-12-06 12:27:26 +00:00

38 lines
893 B
Go

//go:build use_beacon_api
// +build use_beacon_api
package beacon_api
import (
neturl "net/url"
"github.com/pkg/errors"
rpcmiddleware "github.com/prysmaticlabs/prysm/v3/beacon-chain/rpc/apimiddleware"
)
func (c *beaconApiValidatorClient) getStateValidators(stringPubkeys []string) (*rpcmiddleware.StateValidatorsResponseJson, error) {
params := neturl.Values{}
for _, stringPubkey := range stringPubkeys {
params.Add("id", stringPubkey)
}
url := buildURL(
"/eth/v1/beacon/states/head/validators",
params,
)
stateValidatorsJson := &rpcmiddleware.StateValidatorsResponseJson{}
_, err := c.jsonRestHandler.GetRestJsonResponse(url, stateValidatorsJson)
if err != nil {
return nil, errors.Wrap(err, "failed to get json response")
}
if stateValidatorsJson.Data == nil {
return nil, errors.New("stateValidatorsJson.Data is nil")
}
return stateValidatorsJson, nil
}