Last active
August 4, 2022 00:29
-
-
Save Jsewill/0b45cbf2021eff2eb911aa3db7f456b4 to your computer and use it in GitHub Desktop.
CAT1 Snapshot
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 | |
export FULL_NODE_HOSTNAME=localhost | |
export DB_SOURCE_DIR=$HOME/.chia/mainnet/db | |
export START_HEIGHT=1146800 | |
export TARGET_HEIGHT=2311760 | |
usage() { | |
cat << EOF | |
Usage: $0 [-psc] [-t "<tail:prefix> <tail:prefix> ..."] | |
-p define a working path. Defaults to your current working directory ($PWD). | |
-s Clone the repo and build the snapshot in your current working directory ($PWD). Defaults to false. | |
-c Cleanup from failed snapshot. Defaults to false. | |
-t A quoted, space-separated list of CAT tail:asset_id pairs with which to export snapshot CSVs. If this is your first time running this script, combine (or run it once) with -s. ($PWD) | |
EOF | |
1>&2; exit 1; | |
} | |
[ $# -eq 0 ] && usage | |
tails="" | |
bs=false | |
cl=false | |
wd=$PWD | |
while getopts "p:t:sch" flag; do | |
case "${flag}" in | |
p) | |
wd=$OPTARG; | |
;; | |
s) | |
bs=true; | |
;; | |
c) | |
cl=true; | |
;; | |
t) | |
tails=$OPTARG; | |
;; | |
h | *) | |
usage; | |
;; | |
esac | |
done; | |
# Generate the snapshot | |
cd $wd && git status > /dev/null 2>&1 | |
if [ $? -gt 0 ]; then | |
if $bs; then | |
# If our working directory is a git repository, assume this hasn't been run before and use it to clone the git repository and setup the database. | |
echo "Cloning repository and installing dependencies." | |
git clone https://github.com/Chia-Network/CAT-addresses.git . && python3 setup.py install && pip install python-dotenv && pip install backoff && python3 setup_database.py | |
fi | |
else | |
if $cl; then | |
python3 clean.py | |
fi | |
fi | |
if $bs; then | |
# Start snapshot. | |
echo "Generating the snapshot." | |
python3 start.py | |
fi | |
if [ "$tails" == "" ]; then | |
exit 1; | |
fi | |
# Export the snapshots for specific TAILS to CSV | |
echo "Exporting TAILS to CSV files." | |
for tp in $tails; do | |
t=$(echo $tp | cut -d':' -f1) | |
p=$(echo $tp | cut -d':' -f2) | |
python3 export.py --output-dir ./$p_ --tail-hash $t | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now that I've had a chance to test this script, I've fixed a few bugs, and added a clean option. I may have more improvements once my testing is complete.