Skip to content

Commit

Permalink
Add keymanager graffiti (eth-educators#1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdowne authored Dec 7, 2023
1 parent 3b8dd45 commit 2604d73
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ethd
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,14 @@ __keys_usage() {
echo " delete-gas 0xPUBKEY"
echo " Delete individual execution gas limit for the validator with public key 0xPUBKEY"
echo
echo " get-graffiti 0xPUBKEY"
echo " List graffiti set for the validator with public key 0xPUBKEY"
echo " Validators will use GRAFFITI in .env by default, if not set individually"
echo " set-graffiti 0xPUBKEY amount"
echo " Set individual graffiti for the validator with public key 0xPUBKEY"
echo " delete-graffiti 0xPUBKEY"
echo " Delete individual graffiti for the validator with public key 0xPUBKEY"
echo
echo " get-api-token"
echo " Print the token for the keymanager API running on port ${KEY_API_PORT:-7500}."
echo " This is also the token for the Prysm Web UI"
Expand Down
88 changes: 88 additions & 0 deletions vc-utils/keymanager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,73 @@ gas-delete() {
esac
}

graffiti-get() {
if [ -z "$__pubkey" ]; then
echo "Please specify a validator public key"
exit 0
fi
get-token
__api_path=eth/v1/validator/$__pubkey/graffiti
__api_data=""
__http_method=GET
call_api
case $__code in
200) echo "The graffiti for the validator with public key $__pubkey is:"; echo "$__result" | jq -r '.data.graffiti'; exit 0;;
400) echo "The pubkey was formatted wrong. Error: $(echo "$__result" | jq -r '.message')"; exit 1;;
401) echo "No authorization token found. This is a bug. Error: $(echo "$__result" | jq -r '.message')"; exit 70;;
403) echo "The authorization token is invalid. Error: $(echo "$__result" | jq -r '.message')"; exit 1;;
404) echo "Path not found error. Was that the right pubkey? Error: $(echo "$__result" | jq -r '.message')"; exit 0;;
500) echo "Internal server error. Error: $(echo "$__result" | jq -r '.message')"; exit 1;;
*) echo "Unexpected return code $__code. Result: $__result"; exit 1;;
esac
}

graffiti-set() {
if [ -z "$__pubkey" ]; then
echo "Please specify a validator public key"
exit 0
fi
if [ -z "$__graffiti" ]; then
echo "Please specify a graffiti string"
exit 0
fi
get-token
__api_path=eth/v1/validator/$__pubkey/graffiti
__api_data="{\"graffiti\": \"$__graffiti\" }"
__http_method=POST
call_api
case $__code in
202) echo "The graffiti for the validator with public key $__pubkey was updated."; exit 0;;
400) echo "The pubkey or limit was formatted wrong. Error: $(echo "$__result" | jq -r '.message')"; exit 1;;
401) echo "No authorization token found. This is a bug. Error: $(echo "$__result" | jq -r '.message')"; exit 70;;
403) echo "The authorization token is invalid. Error: $(echo "$__result" | jq -r '.message')"; exit 1;;
404) echo "Path not found error. Was that the right pubkey? Error: $(echo "$__result" | jq -r '.message')"; exit 0;;
500) echo "Internal server error. Error: $(echo "$__result" | jq -r '.message')"; exit 1;;
*) echo "Unexpected return code $__code. Result: $__result"; exit 1;;
esac
}

graffiti-delete() {
if [ -z "$__pubkey" ]; then
echo "Please specify a validator public key"
exit 0
fi
get-token
__api_path=eth/v1/validator/$__pubkey/graffiti
__api_data=""
__http_method=DELETE
call_api
case $__code in
204) echo "The graffiti for the validator with public key $__pubkey was set back to default."; exit 0;;
400) echo "The pubkey was formatted wrong. Error: $(echo "$__result" | jq -r '.message')"; exit 1;;
401) echo "No authorization token found. This is a bug. Error: $(echo "$__result" | jq -r '.message')"; exit 70;;
403) echo "A graffiti was found, but cannot be deleted. It may be in a configuration file. Message: $(echo "$__result" | jq -r '.message')"; exit 0;;
404) echo "The key was not found on the server, nothing to delete. Message: $(echo "$__result" | jq -r '.message')"; exit 0;;
500) echo "Internal server error. Error: $(echo "$__result" | jq -r '.message')"; exit 1;;
*) echo "Unexpected return code $__code. Result: $__result"; exit 1;;
esac
}

exit-sign() {
if [ -z "$__pubkey" ]; then
echo "Please specify a validator public key"
Expand Down Expand Up @@ -922,6 +989,14 @@ usage() {
echo " delete-gas 0xPUBKEY"
echo " Delete individual execution gas limit for the validator with public key 0xPUBKEY"
echo
echo " get-graffiti 0xPUBKEY"
echo " List graffiti set for the validator with public key 0xPUBKEY"
echo " Validators will use GRAFFITI in .env by default, if not set individually"
echo " set-graffiti 0xPUBKEY amount"
echo " Set individual graffiti for the validator with public key 0xPUBKEY"
echo " delete-graffiti 0xPUBKEY"
echo " Delete individual graffiti for the validator with public key 0xPUBKEY"
echo
echo " get-api-token"
echo " Print the token for the keymanager API running on port ${__api_port}."
echo " This is also the token for the Prysm Web UI"
Expand Down Expand Up @@ -1048,6 +1123,19 @@ case "$3" in
__pubkey=$4
gas-delete
;;
get-graffiti)
__pubkey=$4
graffiti-get
;;
set-graffiti)
__pubkey=$4
__graffiti=$5
graffiti-set
;;
delete-graffiti)
__pubkey=$4
graffiti-delete
;;
sign-exit)
__pubkey=$4
exit-sign
Expand Down

0 comments on commit 2604d73

Please sign in to comment.