Skip to content

Instantly share code, notes, and snippets.

@riimak
Created May 18, 2021 05:33
Show Gist options
  • Save riimak/bfb923331fa7b8c4b3351ce5f28602f9 to your computer and use it in GitHub Desktop.
Save riimak/bfb923331fa7b8c4b3351ce5f28602f9 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Missing arguments!"
echo ""
echo "Argument for enable staker is missing."
echo ""
echo "Example usage ./enablestaker.sh Barrage"
exit 1;
fi
command -v jq >/dev/null 2>&1 || { echo >&2 "This tool require jq but it's not installed (i.e. yum install jq). Aborting."; exit 1; }
# define StealthCoind binary
stealthd="/usr/local/bin/StealthCoind -conf=/var/lib/stealthd/stealthd.conf";
# staker name
stakerName=$1
ownerAddress=$($stealthd getstakerauthorities $stakerName | jq -r '.owner.address')
# get owner address
hasOwnerAddressInAccount=$($stealthd getaddressesbyaccount "" | jq -r --arg owner_address "$ownerAddress" '.[] | select(. == $owner_address)')
if [[ -z $hasOwnerAddressInAccount ]]; then
echo 'There is no owner address '$ownerAddress' in the local wallet and default account ""'
exit 1;
fi
echo "ownerAddress: $ownerAddress"
# do a transaction and store the transaction ID into the txid variable
sendToAddress="$stealthd sendtoaddress $ownerAddress 0.01"
echo "Executing command $sendToAddress"
txid=$($sendToAddress)
echo "sendToAddress result: $txid"
# get transaction to fetch the vout number
gettx="$stealthd gettransaction $txid"
echo "Executing command $gettx"
txinfo=$($gettx)
vout=$(echo $txinfo | jq -r --arg owner_address "$ownerAddress" '.vout[] | select(.scriptPubKey.addresses[0] == $owner_address) | .n')
echo "vout: $vout"
if [[ -z $vout ]]; then
echo "Invalid vout. Received: $vout"
exit 1;
fi
confirmations=$($stealthd gettransaction $txid | jq -r '.confirmations')
echo "Confirmations number: $confirmations"
while [ $confirmations = 0 ]
do
confirmations=$($stealthd gettransaction $txid | jq -r '.confirmations')
done
echo "Confirmations number: $confirmations"
# disable staker
disableStaker="$stealthd disablestaker $txid $vout $stakerName"
echo "Executing command $disableStaker"
disable=$($enableStaker)
if [[ -z $disable ]]; then
echo "Something went wrong with 'disablestaker' command. Error: $disableStaker";
exit 1;
fi
stakerEnabled=$($stealthd getstakerinfo $stakerName | jq -r '.enabled')
echo "Staker enable status: $stakerEnabled"
while [ $stakerEnabled = true ]
do
stakerEnabled=$($stealthd getstakerinfo $stakerName | jq -r '.enabled')
done
echo "Staker enable status: $stakerEnabled"
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment