Skip to content

Instantly share code, notes, and snippets.

@mcanvar
Last active February 8, 2021 23:07
Show Gist options
  • Save mcanvar/2fdb752be8a04946c606687f26cffca4 to your computer and use it in GitHub Desktop.
Save mcanvar/2fdb752be8a04946c606687f26cffca4 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [[ -z $1 ]]
then
echo "Crossfire competition status checker."
echo ""
echo "Usage:"
echo " estimate-cf.sh [moniker-name]"
exit
fi
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m'
red() { printf "${RED}$@${NC}\n"; }
green() { printf "${GREEN}$@${NC}\n"; }
yellow() { printf "${YELLOW}$@${NC}\n"; }
cyan() { printf "${CYAN}$@${NC}\n"; }
ansi() { echo -e "\e[${1}m${*:2}\e[0m"; }
bold() { ansi 1 "$@"; }
italic() { ansi 3 "$@"; }
strikethrough() { ansi 9 "$@"; }
function check {
if [[ $1 = "Completed" ]]
then
echo "$(green $1) $(bold $2\$)"
elif [[ $1 = "progress" ]]
then
echo "$(yellow 'In progress') $(italic $2\$)"
else
echo "$(red $1) $(strikethrough $2\$)"
fi
}
function activeTask {
if [[ $2 -gt 0 ]]
then
P=$(($1 * 100 / $2 ))
if [[ $P -ge 50 ]]
then
echo "$(green $P)%"
elif [[ $P -lt 50 ]]
then
echo "$(red $P)%"
fi
else
echo "n/a"
fi
}
RAW=`curl -s "https://chain.crypto.com/explorer/crossfire/api/v1/crossfire/validators?$(date +%s)" | jq -c '.result[] | select( .moniker | contains("'$1'"))' | jq .`
if [[ -z $RAW ]]
then
echo 'Please check your moniker.'
exit
fi
TEXT_IN_PROG="In progress"
TP1=$(echo $RAW | jq -r .taskSetup)
TP2=$(echo $RAW | jq -r .taskKeepActive)
TP2V=$(echo $RAW | jq -r .taskProposalVote)
TP2U=$(echo $RAW | jq -r .taskNetworkUpgrade)
joinedAt=$(echo $RAW | jq -r .stats.joinedAtBlockHeight)
commitsAtP1P2=$(echo $RAW | jq -r .stats.commitCountPhase1n2)
commitsAtP2=$(echo $RAW | jq -r .stats.commitCountPhase2)
commitsAtP1=$( expr $commitsAtP1P2 - $commitsAtP2 )
blocksAtP2=$(echo $RAW | jq -r .stats.phase2BlockCount)
clear
echo ""
echo " $(cyan $1' Node') "
echo ".........................................................................."
echo " $(bold 'Phase 1') Setup Node & Submit 1 Block $(check $TP1 '200') "
echo ""
echo " Joined at $joinedAt & submitted $commitsAtP1 block(s)."
echo ".........................................................................."
echo " $(bold 'Phase 2') Maintain 50% Up Time $(check $TP2 '800') "
echo ""
echo " Node is maintaining $(activeTask $commitsAtP2 $blocksAtP2) uptime."
echo ".........................................................................."
echo " $(bold 'Phase 2') Proposal Voting $(check $TP2V '50') "
echo ""
echo " Vote for network upgrade."
echo ".........................................................................."
echo " $(bold 'Phase 2') Perform Upgrade $(check $TP2U '100') "
echo ""
echo " Perform network upgrade."
echo ".........................................................................."
echo ""
echo "$(bold 'Note: ') This is only an unofficial prediction script."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment