Skip to content

Commit

Permalink
Merge pull request #774 from IntersectMBO/smelc/governance-view-show-…
Browse files Browse the repository at this point in the history
…proposals-and-votes

      transaction view: show proposals and votes
  • Loading branch information
smelc authored May 30, 2024
2 parents b08f10c + 026cf6d commit 1f81d15
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 2 deletions.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ library
, transformers-except ^>= 0.1.3
, unliftio-core
, utf8-string
, vector
, yaml

executable cardano-cli
Expand Down
39 changes: 38 additions & 1 deletion cardano-cli/src/Cardano/CLI/Json/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}

-- | User-friendly pretty-printing for textual user interfaces (TUI)
Expand Down Expand Up @@ -36,7 +37,7 @@ import Cardano.Api.Shelley (Address (ShelleyAddress), Hash (..),
fromShelleyStakeReference, toShelleyStakeCredential)

import Cardano.CLI.Types.MonadWarning (MonadWarning, eitherToWarning, runWarningIO)
import Cardano.Prelude (first)
import Cardano.Prelude (Foldable (..), first)

import Codec.CBOR.Encoding (Encoding)
import Codec.CBOR.FlatTerm (fromFlatTerm, toFlatTerm)
Expand All @@ -56,12 +57,16 @@ import qualified Data.Map.Strict as Map
import Data.Maybe (catMaybes, isJust, maybeToList)
import Data.Ratio (numerator)
import qualified Data.Text as Text
import qualified Data.Vector as Vector
import Data.Yaml (array)
import Data.Yaml.Pretty (setConfCompare)
import qualified Data.Yaml.Pretty as Yaml
import GHC.Real (denominator)
import GHC.Unicode (isAlphaNum)

{- HLINT ignore "Redundant bracket" -}
{- HLINT ignore "Move brackets to avoid $" -}

data FriendlyFormat = FriendlyJson | FriendlyYaml

friendly ::
Expand Down Expand Up @@ -175,6 +180,8 @@ friendlyTxBodyImpl
, txTotalCollateral
, txReturnCollateral
, txInsReference
, txProposalProcedures
, txVotingProcedures
, txUpdateProposal
, txValidityLowerBound
, txValidityUpperBound
Expand All @@ -200,7 +207,37 @@ friendlyTxBodyImpl
, "update proposal" .= friendlyUpdateProposal txUpdateProposal
, "validity range" .= friendlyValidityRange era (txValidityLowerBound, txValidityUpperBound)
, "withdrawals" .= friendlyWithdrawals txWithdrawals
, "governance actions" .=
(inEonForEra
Null
(\(cOnwards :: ConwayEraOnwards era) ->
case txProposalProcedures of
Nothing -> Null
Just (Featured _ TxProposalProceduresNone) -> Null
Just (Featured _ (TxProposalProcedures lProposals _witnesses)) ->
friendlyLedgerProposals cOnwards $ toList lProposals)
era)
, "voters" .=
(inEonForEra
Null
(\cOnwards ->
case txVotingProcedures of
Nothing -> Null
Just (Featured _ TxVotingProceduresNone) -> Null
Just (Featured _ (TxVotingProcedures votes _witnesses)) ->
friendlyVotingProcedures cOnwards votes)
era)
])
where
friendlyLedgerProposals :: ConwayEraOnwards era -> [L.ProposalProcedure (ShelleyLedgerEra era)] -> Aeson.Value
friendlyLedgerProposals cOnwards proposalProcedures =
Array $ Vector.fromList $ map (friendlyLedgerProposal cOnwards) proposalProcedures

friendlyLedgerProposal :: ConwayEraOnwards era -> L.ProposalProcedure (ShelleyLedgerEra era) -> Aeson.Value
friendlyLedgerProposal cOnwards proposalProcedure = object $ friendlyProposalImpl cOnwards (Proposal proposalProcedure)

friendlyVotingProcedures :: ConwayEraOnwards era -> L.VotingProcedures (ShelleyLedgerEra era) -> Aeson.Value
friendlyVotingProcedures cOnwards x = conwayEraOnwardsConstraints cOnwards $ toJSON x

redeemerIfShelleyBased :: MonadWarning m => CardanoEra era -> TxBody era -> m [Aeson.Pair]
redeemerIfShelleyBased era tb =
Expand Down
31 changes: 30 additions & 1 deletion cardano-cli/test/cardano-cli-golden/Test/Golden/TxView.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Test.Golden.TxView
, hprop_golden_view_metadata
, hprop_golden_view_alonzo_yaml
, hprop_golden_view_alonzo_signed_yaml
, hprop_golden_view_conway_three_votes
, hprop_golden_view_conway_proposal
) where

import Cardano.Api (TxMetadataJsonSchema (..))
Expand Down Expand Up @@ -389,7 +391,7 @@ hprop_golden_view_alonzo_signed_yaml :: Property
hprop_golden_view_alonzo_signed_yaml =
propertyOnce $ moduleWorkspace "tmp" $ \tempDir -> do
let golden = goldenDir </> "alonzo"
let input = inputDir </> "alonzo"
input = inputDir </> "alonzo"

transactionBodyFile <- noteTempFile tempDir "transaction-body"
transactionFile <- noteTempFile tempDir "transaction"
Expand All @@ -412,3 +414,30 @@ hprop_golden_view_alonzo_signed_yaml =

H.diffVsGoldenFile result (golden </> "signed-transaction-view.out")

-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden view conway three votes/"'@
hprop_golden_view_conway_three_votes :: Property
hprop_golden_view_conway_three_votes =
propertyOnce $ do
let golden = goldenDir </> "conway"
input = inputDir </> "conway"

result <-
execCardanoCLI
["transaction", "view", "--tx-file", input </> "tx-three-votes.json", "--output-json"]

H.diffVsGoldenFile result (golden </> "tx-three-votes-view.out.json")

-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden view conway proposal/"'@
hprop_golden_view_conway_proposal :: Property
hprop_golden_view_conway_proposal =
propertyOnce $ do
let golden = goldenDir </> "conway"
input = inputDir </> "conway"

result <-
execCardanoCLI
["transaction", "view", "--tx-file", input </> "tx-proposal.json", "--output-json"]

H.diffVsGoldenFile result (golden </> "tx-proposal.out.json")
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ certificates: null
collateral inputs: null
era: Allegra
fee: 100 Lovelace
governance actions: null
inputs:
- fe5dd07fb576bff960d6e066eade5b26cdb5afebe29f76ea58d0a098bce5d891#94
metadata: null
Expand All @@ -26,4 +27,5 @@ update proposal: null
validity range:
lower bound: null
upper bound: 101
voters: null
withdrawals: null
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ collateral inputs:
- c9765d7d0e3955be8920e6d7a38e1f3f2032eac48c7c59b0b9193caa87727e7e#256
era: Alonzo
fee: 213 Lovelace
governance actions: null
inputs:
- ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20#212
metadata: null
Expand All @@ -20,6 +21,7 @@ update proposal: null
validity range:
lower bound: null
upper bound: null
voters: null
withdrawals: null
witnesses:
- key: VKey (VerKeyEd25519DSIGN "84ce03e08b05533685d593c14cd6ca5c7485824156ca11fb303ddac9dd3ef41c")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ collateral inputs:
- c9765d7d0e3955be8920e6d7a38e1f3f2032eac48c7c59b0b9193caa87727e7e#256
era: Alonzo
fee: 213 Lovelace
governance actions: null
inputs:
- ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20#212
metadata: null
Expand Down Expand Up @@ -36,4 +37,5 @@ update proposal:
validity range:
lower bound: null
upper bound: null
voters: null
withdrawals: null
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ certificates: null
collateral inputs: []
era: Babbage
fee: 21300 Lovelace
governance actions: null
inputs:
- ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20#213
metadata:
Expand Down Expand Up @@ -38,4 +39,5 @@ update proposal: null
validity range:
lower bound: null
upper bound: null
voters: null
withdrawals: null
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ certificates: null
collateral inputs: []
era: Babbage
fee: 21300 Lovelace
governance actions: null
inputs:
- ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20#213
metadata:
Expand Down Expand Up @@ -71,4 +72,5 @@ update proposal: null
validity range:
lower bound: null
upper bound: null
voters: null
withdrawals: null
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ collateral inputs:
- c9765d7d0e3955be8920e6d7a38e1f3f2032eac48c7c59b0b9193caa87727e7e#256
era: Babbage
fee: 213 Lovelace
governance actions: null
inputs:
- ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20#213
metadata: null
Expand All @@ -23,4 +24,5 @@ update proposal: null
validity range:
lower bound: null
upper bound: null
voters: null
withdrawals: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"auxiliary scripts": null,
"certificates": null,
"collateral inputs": [],
"era": "Conway",
"fee": "181517 Lovelace",
"governance actions": [
{
"anchor": {
"dataHash": "6fad941a5236c151b44c23458fb99d6812bbc5c6eb3a3a8a5d2518e8be8962ab",
"url": "https://github.com/carloslodelar/proposals/blob/main/why-hardfork-to-10.txt"
},
"deposit": 50000000000,
"governance action": {
"contents": [
null,
{
"major": 10,
"minor": 0
}
],
"tag": "HardForkInitiation"
},
"return address": {
"credential": {
"keyHash": "08f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d3"
},
"network": "Testnet"
}
}
],
"inputs": [
"e51d839ec4ef4b3522a965dab8cbd0a2c52ecd5959a469384c001c8691a98ab6#0"
],
"metadata": null,
"mint": null,
"outputs": [
{
"address": "addr_test1qp39w0fa0ccdc4gmg87puydf2kxt5mgt0vteq4a22ktrcssg7ysmx64l90xa0k4z25wpuejngya833qeu9cdxvveynfscsskf5",
"address era": "Shelley",
"amount": {
"lovelace": 49999818483
},
"network": "Testnet",
"payment credential key hash": "62573d3d7e30dc551b41fc1e11a9558cba6d0b7b179057aa55963c42",
"reference script": null,
"stake reference": {
"stake credential key hash": "08f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d3"
}
}
],
"redeemers": {},
"reference inputs": [],
"required signers (payment key hashes needed for scripts)": null,
"return collateral": null,
"total collateral": null,
"update proposal": null,
"validity range": {
"lower bound": null,
"upper bound": null
},
"voters": {},
"withdrawals": null,
"witnesses": [
{
"key": "VKey (VerKeyEd25519DSIGN \"8e090717d4c91437d3b8c467acc850197485913efdbfb48114a4d6cf0ca2dc02\")",
"signature": "SignedDSIGN (SigEd25519DSIGN \"28230d2507267600d17c7f062d9f3184f4686af570c31e2f9ed652d339d776dcd72fccf30dd17bc077d2615845bbad64fd6ddffdba5b2874651d0c3533e10d0b\")"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"auxiliary scripts": null,
"certificates": null,
"collateral inputs": [],
"era": "Conway",
"fee": "185433 Lovelace",
"governance actions": [],
"inputs": [
"96e3be606ca03f67b0d299ca0eb0d660670edaa8452fffcc4bfccd8757a9b45d#0"
],
"metadata": null,
"mint": null,
"outputs": [
{
"address": "addr_test1qp39w0fa0ccdc4gmg87puydf2kxt5mgt0vteq4a22ktrcssg7ysmx64l90xa0k4z25wpuejngya833qeu9cdxvveynfscsskf5",
"address era": "Shelley",
"amount": {
"lovelace": 49497089775
},
"network": "Testnet",
"payment credential key hash": "62573d3d7e30dc551b41fc1e11a9558cba6d0b7b179057aa55963c42",
"reference script": null,
"stake reference": {
"stake credential key hash": "08f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d3"
}
}
],
"redeemers": {},
"reference inputs": [],
"required signers (payment key hashes needed for scripts)": null,
"return collateral": null,
"total collateral": null,
"update proposal": null,
"validity range": {
"lower bound": null,
"upper bound": null
},
"voters": {
"drep-keyHash-efda35608d806f37ac3948f1ddaff912e5f9130e9b52035c166bd8f2": {
"4c2121ececebac2a364878d295c959029e55225b426dfea5e0511ae0abc28d50#0": {
"anchor": null,
"decision": "VoteYes"
},
"67820c121787464a9b670cf4c648f67cabd9573eb71b220214971ce467d25027#0": {
"anchor": null,
"decision": "VoteNo"
},
"9bd2b6547ab8e8ed5c34049d6b984772a8352ac70e92198e1a7f6cdbb12d6397#0": {
"anchor": null,
"decision": "Abstain"
}
}
},
"withdrawals": null,
"witnesses": [
{
"key": "VKey (VerKeyEd25519DSIGN \"8e090717d4c91437d3b8c467acc850197485913efdbfb48114a4d6cf0ca2dc02\")",
"signature": "SignedDSIGN (SigEd25519DSIGN \"8e92da471878c0fe6b97a4390df93cc81a6b84348bf1b393e6270b680b0d6402c9681672f393a54b35817c92884f7806ed5a00811e5aff6cfee8468100fecb04\")"
},
{
"key": "VKey (VerKeyEd25519DSIGN \"8a10253789af22a6493dbe6a3a415732152989a9bd00b010e18f07a7cabcc74a\")",
"signature": "SignedDSIGN (SigEd25519DSIGN \"80bf834e873c59259fe6248cb98d7de49e7214f293895bbc7e0064030c7de10e565f867c5dfded379aaa8bfd2140f41ace6301f02e2b6678ad020a72e26b6505\")"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ certificates: null
collateral inputs: null
era: Mary
fee: 139 Lovelace
governance actions: null
inputs:
- fe5dd07fb576bff960d6e066eade5b26cdb5afebe29f76ea58d0a098bce5d891#135
metadata: null
Expand Down Expand Up @@ -42,4 +43,5 @@ update proposal: null
validity range:
lower bound: 140
upper bound: null
voters: null
withdrawals: null
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ certificates:
collateral inputs: null
era: Shelley
fee: 32 Lovelace
governance actions: null
inputs:
- fe5dd07fb576bff960d6e066eade5b26cdb5afebe29f76ea58d0a098bce5d891#29
metadata: null
Expand Down Expand Up @@ -76,6 +77,7 @@ update proposal:
validity range:
lower bound: null
upper bound: 33
voters: null
withdrawals:
- address: stake_test1up00fz9lyqs5sjks82k22eqz7a9srym9vysjgp3h2ua2v2cm522kg
amount: 42 Lovelace
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Witnessed Tx ConwayEra",
"description": "Ledger Cddl Format",
"cborHex": "84a400d9010281825820e51d839ec4ef4b3522a965dab8cbd0a2c52ecd5959a469384c001c8691a98ab60001818258390062573d3d7e30dc551b41fc1e11a9558cba6d0b7b179057aa55963c4208f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d31b0000000ba438aef3021a0002c50d14d9010281841b0000000ba43b7400581de008f121b36abf2bcdd7daa2551c1e6653413a78c419e170d3319924d38301f6820a0082784b68747470733a2f2f6769746875622e636f6d2f6361726c6f736c6f64656c61722f70726f706f73616c732f626c6f622f6d61696e2f7768792d68617264666f726b2d746f2d31302e74787458206fad941a5236c151b44c23458fb99d6812bbc5c6eb3a3a8a5d2518e8be8962aba100d90102818258208e090717d4c91437d3b8c467acc850197485913efdbfb48114a4d6cf0ca2dc02584028230d2507267600d17c7f062d9f3184f4686af570c31e2f9ed652d339d776dcd72fccf30dd17bc077d2615845bbad64fd6ddffdba5b2874651d0c3533e10d0bf5f6"
}
Loading

0 comments on commit 1f81d15

Please sign in to comment.