Skip to content

Commit 29817a4

Browse files
committed
gov action query: fix up different jq cases
1 parent b26e07b commit 29817a4

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

scripts/recipes/governance.just

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ query-gov-action-status ENV ACTION_ID ACTION_IDX:
143143

144144
POOL_DIST=$(eval "$CARDANO_CLI" latest query spo-stake-distribution --all-spos 2> /dev/null)
145145
POOL_STAKE_TOTAL=$(jq -re '[.[][1]] | add // 0' <<< "$POOL_DIST" 2> /dev/null)
146-
POOL_ABSTAIN_TOTAL=$(jq -re '[(.[] | select(.[2] == "drep-alwaysAbstain")) | .[1]] | add' <<< "$POOL_DIST")
147-
POOL_NOCONF_TOTAL=$(jq -re '[(.[] | select(.[2] == "drep-alwaysNoConfidence")) | .[1]] | add' <<< "$POOL_DIST")
146+
POOL_ABSTAIN_TOTAL=$(jq -re '[(.[] | select(.[2] == "drep-alwaysAbstain")) | .[1]] | add // 0' <<< "$POOL_DIST")
147+
POOL_NOCONF_TOTAL=$(jq -re '[(.[] | select(.[2] == "drep-alwaysNoConfidence")) | .[1]] | add // 0' <<< "$POOL_DIST")
148+
148149
R_JUSTIFY "POOL_STAKE_TOTAL:" "$POOL_STAKE_TOTAL" 50
149150
R_JUSTIFY "POOL_ABSTAIN_TOTAL:" "$POOL_ABSTAIN_TOTAL" 50
150151
R_JUSTIFY "POOL_NOCONF_TOTAL:" "$POOL_NOCONF_TOTAL" 50
@@ -619,16 +620,22 @@ query-gov-action-status ENV ACTION_ID ACTION_IDX:
619620

620621
ADD_HASHES_RENDER=$(jq -re "
621622
.[2] // {}
622-
| to_entries[]
623-
| \"Adding $GREEN\(.key)-\(.value)\"
624-
| split(\"-\") | \"\(.[0])$OFF ► $BLUE\(.[1])$OFF (max term epoch \(.[2]))\"
623+
| to_entries as \$entries
624+
| if (\$entries | length) > 0
625+
then []
626+
| \"Adding $GREEN\(.key)-\(.value)\"
627+
| split(\"-\")
628+
| \"\(.[0])$OFF ► $BLUE\(.[1])$OFF (max term epoch \(.[2]))\"
629+
else \"No additions\"
630+
end
625631
" <<< "$ACTION_CONTENTS" 2> /dev/null)
626632

627633
REM_HASHES_RENDER=$(jq -re "
628634
.[1][] // []
629635
| to_entries as \$entries
630636
| if (\$entries | length > 0)
631-
then \"Remove $GREEN\(\$entries | .key)$OFF ◄ $RED\(\$entries | .value)$OFF\"
637+
then \$entries[]
638+
| \"Remove $GREEN\(.key)$OFF ◄ $RED\(.value)$OFF\"
632639
else \"No removals\"
633640
end
634641
" <<< "$ACTION_CONTENTS" 2> /dev/null)

0 commit comments

Comments
 (0)