Skip to content

Commit

Permalink
CNTools 11.0.2 (#1696)
Browse files Browse the repository at this point in the history
formatLovelace updated to trim trailing fraction zeros by default for a less verbose output.
CNTools updated to use AdaToLovelace with formatLovelace in a few more places to be consistent in how these values are treated.
  • Loading branch information
Scitz0 authored Oct 30, 2023
1 parent a4da8ff commit 0ef12fc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
4 changes: 4 additions & 0 deletions docs/Scripts/cntools-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to this tool will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [11.0.2] - 2023-10-30
#### Fixed
- Fix additional Ada printing. Now omits trailing zeros from fraction part of Ada output.

## [11.0.1] - 2023-10-25
#### Fixed
- Fix display for Pool Cost and Pledge to accept integer as well as decimal format of ADA
Expand Down
2 changes: 1 addition & 1 deletion scripts/cnode-helper-scripts/cntools.library
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CNTOOLS_MAJOR_VERSION=11
# Minor: Changes and features of minor character that can be applied without breaking existing functionality or workflow
CNTOOLS_MINOR_VERSION=0
# Patch: Backwards compatible bug fixes. No additional functionality or major changes
CNTOOLS_PATCH_VERSION=1
CNTOOLS_PATCH_VERSION=2

CNTOOLS_VERSION="${CNTOOLS_MAJOR_VERSION}.${CNTOOLS_MINOR_VERSION}.${CNTOOLS_PATCH_VERSION}"

Expand Down
20 changes: 10 additions & 10 deletions scripts/cnode-helper-scripts/cntools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ function main {
echo
pledge_ada=50000 # default pledge
[[ -f "${pool_config}" ]] && pledge_ada=$(jq -r '.pledgeADA //0' "${pool_config}")
getAnswerAnyCust pledge_enter "Pledge (in Ada, default: $(formatAsset ${pledge_ada}))"
getAnswerAnyCust pledge_enter "Pledge (in Ada, default: $(formatLovelace $(AdaToLovelace ${pledge_ada}))"
pledge_enter="${pledge_enter//,}"
if [[ -n "${pledge_enter}" ]]; then
if ! AdaToLovelace "${pledge_enter}" >/dev/null; then
Expand Down Expand Up @@ -2392,7 +2392,7 @@ function main {
println "Owner #$((index+1)) : ${FG_GREEN}${owner_wallets[${index}]}${NC}"
done
println "Reward Wallet : ${FG_GREEN}${reward_wallet}${NC}"
println "Pledge : ${FG_LBLUE}$(formatAsset ${pledge_ada})${NC} Ada"
println "Pledge : ${FG_LBLUE}$(formatLovelace $(AdaToLovelace ${pledge_ada}))${NC} Ada"
println "Margin : ${FG_LBLUE}${margin}${NC} %"
println "Cost : ${FG_LBLUE}$(formatLovelace ${cost_lovelace})${NC} Ada"
if [[ ${SUBCOMMAND} = "register" ]]; then
Expand Down Expand Up @@ -2718,14 +2718,14 @@ function main {
fi
fi
if [[ ${CNTOOLS_MODE} = "OFFLINE" && -f "${pool_config}" ]]; then
conf_pledge=$(( $(jq -r '.pledgeADA //0' "${pool_config}") * 1000000 ))
conf_pledge=$(jq -r '.pledgeADA //0' "${pool_config}")
conf_margin=$(jq -r '.margin //0' "${pool_config}")
conf_cost=$(jq -r '.costADA //0' "${pool_config}" | tr -d '.')
conf_cost=$(jq -r '.costADA //0' "${pool_config}")
conf_owner=$(jq -r '.pledgeWallet //"unknown"' "${pool_config}")
conf_reward=$(jq -r '.rewardWallet //"unknown"' "${pool_config}")
println "$(printf "%-21s : ${FG_LBLUE}%s${NC} Ada" "Pledge" "$(formatAsset "${conf_pledge::-6}")")"
println "$(printf "%-21s : ${FG_LBLUE}%s${NC} Ada" "Pledge" "$(formatLovelace $(AdaToLovelace "${conf_pledge}"))")"
println "$(printf "%-21s : ${FG_LBLUE}%s${NC} %%" "Margin" "${conf_margin}")"
println "$(printf "%-21s : ${FG_LBLUE}%s${NC} Ada" "Cost" "$(formatAsset "${conf_cost::-6}")")"
println "$(printf "%-21s : ${FG_LBLUE}%s${NC} Ada" "Cost" "$(formatLovelace $(AdaToLovelace "${conf_cost}"))")"
println "$(printf "%-21s : ${FG_GREEN}%s${NC} (%s)" "Owner Wallet" "${conf_owner}" "primary only, use online mode for multi-owner")"
println "$(printf "%-21s : ${FG_GREEN}%s${NC}" "Reward Wallet" "${conf_reward}")"
relay_title="Relay(s)"
Expand All @@ -2747,9 +2747,9 @@ function main {
pParams_pledge=${fPParams_pledge}
fi
if [[ ${pParams_pledge} -eq ${fPParams_pledge} ]]; then
println "$(printf "%-21s : ${FG_LBLUE}%s${NC} Ada" "Pledge" "$(formatAsset "${pParams_pledge::-6}")")"
println "$(printf "%-21s : ${FG_LBLUE}%s${NC} Ada" "Pledge" "$(formatLovelace "${pParams_pledge}")")"
else
println "$(printf "%-15s (${FG_YELLOW}%s${NC}) : ${FG_LBLUE}%s${NC} Ada" "Pledge" "new" "$(formatAsset "${fPParams_pledge::-6}")" )"
println "$(printf "%-15s (${FG_YELLOW}%s${NC}) : ${FG_LBLUE}%s${NC} Ada" "Pledge" "new" "$(formatLovelace "${fPParams_pledge}")" )"
fi
[[ -n ${KOIOS_API} ]] && println "$(printf "%-21s : ${FG_LBLUE}%s${NC} Ada" "Live Pledge" "$(formatLovelace "${p_live_pledge}")")"

Expand All @@ -2776,9 +2776,9 @@ function main {
pParams_cost=${fPParams_cost}
fi
if [[ ${pParams_cost} -eq ${fPParams_cost} ]]; then
println "$(printf "%-21s : ${FG_LBLUE}%s${NC} Ada" "Cost" "$(formatAsset "${pParams_cost::-6}")")"
println "$(printf "%-21s : ${FG_LBLUE}%s${NC} Ada" "Cost" "$(formatLovelace "${pParams_cost}")")"
else
println "$(printf "%-15s (${FG_YELLOW}%s${NC}) : ${FG_LBLUE}%s${NC} Ada" "Cost" "new" "$(formatAsset "${fPParams_cost::-6}")" )"
println "$(printf "%-15s (${FG_YELLOW}%s${NC}) : ${FG_LBLUE}%s${NC} Ada" "Cost" "new" "$(formatLovelace "${fPParams_cost}")" )"
fi

# get relays
Expand Down
7 changes: 5 additions & 2 deletions scripts/cnode-helper-scripts/env
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,14 @@ validateDecimalNbr() {
# Description : Pretty print Lovelace value
# : $1 = Amount in Lovelace
# : $2 = normal | pretty (default)
# : $3 = full | trim (default, removes trailing zeros from fraction)
formatLovelace() {
if isNumber $1; then
[[ $1 -eq 0 ]] && echo 0 && return
[[ $1 -le 999999 ]] && printf '0.%06d' "$1" && return
[[ -z $2 || $2 = 'pretty' ]] && printf '%s.%s' "$(sed ':a;s/\B[0-9]\{3\}\>/,&/;ta' <<< ${1::-6})" "${1: -6}" || printf '%s.%s' "${1::-6}" "${1: -6}"
[[ $1 -le 999999 ]] && printf '%s' "$(local frac=$(printf '%06d' "$1"); [[ -z $3 || $3 = 'trim' ]] && ([[ ${frac} =~ (^[0-9]*[1-9])?0*$ ]]; printf '0.%s' "${BASH_REMATCH[1]}") || printf '0.%s' "${frac}")" && return
[[ -z $3 || $3 = 'trim' ]] && fraction="$(local frac=${1: -6}; [[ ${frac} =~ (^[0-9]*[1-9])?0*$ ]]; printf '.%s' "${BASH_REMATCH[1]}")" || fraction=".${1: -6}"
[[ ${fraction} = '.' ]] && fraction=""
[[ -z $2 || $2 = 'pretty' ]] && printf '%s%s' "$(sed ':a;s/\B[0-9]\{3\}\>/,&/;ta' <<< ${1::-6})" "${fraction}" || printf '%s%s' "${1::-6}" "${fraction}"
else
printf "${FG_RED}ERROR${NC}: must be a valid integer number" 1>&2
return 1
Expand Down

0 comments on commit 0ef12fc

Please sign in to comment.