Skip to content

Instantly share code, notes, and snippets.

@wallentx
Last active August 4, 2023 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wallentx/9dec567ddb0ab12143d4c0fe938938c3 to your computer and use it in GitHub Desktop.
Save wallentx/9dec567ddb0ab12143d4c0fe938938c3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
INPUT=$1
NWAIT="${INPUT:-1}"
start_block_height=$(chia rpc full_node get_blockchain_state | jq -r '.blockchain_state.peak.height')
start_time=$(date +%s)
synced_state=$(chia rpc full_node get_blockchain_state | jq -r '.blockchain_state.sync.synced')
fakewatch() {
while [[ $synced_state == false ]]; do
RESULT=$("${@}")
clear
echo "$RESULT"
read -t 1 -n 1 k
if [[ $k == q ]]; then
break
fi
done
echo "synced"
}
calcSync() {
json_data=$(chia rpc full_node get_blockchain_state)
current_block_height=$(echo "$json_data" | jq -r '.blockchain_state.sync.sync_progress_height')
total_block_height=$(echo "$json_data" | jq -r '.blockchain_state.sync.sync_tip_height')
time_elapsed=$(( $(date +%s) - start_time ))
if [ "$current_block_height" != "null" ] && [ "$total_block_height" != "null" ] && [ "$total_block_height" -gt "$start_block_height" ] && [ "$current_block_height" -gt "$start_block_height" ]; then
progress=$(awk "BEGIN {printf \"%.0f\", ($current_block_height * 100) / $total_block_height}")
bps=$(bc <<< "scale=2; ($current_block_height - $start_block_height) / $time_elapsed")
filled_length=$(( ($progress * 20) / 100 ))
remaining_length=$(( 20 - filled_length ))
progress_bar=$(printf "[")
for ((i=0; i<$filled_length; i++)); do
progress_bar+="="
done
for ((i=0; i<$remaining_length; i++)); do
progress_bar+=" "
done
progress_bar+="]"
else
progress=0
bps=0
progress_bar=""
fi
echo "Syncing progress: $current_block_height / $total_block_height blocks ($progress%)"
echo "Syncing speed: $bps BPS"
echo "Progress: $progress_bar"
sleep ${NWAIT}
}
fakewatch calcSync
@wallentx
Copy link
Author

wallentx commented Aug 4, 2023

2023-08-04_15-05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment