mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
dbeb3ee886
* WIP * WIP * WIP * WIP * WIP * WIP * WIP * Onboard validator's Beacon REST API usage to e2e tests * Remove unused variables * Remove use_beacon_api tags * Fix DeepSource errors * Revert unneeded changes * Revert evaluator changes * Revert import reordering * Address PR comments * Remove all REST API e2e tests except minimal one * Fix validator pointing to inexisting beacon node port Co-authored-by: Radosław Kapka <rkapka@wp.pl>
33 lines
999 B
Go
33 lines
999 B
Go
package beacon_api
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/pkg/errors"
|
|
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
)
|
|
|
|
func (c beaconApiValidatorClient) validatorIndex(in *ethpb.ValidatorIndexRequest) (*ethpb.ValidatorIndexResponse, error) {
|
|
stringPubKey := hexutil.Encode(in.PublicKey)
|
|
|
|
stateValidator, err := c.getStateValidators([]string{stringPubKey})
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to get validator state")
|
|
}
|
|
|
|
if len(stateValidator.Data) == 0 {
|
|
return nil, errors.Errorf("could not find validator index for public key `%s`", stringPubKey)
|
|
}
|
|
|
|
stringValidatorIndex := stateValidator.Data[0].Index
|
|
|
|
index, err := strconv.ParseUint(stringValidatorIndex, 10, 64)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to parse validator index")
|
|
}
|
|
|
|
return ðpb.ValidatorIndexResponse{Index: types.ValidatorIndex(index)}, nil
|
|
}
|