prysm-pulse/validator/client/beacon-api/beacon_api_helpers.go
Manu NALEPA 9c21809c50
Add REST implementation for ValidatorStatus (#11757)
* Add REST implementation for `ValidatorStatus`

* Fix review comments
2022-12-14 12:58:36 +00:00

45 lines
1.3 KiB
Go

package beacon_api
import (
"fmt"
neturl "net/url"
"regexp"
"strconv"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
)
var beaconAPITogRPCValidatorStatus = map[string]ethpb.ValidatorStatus{
"pending_initialized": ethpb.ValidatorStatus_DEPOSITED,
"pending_queued": ethpb.ValidatorStatus_PENDING,
"active_ongoing": ethpb.ValidatorStatus_ACTIVE,
"active_exiting": ethpb.ValidatorStatus_EXITING,
"active_slashed": ethpb.ValidatorStatus_SLASHING,
"exited_unslashed": ethpb.ValidatorStatus_EXITED,
"exited_slashed": ethpb.ValidatorStatus_EXITED,
"withdrawal_possible": ethpb.ValidatorStatus_EXITED,
"withdrawal_done": ethpb.ValidatorStatus_EXITED,
}
func validRoot(root string) bool {
matchesRegex, err := regexp.MatchString("^0x[a-fA-F0-9]{64}$", root)
if err != nil {
return false
}
return matchesRegex
}
func uint64ToString[T uint64 | types.Slot | types.ValidatorIndex | types.CommitteeIndex | types.Epoch](val T) string {
return strconv.FormatUint(uint64(val), 10)
}
func buildURL(path string, queryParams ...neturl.Values) string {
if len(queryParams) == 0 {
return path
}
return fmt.Sprintf("%s?%s", path, queryParams[0].Encode())
}