Skip to content

Instantly share code, notes, and snippets.

@c29r3
Last active February 10, 2021 01:26
Show Gist options
  • Save c29r3/b6654755e8f7180aec8f5ce27e52c2f6 to your computer and use it in GitHub Desktop.
Save c29r3/b6654755e8f7180aec8f5ce27e52c2f6 to your computer and use it in GitHub Desktop.
#!/bin/bash
#usage: sol_stake_next.sh $vote_account
SOL_BIN=$(find $HOME -type f -iname solana | tail -n 1)
VOTE_PATH=$(find $HOME -iname vote-account-keypair.json | head -n 1)
vote=$($SOL_BIN address -k $VOTE_PATH)
echo "Vote address ${vote}"
re='[0-9]+([.][0-9]+)?'
active="$($SOL_BIN validators | grep -e $vote | awk '{print $8}')";
if ! [[ $active =~ $re ]] ; then
active=0
fi
deactivates="$( $SOL_BIN stakes $vote | grep -i deactivates --color -A5 -B5 | grep Balance | awk '{print $2}' | paste -sd+ | bc) ";
if ! [[ $deactivates =~ $re ]] ; then
deactivates=0
fi
activates="$( $SOL_BIN stakes $vote | grep -i -w activates --color -A5 -B5 | grep Balance | awk '{print $2}' | paste -sd+ | bc) ";
if ! [[ $activates =~ $re ]] ; then
activates=0
fi
formula=$(echo "$active - $deactivates + $activates" )
echo "$formula" | bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment