mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
0a5c65e29c
* 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>
38 lines
893 B
Go
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
|
|
}
|