From 8d7731f839a79c11ac392afbf494431fa1ed6cdf Mon Sep 17 00:00:00 2001 From: Ola <ola.ahlman@gmail.com> Date: Mon, 4 Nov 2024 12:48:52 +0100 Subject: [PATCH] handling around predefined roles --- scripts/cnode-helper-scripts/cntools.library | 5 + scripts/cnode-helper-scripts/cntools.sh | 162 ++++++++++--------- 2 files changed, 94 insertions(+), 73 deletions(-) diff --git a/scripts/cnode-helper-scripts/cntools.library b/scripts/cnode-helper-scripts/cntools.library index 11786689a..ddec43773 100644 --- a/scripts/cnode-helper-scripts/cntools.library +++ b/scripts/cnode-helper-scripts/cntools.library @@ -2177,6 +2177,11 @@ getRewardInfoKoios() { rewards_available["${stake_address}"]="${rewards_available}" [[ -n ${delegated_pool} ]] && pool_delegations["${stake_address}"]="${delegated_pool}" if [[ -n ${delegated_drep} ]]; then + if [[ ${delegated_drep} = always_abstain ]]; then + vote_delegations["${stake_address}"]="alwaysAbstain"; return + elif [[ ${delegated_drep} = always_no_confidence ]]; then + vote_delegations["${stake_address}"]="alwaysNoConfidence"; return + fi # convert to cli format <type>-<hash> vote_delegation_raw=$(bech32 <<< "${delegated_drep}") if [[ ${vote_delegation_raw:0:2} = '22' ]]; then diff --git a/scripts/cnode-helper-scripts/cntools.sh b/scripts/cnode-helper-scripts/cntools.sh index 40768c968..f777c55e9 100755 --- a/scripts/cnode-helper-scripts/cntools.sh +++ b/scripts/cnode-helper-scripts/cntools.sh @@ -1122,50 +1122,60 @@ function main { if getWalletVoteDelegation ${wallet_name}; then unset vote_delegation_hash vote_delegation_type="${vote_delegation%-*}" - if [[ ${vote_delegation} = *-* ]]; then - vote_delegation_hash="${vote_delegation#*-}" - while IFS= read -r -d '' _wallet; do - getGovKeyInfo "$(basename ${_wallet})" - if [[ "${drep_hash}" = "${vote_delegation_hash}" ]]; then - walletName="$(basename ${_wallet})" && break - fi - done < <(find "${WALLET_FOLDER}" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z) - fi - getDRepIds ${vote_delegation_type} ${vote_delegation_hash} - println "Delegation : CIP-105 => ${FG_LGRAY}${vote_delegation_type} ${drep_id}${NC}" - println " : CIP-129 => ${FG_LGRAY}${vote_delegation_type} ${drep_id_cip129}${NC}" - if [[ -n ${walletName} ]]; then - println " : Wallet => ${FG_GREEN}${walletName}${NC}" - fi if [[ ${vote_delegation} = always* ]]; then - : # do nothing - elif getDRepStatus ${vote_delegation_type} ${vote_delegation_hash}; then - [[ $(getEpoch) -lt ${drep_expiry} ]] && expire_status="${FG_GREEN}active${NC}" || expire_status="${FG_RED}inactive${NC} (vote power does not count)" - println "DRep expiry : epoch ${FG_LBLUE}${drep_expiry}${NC} - ${expire_status}" - if [[ -n ${drep_anchor_url} ]]; then - println "DRep anchor url : ${FG_LGRAY}${drep_anchor_url}${NC}" - getDRepAnchor "${drep_anchor_url}" "${drep_anchor_hash}" - case $? in - 0) println "DRep anchor data :\n${FG_LGRAY}" - jq -er "${drep_anchor_file}" 2>/dev/null || cat "${drep_anchor_file}" - println DEBUG "${NC}" - ;; - 1) println "DRep anchor data : ${FG_YELLOW}Invalid URL or currently not available${NC}" ;; - 2) println "DRep anchor data :\n${FG_LGRAY}" - jq -er "${drep_anchor_file}" 2>/dev/null || cat "${drep_anchor_file}" - println "${NC}DRep anchor hash : ${FG_YELLOW}mismatch${NC}" - println " registered : ${FG_LGRAY}${drep_anchor_hash}${NC}" - println " actual : ${FG_LGRAY}${drep_anchor_real_hash}${NC}" - ;; - esac + if [[ ${vote_delegation} = alwaysAbstain ]]; then + println "Delegation : ${FG_LGRAY}Always abstain${NC}" + else + println "Delegation : ${FG_LGRAY}Always no confidence${NC}" fi else - println "Status : ${FG_RED}Unable to get DRep status, retired?${NC}" + if [[ ${vote_delegation} = *-* ]]; then + vote_delegation_hash="${vote_delegation#*-}" + while IFS= read -r -d '' _wallet; do + getGovKeyInfo "$(basename ${_wallet})" + if [[ "${drep_hash}" = "${vote_delegation_hash}" ]]; then + walletName="$(basename ${_wallet})" && break + fi + done < <(find "${WALLET_FOLDER}" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z) + fi + getDRepIds ${vote_delegation_type} ${vote_delegation_hash} + println "Delegation : CIP-105 => ${FG_LGRAY}${vote_delegation_type} ${drep_id}${NC}" + println " : CIP-129 => ${FG_LGRAY}${vote_delegation_type} ${drep_id_cip129}${NC}" + if [[ -n ${walletName} ]]; then + println " : Wallet => ${FG_GREEN}${walletName}${NC}" + fi + if getDRepStatus ${vote_delegation_type} ${vote_delegation_hash}; then + [[ $(getEpoch) -lt ${drep_expiry} ]] && expire_status="${FG_GREEN}active${NC}" || expire_status="${FG_RED}inactive${NC} (vote power does not count)" + println "DRep expiry : epoch ${FG_LBLUE}${drep_expiry}${NC} - ${expire_status}" + if [[ -n ${drep_anchor_url} ]]; then + println "DRep anchor url : ${FG_LGRAY}${drep_anchor_url}${NC}" + getDRepAnchor "${drep_anchor_url}" "${drep_anchor_hash}" + case $? in + 0) println "DRep anchor data :\n${FG_LGRAY}" + jq -er "${drep_anchor_file}" 2>/dev/null || cat "${drep_anchor_file}" + println DEBUG "${NC}" + ;; + 1) println "DRep anchor data : ${FG_YELLOW}Invalid URL or currently not available${NC}" ;; + 2) println "DRep anchor data :\n${FG_LGRAY}" + jq -er "${drep_anchor_file}" 2>/dev/null || cat "${drep_anchor_file}" + println "${NC}DRep anchor hash : ${FG_YELLOW}mismatch${NC}" + println " registered : ${FG_LGRAY}${drep_anchor_hash}${NC}" + println " actual : ${FG_LGRAY}${drep_anchor_real_hash}${NC}" + ;; + esac + fi + else + println "Status : ${FG_RED}Unable to get DRep status, retired?${NC}" + fi fi getDRepVotePower ${vote_delegation_type} ${vote_delegation_hash} println "Active Vote power : ${FG_LBLUE}$(formatLovelace ${vote_power:=0})${NC} ADA (${FG_LBLUE}${vote_power_pct:=0} %${NC})" else - println "Delegation : ${FG_YELLOW}undelegated${NC} - please note that reward withdrawals will not work in the future until wallet is vote delegated" + if versionCheck "10.0" "${PROT_VERSION}"; then + println "Delegation : ${FG_YELLOW}undelegated${NC} - please note that reward withdrawals will not work until wallet is vote delegated" + else + println "Delegation : ${FG_YELLOW}undelegated${NC}" + fi fi fi waitToProceed && continue @@ -3871,45 +3881,51 @@ function main { if getWalletVoteDelegation ${wallet_name}; then unset vote_delegation_hash vote_delegation_type="${vote_delegation%-*}" - if [[ ${vote_delegation} = *-* ]]; then - vote_delegation_hash="${vote_delegation#*-}" - while IFS= read -r -d '' _wallet; do - getGovKeyInfo "$(basename ${_wallet})" - if [[ ${drep_hash} = "${vote_delegation_hash}" ]]; then - walletName="$(basename ${_wallet})" && break - fi - done < <(find "${WALLET_FOLDER}" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z) - fi - getDRepIds ${vote_delegation_type} ${vote_delegation_hash} - println "Delegation : CIP-105 => ${FG_LGRAY}${vote_delegation_type} ${drep_id}${NC}" - println " : CIP-129 => ${FG_LGRAY}${vote_delegation_type} ${drep_id_cip129}${NC}" - if [[ -n ${walletName} ]]; then - println " : Wallet => ${FG_GREEN}${walletName}${NC}" - fi if [[ ${vote_delegation} = always* ]]; then - : # do nothing - elif getDRepStatus ${vote_delegation_type} ${vote_delegation_hash}; then - [[ ${current_epoch} -lt ${drep_expiry} ]] && expire_status="${FG_GREEN}active${NC}" || expire_status="${FG_RED}inactive${NC} (vote power does not count)" - println "DRep expiry : epoch ${FG_LBLUE}${drep_expiry}${NC} - ${expire_status}" - if [[ -n ${drep_anchor_url} ]]; then - println "DRep anchor url : ${FG_LGRAY}${drep_anchor_url}${NC}" - getDRepAnchor "${drep_anchor_url}" "${drep_anchor_hash}" - case $? in - 0) println "DRep anchor data :\n${FG_LGRAY}" - jq -er "${drep_anchor_file}" 2>/dev/null || cat "${drep_anchor_file}" - println DEBUG "${NC}" - ;; - 1) println "DRep anchor data : ${FG_YELLOW}Invalid URL or currently not available${NC}" ;; - 2) println "DRep anchor data :\n${FG_LGRAY}" - jq -er "${drep_anchor_file}" 2>/dev/null || cat "${drep_anchor_file}" - println "${NC}DRep anchor hash : ${FG_YELLOW}mismatch${NC}" - println " registered : ${FG_LGRAY}${drep_anchor_hash}${NC}" - println " actual : ${FG_LGRAY}${drep_anchor_real_hash}${NC}" - ;; - esac + if [[ ${vote_delegation} = alwaysAbstain ]]; then + println "Delegation : ${FG_LGRAY}Always abstain${NC}" + else + println "Delegation : ${FG_LGRAY}Always no confidence${NC}" fi else - println "Status : ${FG_RED}Unable to get DRep status, retired?${NC}" + if [[ ${vote_delegation} = *-* ]]; then + vote_delegation_hash="${vote_delegation#*-}" + while IFS= read -r -d '' _wallet; do + getGovKeyInfo "$(basename ${_wallet})" + if [[ ${drep_hash} = "${vote_delegation_hash}" ]]; then + walletName="$(basename ${_wallet})" && break + fi + done < <(find "${WALLET_FOLDER}" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z) + fi + getDRepIds ${vote_delegation_type} ${vote_delegation_hash} + println "Delegation : CIP-105 => ${FG_LGRAY}${vote_delegation_type} ${drep_id}${NC}" + println " : CIP-129 => ${FG_LGRAY}${vote_delegation_type} ${drep_id_cip129}${NC}" + if [[ -n ${walletName} ]]; then + println " : Wallet => ${FG_GREEN}${walletName}${NC}" + fi + if getDRepStatus ${vote_delegation_type} ${vote_delegation_hash}; then + [[ ${current_epoch} -lt ${drep_expiry} ]] && expire_status="${FG_GREEN}active${NC}" || expire_status="${FG_RED}inactive${NC} (vote power does not count)" + println "DRep expiry : epoch ${FG_LBLUE}${drep_expiry}${NC} - ${expire_status}" + if [[ -n ${drep_anchor_url} ]]; then + println "DRep anchor url : ${FG_LGRAY}${drep_anchor_url}${NC}" + getDRepAnchor "${drep_anchor_url}" "${drep_anchor_hash}" + case $? in + 0) println "DRep anchor data :\n${FG_LGRAY}" + jq -er "${drep_anchor_file}" 2>/dev/null || cat "${drep_anchor_file}" + println DEBUG "${NC}" + ;; + 1) println "DRep anchor data : ${FG_YELLOW}Invalid URL or currently not available${NC}" ;; + 2) println "DRep anchor data :\n${FG_LGRAY}" + jq -er "${drep_anchor_file}" 2>/dev/null || cat "${drep_anchor_file}" + println "${NC}DRep anchor hash : ${FG_YELLOW}mismatch${NC}" + println " registered : ${FG_LGRAY}${drep_anchor_hash}${NC}" + println " actual : ${FG_LGRAY}${drep_anchor_real_hash}${NC}" + ;; + esac + fi + else + println "Status : ${FG_RED}Unable to get DRep status, retired?${NC}" + fi fi getDRepVotePower ${vote_delegation_type} ${vote_delegation_hash} println "Active Vote power : ${FG_LBLUE}$(formatLovelace ${vote_power:=0})${NC} ADA (${FG_LBLUE}${vote_power_pct:=0} %${NC})"