mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
9c21809c50
* Add REST implementation for `ValidatorStatus` * Fix review comments
45 lines
1.3 KiB
Go
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())
|
|
}
|