Skip to content

Instantly share code, notes, and snippets.

@riimak
Last active March 23, 2021 20:59
Show Gist options
  • Save riimak/a0ab0c964a4b603c83bd214d7e3b3f60 to your computer and use it in GitHub Desktop.
Save riimak/a0ab0c964a4b603c83bd214d7e3b3f60 to your computer and use it in GitHub Desktop.
StealthCoind claimqpos script with helper steps
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Missing arguments!"
echo ""
echo "Argument for claim QPoS balance is missing."
echo ""
echo "Example usage ./claimqposbalance.sh Barrage 1000"
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
claimAmount=$2
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"
# claim QPoS balance
command="$stealthd claimqposbalance $txid $vout $claimAmount"
echo "Executing command $command"
executecommand=$($command)
if [[ -z $executecommand ]]; then
echo "Something went wrong with command. Error: $executeCommand";
exit 1;
fi
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment