Last active
August 17, 2022 17:49
-
-
Save Jsewill/2c6734480146ac8faee1d5747135a292 to your computer and use it in GitHub Desktop.
Script for renaming Chia CAT wallets
This file contains 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 | |
###### | |
# | |
# Make sure Chia is in your PATH env variable, or that you activate your chia virtual environment before running this script. Everyone's setup is different. | |
# | |
##### | |
usage() { echo "Usage: $0 [-f <wallet_fingerprint>]" 1>&2; exit 1; } | |
[ $# -eq 0 ] && usage | |
while getopts ":f:h" flag; do | |
case "${flag}" in | |
f) | |
fingerprint=$OPTARG; | |
;; | |
h | *) | |
usage; | |
;; | |
esac | |
done; | |
# Test if Chia is available. | |
if ! command -v chia &> /dev/null; then | |
echo "Chia not found in PATH. Try activating your chia venv."; | |
exit 2; | |
fi | |
# Check synchronization status. | |
sync_status=$(chia rpc wallet get_sync_status | python3 -c "import sys, json; print(json.load(sys.stdin)['synced'])") | |
until [ "$sync_status" == "True" ]; do | |
echo "The wallet is not synchronized. Trying again in 5s." | |
sleep 5; | |
sync_status=$(chia rpc wallet get_sync_status | python3 -c "import sys, json; print(json.load(sys.stdin)['synced'])") | |
done; | |
# Loop over CAT wallets. | |
echo "Getting wallets"; | |
chia wallet show -f $fingerprint -w cat | grep -A 6 "CAT[[:blank:]]\+[[:alnum:]]\{16\}..." | grep "Asset ID\|Wallet ID" | while read lone; read ltwo; do | |
# Store Asset and Wallet IDs | |
aid=$(echo $lone | grep "Asset ID" | awk '{ print $NF }'); | |
wid=$(echo $ltwo | grep "Wallet ID" | awk '{ print $NF }'); | |
if [ "$aid" == "" ] || [ "$wid" == "" ]; then | |
continue | |
fi | |
# Get the name associated with the asset IDs, from taildatabase API | |
aname=$(curl -s -X 'GET' "https://api.taildatabase.com/enterprise/tail/$aid" -H 'accept: application/json' -H 'x-api-version: 1' | python3 -c "import sys, json; print(json.load(sys.stdin)['name'])"); | |
# Name wallet | |
if [ "$aname" == "" ]; then | |
continue | |
fi | |
echo "Naming Wallet ID $wid (Asset ID: $aid), \"$aname\""; | |
chia wallet add_token -f $fingerprint -id "$aid" -n "$aname"; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment