Skip to content

Instantly share code, notes, and snippets.

@riimak
Last active February 21, 2023 01:36
Show Gist options
  • Save riimak/2fe969a31fbe783bac0638361ddf2c37 to your computer and use it in GitHub Desktop.
Save riimak/2fe969a31fbe783bac0638361ddf2c37 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Missing arguments!"
echo ""
echo "Argument for purchase staker is missing."
echo ""
echo "Example usage ./purchasestaker.sh Barrage n2mncrSmtgDhTzTD4PNFkVoHG6gyNCxcTA"
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=$2
ownerPubkey=$($stealthd validateaddress n2mncrSmtgDhTzTD4PNFkVoHG6gyNCxcTA | jq -r '.pubkey')
echo "ownerAddress: $ownerAddress"
echo "ownerPubkey: $ownerPubkey"
# 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"
# purchase staker
purchaseStaker="$stealthd purchasestaker $txid $vout $stakerName $ownerPubkey"
echo "Executing command $purchaseStaker"
purchase=$($purchaseStaker)
if [[ -z $purchase ]]; then
echo "Something went wrong with 'purchasestaker' command. Error: $purchaseStaker";
exit 1;
fi
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment