From 53b168ac86498b308b42b8a4b2c3645053e20f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Tue, 19 Sep 2023 21:26:20 +0200 Subject: [PATCH 1/4] cardano-cli: add governance create-info command --- .../EraBased/Commands/Governance/Actions.hs | 19 +++++++++--- .../EraBased/Options/Governance/Actions.hs | 20 +++++++++++++ .../CLI/EraBased/Run/Governance/Actions.hs | 30 ++++++++++++++----- 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs index 251de232a7..162022d770 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs @@ -7,6 +7,7 @@ module Cardano.CLI.EraBased.Commands.Governance.Actions , GovernanceActionCmds(..) , NewCommitteeCmd(..) , NewConstitutionCmd(..) + , NewInfoCmd(..) , NoConfidenceCmd(..) , TreasuryWithdrawalCmd(..) , renderGovernanceActionCmds @@ -41,10 +42,9 @@ data GovernanceActionCmds era | GovernanceActionTreasuryWithdrawalCmd (ConwayEraOnwards era) TreasuryWithdrawalCmd - | GoveranceActionInfoCmd -- TODO: Conway era - ledger currently provides a placeholder constructor + | GovernanceActionInfoCmd (ConwayEraOnwards era) - (File () In) - (File () Out) + NewInfoCmd deriving Show data NewCommitteeCmd @@ -74,6 +74,17 @@ data NewConstitutionCmd , encFilePath :: File () Out } deriving Show +-- | Datatype to carry data for the create-info governance action +data NewInfoCmd + = NewInfoCmd + { niNetwork :: Ledger.Network + , niDeposit :: Lovelace + , niStakeCredential :: AnyStakeIdentifier + , niProposalUrl :: ProposalUrl + , niProposalHashSource :: ProposalHashSource + , niOutputFilePath :: File () Out + } deriving Show + data NoConfidenceCmd = NoConfidenceCmd { ncNetwork :: Ledger.Network @@ -114,7 +125,7 @@ renderGovernanceActionCmds = ("governance action " <>) . \case GovernanceActionCreateNoConfidenceCmd {} -> "create-no-confidence" - GoveranceActionInfoCmd {} -> + GovernanceActionInfoCmd {} -> "create-info" data AnyStakeIdentifier diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs index 00add08074..c391f0d150 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs @@ -33,11 +33,31 @@ pGovernanceActionCmds era = ) [ pGovernanceActionNewConstitutionCmd era , pGovernanceActionNewCommitteeCmd era + , pGovernanceActionNewInfoCmd era , pGovernanceActionNoConfidenceCmd era , pGovernanceActionProtocolParametersUpdateCmd era , pGovernanceActionTreasuryWithdrawalCmd era ] +pGovernanceActionNewInfoCmd + :: CardanoEra era + -> Maybe (Parser (GovernanceActionCmds era)) +pGovernanceActionNewInfoCmd era = do + cOn <- maybeFeatureInEra era + pure + $ subParser "create-info" + $ Opt.info + ( fmap (GovernanceActionInfoCmd cOn) $ + NewInfoCmd + <$> pNetwork + <*> pGovActionDeposit + <*> pAnyStakeIdentifier + <*> pProposalUrl + <*> pProposalHashSource + <*> pFileOutDirection "out-file" "Path to action file to be used later on with build or build-raw " + ) + $ Opt.progDesc "Create an info action." + pGovernanceActionNewConstitutionCmd :: CardanoEra era diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs index cf396c150e..241db28f0d 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs @@ -2,7 +2,6 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TupleSections #-} -{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} module Cardano.CLI.EraBased.Run.Governance.Actions @@ -23,7 +22,6 @@ import Cardano.CLI.Types.Key import qualified Cardano.Ledger.Conway.Governance as Ledger import Control.Monad.Except (ExceptT) -import Control.Monad.IO.Class (liftIO) import Control.Monad.Trans.Except.Extra import Data.Function import qualified Data.Map.Strict as Map @@ -47,16 +45,32 @@ runGovernanceActionCmds = \case GovernanceActionCreateNoConfidenceCmd cOn noConfidence -> runGovernanceActionCreateNoConfidenceCmd cOn noConfidence - GoveranceActionInfoCmd cOn iFp oFp -> - runGovernanceActionInfoCmd cOn iFp oFp + GovernanceActionInfoCmd cOn newInfo -> + runGovernanceActionInfoCmd cOn newInfo runGovernanceActionInfoCmd :: ConwayEraOnwards era - -> File () In - -> File () Out + -> NewInfoCmd -> ExceptT GovernanceActionsError IO () -runGovernanceActionInfoCmd _cOn _iFp _oFp = - liftIO $ print @String "TODO: Conway era - implement runGovernanceActionInfoCmd - ledger currently provides a placeholder constructor" +runGovernanceActionInfoCmd cOn (NewInfoCmd network deposit returnAddr proposalUrl proposalHashSource outFp) = do + returnKeyHash <- readStakeKeyHash returnAddr + + proposalHash <- + proposalHashSourceToHash proposalHashSource + & firstExceptT GovernanceActionsCmdProposalError + + let proposalAnchor = Ledger.Anchor + { Ledger.anchorUrl = unProposalUrl proposalUrl + , Ledger.anchorDataHash = proposalHash + } + + let sbe = conwayEraOnwardsToShelleyBasedEra cOn + govAction = InfoAct + proposalProcedure = createProposalProcedure sbe network deposit returnKeyHash govAction proposalAnchor + + firstExceptT GovernanceActionsCmdWriteFileError . newExceptT + $ conwayEraOnwardsConstraints cOn + $ writeFileTextEnvelope outFp Nothing proposalProcedure -- TODO: Conway era - update with new ledger types from cardano-ledger-conway-1.7.0.0 runGovernanceActionCreateNoConfidenceCmd From b2ab7afcb4dde2996d8a1d60f9c2677572f81cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 20 Sep 2023 15:05:35 +0200 Subject: [PATCH 2/4] create-info governance action: adapt golden test file --- .../files/golden/help/conway_governance_action.cli | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action.cli index 5fc5b33033..e0bf9081a2 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action.cli @@ -1,6 +1,7 @@ Usage: cardano-cli conway governance action ( create-constitution | create-new-committee + | create-info | create-no-confidence | create-protocol-parameters-update | create-treasury-withdrawal @@ -14,6 +15,7 @@ Available options: Available commands: create-constitution Create a constitution. create-new-committee Create a new committee proposal. + create-info Create an info action. create-no-confidence Create a no confidence proposal. create-protocol-parameters-update Create a protocol parameters update. From e05d203bd7f1f0b518077cdbcb0513c3d49e074c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 20 Sep 2023 15:47:35 +0200 Subject: [PATCH 3/4] create-info governance action: adapt large golden test file (full help) --- .../cardano-cli-golden/files/golden/help.cli | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index 27a730bb45..59a4d94b54 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -6449,6 +6449,7 @@ Usage: cardano-cli conway governance query committee-state Usage: cardano-cli conway governance action ( create-constitution | create-new-committee + | create-info | create-no-confidence | create-protocol-parameters-update | create-treasury-withdrawal @@ -6524,6 +6525,24 @@ Usage: cardano-cli conway governance action create-new-committee Create a new committee proposal. +Usage: cardano-cli conway governance action create-info (--mainnet | --testnet) + --governance-action-deposit NATURAL + ( --stake-pool-verification-key STRING + | --cold-verification-key-file FILE + | --stake-pool-id STAKE_POOL_ID + | --stake-verification-key STRING + | --stake-verification-key-file FILE + | --stake-key-hash HASH + ) + --proposal-url TEXT + ( --proposal-text TEXT + | --proposal-file FILE + | --proposal-hash HASH + ) + --out-file FILE + + Create an info action. + Usage: cardano-cli conway governance action create-no-confidence ( --mainnet | --testnet From 988c91bdada5bca8b34cfc6bb6940c50386c4fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 20 Sep 2023 16:51:32 +0200 Subject: [PATCH 4/4] create-info governance action: add golden test file --- .../conway_governance_action_create-info.cli | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-info.cli diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-info.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-info.cli new file mode 100644 index 0000000000..ab609e015c --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-info.cli @@ -0,0 +1,43 @@ +Usage: cardano-cli conway governance action create-info (--mainnet | --testnet) + --governance-action-deposit NATURAL + ( --stake-pool-verification-key STRING + | --cold-verification-key-file FILE + | --stake-pool-id STAKE_POOL_ID + | --stake-verification-key STRING + | --stake-verification-key-file FILE + | --stake-key-hash HASH + ) + --proposal-url TEXT + ( --proposal-text TEXT + | --proposal-file FILE + | --proposal-hash HASH + ) + --out-file FILE + + Create an info action. + +Available options: + --mainnet Use the mainnet magic id. + --testnet Use the testnet magic id. + --governance-action-deposit NATURAL + Deposit required to submit a governance action. + --stake-pool-verification-key STRING + Stake pool verification key (Bech32 or hex-encoded). + --cold-verification-key-file FILE + Filepath of the stake pool verification key. + --stake-pool-id STAKE_POOL_ID + Stake pool ID/verification key hash (either + Bech32-encoded or hex-encoded). Zero or more + occurences of this option is allowed. + --stake-verification-key STRING + Stake verification key (Bech32 or hex-encoded). + --stake-verification-key-file FILE + Filepath of the staking verification key. + --stake-key-hash HASH Stake verification key hash (hex-encoded). + --proposal-url TEXT Proposal anchor URL + --proposal-text TEXT Input proposal as UTF-8 encoded text. + --proposal-file FILE Input proposal as a text file. + --proposal-hash HASH Proposal anchor data hash. + --out-file FILE Path to action file to be used later on with build or + build-raw + -h,--help Show this help text