From 7cb74a0931794432a6b4abd17827a3ef5758df0b Mon Sep 17 00:00:00 2001 From: Scitz0 Date: Sun, 29 Oct 2023 12:57:35 +0100 Subject: [PATCH 1/3] Utilize formatLovelace/AdaToLovelace helper functions instead of formatAsset for Ada printing. formatLovelace updated to trim trailing fraction zeros by default for a less verbose output. --- scripts/cnode-helper-scripts/cntools.library | 2 +- scripts/cnode-helper-scripts/cntools.sh | 20 ++++++++++---------- scripts/cnode-helper-scripts/env | 7 +++++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/scripts/cnode-helper-scripts/cntools.library b/scripts/cnode-helper-scripts/cntools.library index b6719dfac..a75e98c28 100644 --- a/scripts/cnode-helper-scripts/cntools.library +++ b/scripts/cnode-helper-scripts/cntools.library @@ -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}" diff --git a/scripts/cnode-helper-scripts/cntools.sh b/scripts/cnode-helper-scripts/cntools.sh index e63c8e5f1..59a7c4dfb 100755 --- a/scripts/cnode-helper-scripts/cntools.sh +++ b/scripts/cnode-helper-scripts/cntools.sh @@ -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 @@ -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 @@ -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)" @@ -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}")")" @@ -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 diff --git a/scripts/cnode-helper-scripts/env b/scripts/cnode-helper-scripts/env index 50f6a6b7c..e183051f0 100644 --- a/scripts/cnode-helper-scripts/env +++ b/scripts/cnode-helper-scripts/env @@ -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' ]] && printf '0.%s' "${frac::+(0)}" || printf '0.%s' "${frac}")" && return + [[ -z $3 || $3 = 'trim' ]] && fraction="$(local frac=${1: -6}; printf '.%s' "${frac::+(0)}")" || 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 From 9d3472cae2afb29fe784ad124c60fdc2dfc50e6f Mon Sep 17 00:00:00 2001 From: Scitz0 Date: Mon, 30 Oct 2023 10:49:39 +0100 Subject: [PATCH 2/3] Fix fraction trim code --- scripts/cnode-helper-scripts/env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/cnode-helper-scripts/env b/scripts/cnode-helper-scripts/env index e183051f0..3db129e4b 100644 --- a/scripts/cnode-helper-scripts/env +++ b/scripts/cnode-helper-scripts/env @@ -328,8 +328,8 @@ validateDecimalNbr() { formatLovelace() { if isNumber $1; then [[ $1 -eq 0 ]] && echo 0 && return - [[ $1 -le 999999 ]] && printf '%s' "$(local frac=$(printf '%06d' "$1"); [[ -z $3 || $3 = 'trim' ]] && printf '0.%s' "${frac::+(0)}" || printf '0.%s' "${frac}")" && return - [[ -z $3 || $3 = 'trim' ]] && fraction="$(local frac=${1: -6}; printf '.%s' "${frac::+(0)}")" || fraction=".${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 From 9066a472f6cd015abf8b024b1a78c4387ad40d9d Mon Sep 17 00:00:00 2001 From: Scitz0 Date: Mon, 30 Oct 2023 10:54:23 +0100 Subject: [PATCH 3/3] changelog --- docs/Scripts/cntools-changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/Scripts/cntools-changelog.md b/docs/Scripts/cntools-changelog.md index 30b9c9751..7e14d843d 100644 --- a/docs/Scripts/cntools-changelog.md +++ b/docs/Scripts/cntools-changelog.md @@ -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