Skip to content

Commit

Permalink
cntools: identify owner stake and display in red if below pledge
Browse files Browse the repository at this point in the history
  • Loading branch information
SmaugPool committed Jul 8, 2020
1 parent a9b87d9 commit fcce896
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions scripts/cnode-helper-scripts/cntools.sh
Expand Up @@ -3,10 +3,10 @@

########## Global tasks ###########################################

# get common env variables
# set locale for compatibility
export LC_ALL=en_US.UTF-8

# get common env variables
. "$(dirname $0)"/env

# get cntools config parameters
Expand Down Expand Up @@ -2077,8 +2077,10 @@ case $OPERATION in
say "${GREEN}${pool_name}${NC} "
say "$(printf "%-21s : %s" "ID" "${pool_id}")" "log"
pool_config="${POOL_FOLDER}/${pool_name}/${POOL_CONFIG_FILENAME}"
pledge=0
if [[ -f "${pool_config}" ]]; then
say "$(printf "%-21s : %s ADA" "Pledge" "$(numfmt --grouping "$(jq -r .pledgeADA "${pool_config}")")")" "log"
pledge=$(jq -r .pledgeADA "${pool_config}")
say "$(printf "%-21s : %s ADA" "Pledge" "$(numfmt --grouping "${pledge}")")" "log"
say "$(printf "%-21s : %s %%" "Margin" "$(numfmt --grouping "$(jq -r .margin "${pool_config}")")")" "log"
say "$(printf "%-21s : %s ADA" "Cost" "$(numfmt --grouping "$(jq -r .costADA "${pool_config}")")")" "log"
fi
Expand Down Expand Up @@ -2132,15 +2134,24 @@ case $OPERATION in
delegators=$(echo "${non_myopic_delegators}" "${snapshot_delegators}" "${lstate_delegators}" | tr ' ' '\n' | sort -u)
total_stake=0
delegator=1
getRewardAddress "${owner_wallet}"
base_addr_hex="$(${CCLI} shelley query stake-address-info --address "${reward_addr}" --testnet-magic ${NWMAGIC} | jq -r 'keys[0]')"
for key in ${delegators}; do
printf "\r"
stake_address="581de0${key}"
stake=$(jq ".esLState._utxoState._utxo | .[] | select(.address | contains(\"${key}\")) | .amount" "${TMP_FOLDER}"/ledger-state.json | awk 'BEGIN{total = 0} {total = total + $1} END{printf "%.0f", total}')
reward=$(jq -r ".esLState._delegationState._dstate._rewards | .[] | select(.[0][\"credential\"][\"key hash\"] == \"${key}\") | .[1]" "${TMP_FOLDER}"/ledger-state.json)
total_stake=$((total_stake + stake + reward))
say "$(printf "%-21s : %s" "Delegator ${delegator} hex key" "${key}")" "log"
say "$(printf "%-21s : ${CYAN}%s${NC} ADA (%s ADA)" " Stake (reward)" "$(numfmt --grouping "$(lovelacetoADA ${stake})")" "$(numfmt --grouping "$(lovelacetoADA ${reward})")")" "log"
delegator=$((delegator+1))
stake_color="${CYAN}"
if echo "${base_addr_hex}" | grep -q "${key}"; then
say "$(printf "%-21s : %s" "Owner hex key" "${key}")" "log"
if [[ $(lovelacetoADA $((stake + reward))) < ${pledge} ]]; then
stake_color="${RED}"
fi
else
say "$(printf "%-21s : %s" "Delegator ${delegator} hex key" "${key}")" "log"
delegator=$((delegator + 1))
fi
say "$(printf "%-21s : ${stake_color}%s${NC} ADA (%s ADA)" " Stake (reward)" "$(numfmt --grouping "$(lovelacetoADA ${stake})")" "$(numfmt --grouping "$(lovelacetoADA ${reward})")")" "log"
done
say "$(printf "%-21s : ${GREEN}%s${NC} ADA" "Stake" "$(numfmt --grouping "$(lovelacetoADA ${total_stake})")")" "log"
stake_pct=$(fractionToPCT "$(printf "%.10f" "$(${CCLI} shelley query stake-distribution --testnet-magic ${NWMAGIC} | grep "${pool_id}" | tr -s ' ' | cut -d ' ' -f 2)")")
Expand Down

0 comments on commit fcce896

Please sign in to comment.