Skip to content

Instantly share code, notes, and snippets.

@riimak
Last active March 23, 2021 20:57
Show Gist options
  • Save riimak/842360047286001294075c1f8b6165bf to your computer and use it in GitHub Desktop.
Save riimak/842360047286001294075c1f8b6165bf 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"
# enable staker
enableStaker="$stealthd enablestaker $txid $vout $stakerName"
echo "Executing command $enableStaker"
enable=$($enableStaker)
if [[ -z $enable ]]; then
echo "Something went wrong with 'enablestaker' command. Error: $enableStaker";
exit 1;
fi
stakerEnabled=$($stealthd getstakerinfo $stakerName | jq -r '.enabled')
echo "Staker enable status: $stakerEnabled"
while [ $stakerEnabled = false ]
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