2022-11-22 12:12:55 +00:00
|
|
|
package beacon_api
|
|
|
|
|
|
|
|
import (
|
2022-12-06 12:27:26 +00:00
|
|
|
"fmt"
|
|
|
|
neturl "net/url"
|
2022-11-22 12:12:55 +00:00
|
|
|
"regexp"
|
2022-12-12 10:39:51 +00:00
|
|
|
"strconv"
|
|
|
|
|
|
|
|
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
2022-12-14 12:58:36 +00:00
|
|
|
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
2022-11-22 12:12:55 +00:00
|
|
|
)
|
|
|
|
|
2022-12-14 12:58:36 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2022-11-22 12:12:55 +00:00
|
|
|
func validRoot(root string) bool {
|
|
|
|
matchesRegex, err := regexp.MatchString("^0x[a-fA-F0-9]{64}$", root)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return matchesRegex
|
|
|
|
}
|
2022-12-06 12:27:26 +00:00
|
|
|
|
2022-12-12 10:39:51 +00:00
|
|
|
func uint64ToString[T uint64 | types.Slot | types.ValidatorIndex | types.CommitteeIndex | types.Epoch](val T) string {
|
|
|
|
return strconv.FormatUint(uint64(val), 10)
|
|
|
|
}
|
|
|
|
|
2022-12-06 12:27:26 +00:00
|
|
|
func buildURL(path string, queryParams ...neturl.Values) string {
|
|
|
|
if len(queryParams) == 0 {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s?%s", path, queryParams[0].Encode())
|
|
|
|
}
|