Created
February 13, 2023 01:16
-
-
Save larry0x/4f449179623bdd59f5ee927c2dfa7792 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/zsh | |
set -e | |
# change this to your address! | |
delegator="mars1..." | |
append-msg() { | |
tx=$1 | |
msgs=$(echo $tx | jq ".body.messages") | |
if [ -f "./tx.json" ]; then | |
jq ".body.messages += $msgs" tx.json | sponge tx.json | |
else | |
echo "$tx" > tx.json | |
fi | |
} | |
if [ -f "./tx.json" ]; then | |
rm ./tx.json | |
fi | |
printf "π Enter marsd keyring password: " | |
read -s password | |
echo "" | |
echo "π€ Querying restakeable rewards..." | |
rewards=$(marsd q distribution rewards $delegator --output json | jq '.rewards') | |
echo "π€ Composing tx..." | |
for row in $(echo $rewards | jq -c '.[]'); do | |
validatorAddress=$(echo $row | jq -r '.validator_address') | |
amountDec=$(echo $row | jq -r '.reward[0].amount') | |
if (( $amountDec > 0 )); then | |
amount=${amountDec%.*} | |
append-msg $(marsd tx staking delegate $validatorAddress ${amount}umars --from $delegator --generate-only) | |
echo "validator $validatorAddress: $amount umars" | |
fi | |
done | |
jq '.auth_info.fee.gas_limit = "2000000"' tx.json | sponge tx.json | |
jq '.auth_info.fee.amount = []' tx.json | sponge tx.json | |
echo "π€ Signing tx..." | |
echo $password | marsd tx sign tx.json --from $delegator --output-document tx.json -y | |
echo "π€ Broadcasting tx..." | |
marsd tx broadcast tx.json | |
echo "β Tx successfully broadcasted!" | |
rm tx.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment