-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
273 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
node_modules | ||
release | ||
.DS_Store | ||
/scripts/ | ||
test/.env | ||
tmp-* | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/bin/bash | ||
|
||
# Source this file with `source scripts/commands.sh` to use the functions in your shell. | ||
# First argument can be an alternative binary path, e.g. `source scripts/commands.sh /path/to/kyved`. | ||
|
||
RED="\e[31m" | ||
GREEN="\e[32m" | ||
ENDCOLOR="\e[0m" | ||
|
||
export BINARY=${1:-"kyved"} | ||
|
||
# Check if binary is executable | ||
if ! command -v "$BINARY" &> /dev/null; then | ||
echo -e "$RED✗ $BINARY binary not found. Please install it or use the correct path.$ENDCOLOR" | ||
return | ||
fi | ||
|
||
export CHAIN_ID=$($BINARY status --output json | jq -r '.node_info.network' | tr -d '\"') | ||
if [[ -z "$CHAIN_ID" ]]; then | ||
export CHAIN_ID=$($BINARY status | jq -r '.NodeInfo.network' | tr -d '\"') | ||
if [[ -z "$CHAIN_ID" ]]; then | ||
echo -e "$RED✗ Could not fetch chain ID. Make sure your node is running.$ENDCOLOR" | ||
return | ||
fi | ||
fi | ||
|
||
export TX="--gas 200000 --fees 5000000tkyve --yes --chain-id $CHAIN_ID" | ||
export ALICE_TX="$TX --from alice" | ||
export TESTBACKEND="--keyring-backend test" | ||
export CHAINHOME="--home ~/.chain" | ||
export JSON="--output json" | ||
|
||
check_tx() { | ||
echo "🔍 Checking transaction..." | ||
|
||
local tx_output | ||
local tx_hash | ||
local code | ||
tx_output=$(cat -) | ||
tx_hash=$(echo "$tx_output" | jq -r '.txhash' | tr -d '.') | ||
code=$(echo "$tx_output" | jq -r '.code' | tr -d '.') | ||
|
||
if [[ -z "$tx_hash" || "$code" -ne 0 ]]; then | ||
local raw_log=$(echo "$tx_output" | jq -r '.raw_log') | ||
echo -e "${RED}✗ Transaction failed with code $code:\n$raw_log${ENDCOLOR}" | ||
return "$code" | ||
fi | ||
|
||
local sleep_time=0.5 | ||
local elapsed_seconds=0 | ||
local progress_bar="" | ||
|
||
# Run a loop to check for tx_output | ||
while true; do | ||
local tx_output=$(kyved q tx "$tx_hash" --output json 2>/dev/null) | ||
local code=$(echo "$tx_output" | jq -r '.code') | ||
|
||
if [[ -z "$code" ]]; then | ||
printf "\r⏳ Fetching transaction: %02d seconds | Progress: [%-30s]" "$elapsed_seconds" "$progress_bar" | ||
sleep $sleep_time | ||
((elapsed_seconds++)) | ||
progress_bar+="=" | ||
else | ||
break | ||
fi | ||
done | ||
|
||
echo "" | ||
|
||
if [[ "$code" -eq 0 ]]; then | ||
echo "✏️ logs:" | ||
echo "$tx_output" | jq '.logs' | ||
echo "" | ||
echo -e "${GREEN}✅ Transaction $tx_hash successful!${ENDCOLOR}" | ||
else | ||
echo "✏️ raw_log:" | ||
echo "$tx_output" | jq '.raw_log' | ||
echo "" | ||
echo -e "${RED}✗ Transaction $tx_hash failed with code $code.${ENDCOLOR}" | ||
fi | ||
return "$code" | ||
} | ||
export -f check_tx | ||
|
||
echo "👋 Welcome to the KYVE CLI!" | ||
echo "" | ||
echo "# Environment variables -> override with your own values" | ||
echo "export TX=\"$TX\"" | ||
echo "export ALICE_TX=\"$ALICE_TX\"" | ||
echo "export TESTBACKEND=\"$TESTBACKEND\"" | ||
echo "export CHAINHOME=\"$CHAINHOME\"" | ||
echo "export JSON=\"$JSON\"" | ||
echo "" | ||
echo "# Add Alice's key" | ||
echo "$BINARY keys add alice --recover \$TESTBACKEND" | ||
echo "# Mnemonic" | ||
echo "expect crisp umbrella hospital firm exhibit future size slot update blood deliver fat happy ghost visa recall usual path purity junior ring ordinary stove" | ||
echo "" | ||
echo "# Send coins" | ||
echo "$BINARY tx bank send alice kyve1jve70gkvgyvdnrxw4q7ry7vq2asu25ac0m48vk 1000tkyve \$CHAINHOME \$TESTBACKEND \$TX \$JSON | check_tx" | ||
echo "" | ||
echo "# Governance" | ||
echo "$BINARY tx gov draft-proposal" | ||
echo "$BINARY tx gov submit-proposal draft_proposal.json \$ALICE_TX \$CHAINHOME \$TESTBACKEND \$TX \$JSON | check_tx" | ||
echo "$BINARY tx gov vote \$($BINARY q gov proposals --page-limit 1 --page-reverse --proposal-status voting-period \$JSON | jq '.proposals[0].id | tonumber') yes \$ALICE_TX \$CHAINHOME \$TESTBACKEND \$JSON | check_tx" | ||
echo "" | ||
echo "# Funders" | ||
echo "$BINARY tx funders create-funder Alice \$CHAINHOME \$TESTBACKEND \$ALICE_TX \$JSON | check_tx" | ||
echo "$BINARY tx funders update-funder Alice \$CHAINHOME \$TESTBACKEND \$ALICE_TX \$JSON | check_tx" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#!/bin/bash | ||
# This script is only used for local testing. Do not use it in production. | ||
|
||
RED="\e[31m" | ||
ENDCOLOR="\e[0m" | ||
|
||
# Check if at least upgrade name is provided | ||
if [ $# -lt 1 ]; then | ||
echo -e "$RED✗ Usage: perform-chain-upgrade.sh [upgrade_name] [wait_blocks (default=30)]$ENDCOLOR" | ||
exit 1 | ||
fi | ||
|
||
# Check if wait_blocks is provided | ||
if [ -z "$2" ]; then | ||
WAIT_BLOCKS=30 | ||
else | ||
WAIT_BLOCKS=$2 | ||
fi | ||
|
||
echo "🚀 Upgrading chain to $1 in $WAIT_BLOCKS blocks" | ||
|
||
# Check if binary env is set | ||
if [ -z "$BINARY" ]; then | ||
echo -e "$RED✗ BINARY env not set. Please source commands.sh before running this script$ENDCOLOR" | ||
exit 1 | ||
fi | ||
|
||
get_height() { | ||
local height= | ||
height=$($BINARY status | jq '.sync_info.latest_block_height' | tr -d '\"') | ||
if [ "$height" == "null" ]; then | ||
height=$($BINARY status | jq '.SyncInfo.latest_block_height' | tr -d '\"') | ||
if [[ -z "$height" ]]; then | ||
exit 1 | ||
fi | ||
fi | ||
echo "$height" | ||
} | ||
|
||
PROPOSAL='{ | ||
"messages": [ | ||
{ | ||
"@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", | ||
"authority": "kyve10d07y265gmmuvt4z0w9aw880jnsr700jdv7nah", | ||
"plan": { | ||
"name": "MY_UPGRADE_NAME", | ||
"height": "MY_UPGRADE_height", | ||
"info": "" | ||
} | ||
} | ||
], | ||
"metadata": "ipfs://QmSbXwSgAnhhkDk5LtvgEwKUf6iUjww5FbMngYs86uGxdG", | ||
"deposit": "50000000000MY_DENOM", | ||
"title": "Upgrade to MY_UPGRADE_NAME", | ||
"summary": "This is an upgrade to MY_UPGRADE_NAME", | ||
"expedited": false | ||
}' | ||
|
||
NAME=$1 | ||
UPGRADE_HEIGHT=`expr "$(get_height)" + $WAIT_BLOCKS` | ||
DENOM="tkyve" | ||
|
||
PROPOSAL="${PROPOSAL//MY_UPGRADE_height/$UPGRADE_HEIGHT}" | ||
PROPOSAL="${PROPOSAL//MY_UPGRADE_NAME/$NAME}" | ||
PROPOSAL="${PROPOSAL//MY_DENOM/$DENOM}" | ||
printf "$PROPOSAL" > /tmp/proposal.json | ||
|
||
# Submit proposal | ||
$BINARY tx gov submit-proposal /tmp/proposal.json $ALICE_TX $CHAINHOME $TESTBACKEND $TX $JSON | check_tx | ||
|
||
# Exit if proposal submission failed | ||
if [ $? -ne 0 ]; then | ||
exit 1 | ||
fi | ||
echo "" | ||
echo "Submitted proposal" | ||
echo "" | ||
|
||
# Get proposal ID | ||
ID=$($BINARY q gov proposals --page-limit 1 --page-reverse --proposal-status voting-period $JSON | jq '.proposals[0].id | tonumber' | tee /dev/null) | ||
if [[ -z "$ID" ]]; then | ||
ID=$($BINARY q gov proposals --limit 1 --reverse --status voting_period $JSON | jq '.proposals[0].id | tonumber') | ||
if [[ -z "$ID" ]]; then | ||
echo -e "$RED✗ Could not fetch proposal ID. Make sure your node is running.$ENDCOLOR" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# Vote on proposal | ||
$BINARY tx gov vote $ID yes $ALICE_TX $CHAINHOME $TESTBACKEND $JSON | check_tx | ||
echo "" | ||
echo "Voted yes on proposal $ID" | ||
echo "Scheduled upgrade for height $UPGRADE_HEIGHT" | ||
|
||
did_proposal_pass() { | ||
local result=$1 | ||
local status=$(echo "$result" | jq -r '.proposal.status') | ||
|
||
if [ "$status" == "null" ]; then | ||
status=$(echo "$result" | jq -r '.status') | ||
fi | ||
|
||
# status 3 or "PROPOSAL_STATUS_PASSED" is passed | ||
if [[ "$status" -eq 3 || "$status" == "PROPOSAL_STATUS_PASSED" ]]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
did_proposal_fail() { | ||
local result=$1 | ||
local status=$(echo "$result" | jq -r '.proposal.status') | ||
|
||
if [ "$status" == "null" ]; then | ||
status=$(echo "$result" | jq -r '.status') | ||
fi | ||
|
||
# everything except status 2 (PROPOSAL_STATUS_VOTING_PERIOD) or status 3 (PROPOSAL_STATUS_PASSED) is failed | ||
if [[ "$status" -ne 2 && "$status" -ne 3 && "$status" != "PROPOSAL_STATUS_VOTING_PERIOD" && "$status" != "PROPOSAL_STATUS_PASSED" ]]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# Wait for upgrade and poll status | ||
elapsed_seconds=0 | ||
progress_bar_length=$(expr $WAIT_BLOCKS \* 1) | ||
while true; do | ||
result=$($BINARY q gov proposal $ID $JSON) | ||
|
||
if did_proposal_pass "$result"; then | ||
printf "\n\r✅ Upgrade successful! Took %02d seconds\n" "$elapsed_seconds" | ||
break | ||
elif did_proposal_fail "$result"; then | ||
printf "\n\r${RED}✗ Upgrade failed!\nCheck if your voting parameters are correct. They need to have a short voting time and a low quorum threshold.${ENDCOLOR}\n" | ||
break | ||
fi | ||
|
||
height=$(get_height) | ||
remaining_blocks=$(expr $UPGRADE_HEIGHT - $height) | ||
|
||
passed_blocks=$(expr $WAIT_BLOCKS - $remaining_blocks) | ||
progress_bar=$(printf "%0.s=" $(seq 1 $passed_blocks)) | ||
|
||
printf "\r⏳ Waiting for upgrade: %02d seconds | Progress: [%-*s] %02d blocks left" "$elapsed_seconds" "$progress_bar_length" "$progress_bar" "$remaining_blocks" | ||
|
||
if [[ "$remaining_blocks" -le 0 ]]; then | ||
printf "\n\r${RED}✗ Upgrade failed!\nCheck if your voting parameters are correct. They need to have a short voting time and a low quorum threshold.${ENDCOLOR}\n" | ||
exit 1 | ||
fi | ||
|
||
sleep 1 | ||
((elapsed_seconds++)) | ||
done |