Last active
March 23, 2021 20:58
-
-
Save riimak/b8aad41f59f7556b7b46a46a8ca97f5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -eq 0 ]; then | |
echo "Missing arguments!" | |
echo "" | |
echo "Argument for set staker meta is missing." | |
echo "" | |
echo "Example usage ./setstakermeta.sh Barrage meta_key meta_value" | |
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 | |
metaKey=$2 | |
metaValue=$3 | |
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" | |
# set staker meta | |
command="$stealthd setstakermeta $txid $vout $stakerName $metaKey $metaValue" | |
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