From cd7ad367607de872316488eba35dde7019ed1466 Mon Sep 17 00:00:00 2001 From: John Ky Date: Wed, 11 Oct 2023 22:55:17 +1100 Subject: [PATCH 1/2] Command argument types for governance key commands --- .../EraBased/Commands/Governance/Committee.hs | 68 ++++++++++----- .../EraBased/Options/Governance/Committee.hs | 35 ++++---- .../CLI/EraBased/Run/Governance/Committee.hs | 82 +++++++++++-------- 3 files changed, 118 insertions(+), 67 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs index cb9da0bc50..1d9719d4e9 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs @@ -1,8 +1,14 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE LambdaCase #-} module Cardano.CLI.EraBased.Commands.Governance.Committee ( GovernanceCommitteeCmds(..) + , GovernanceCommitteeKeyGenColdCmdArgs(..) + , GovernanceCommitteeKeyGenHotCmdArgs(..) + , GovernanceCommitteeKeyHashCmdArgs(..) + , GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs(..) + , GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs(..) , renderGovernanceCommitteeCmds ) where @@ -14,28 +20,50 @@ import Cardano.CLI.Types.Key.VerificationKey import Data.Text (Text) data GovernanceCommitteeCmds era - = GovernanceCommitteeKeyGenColdCmd - (ConwayEraOnwards era) - (File (VerificationKey ()) Out) - (File (SigningKey ()) Out) - | GovernanceCommitteeKeyGenHotCmd - (ConwayEraOnwards era) - (File (VerificationKey ()) Out) - (File (SigningKey ()) Out) - | GovernanceCommitteeKeyHashCmd -- TODO to be moved under the top-level command group "key" - (ConwayEraOnwards era) - AnyVerificationKeySource - | GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd -- TODO to be moved under the top-level command group "key" - (ConwayEraOnwards era) - (VerificationKeyOrHashOrFile CommitteeColdKey) - (VerificationKeyOrHashOrFile CommitteeHotKey) - (File () Out) - | GovernanceCommitteeCreateColdKeyResignationCertificateCmd - (ConwayEraOnwards era) - (VerificationKeyOrHashOrFile CommitteeColdKey) - (File () Out) + = GovernanceCommitteeKeyGenColdCmd (GovernanceCommitteeKeyGenColdCmdArgs era) + | GovernanceCommitteeKeyGenHotCmd (GovernanceCommitteeKeyGenHotCmdArgs era) + | GovernanceCommitteeKeyHashCmd (GovernanceCommitteeKeyHashCmdArgs era) -- TODO to be moved under the top-level command group "key" + | GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd (GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era) -- TODO to be moved under the top-level command group "key" + | GovernanceCommitteeCreateColdKeyResignationCertificateCmd (GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs era) deriving Show +data GovernanceCommitteeKeyGenColdCmdArgs era = + GovernanceCommitteeKeyGenColdCmdArgs + { eon :: !(ConwayEraOnwards era) + , vkeyOutFile :: !(File (VerificationKey ()) Out) + , skeyOutFile :: !(File (SigningKey ()) Out) + } deriving Show + +data GovernanceCommitteeKeyGenHotCmdArgs era = + GovernanceCommitteeKeyGenHotCmdArgs + { eon :: !(ConwayEraOnwards era) + , vkeyOutFile :: !(File (VerificationKey ()) Out) + , skeyOutFile :: !(File (SigningKey ()) Out) + } deriving Show + + -- TODO to be moved under the top-level command group "key" +data GovernanceCommitteeKeyHashCmdArgs era = + GovernanceCommitteeKeyHashCmdArgs + { eon :: !(ConwayEraOnwards era) + , vkeySource :: !AnyVerificationKeySource + } deriving Show + +-- TODO to be moved under the top-level command group "key" +data GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era = + GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs + { eon :: !(ConwayEraOnwards era) + , vkeyColdKeySource :: !(VerificationKeyOrHashOrFile CommitteeColdKey) + , vkeyHotKeySource :: !(VerificationKeyOrHashOrFile CommitteeHotKey) + , outFile :: !(File () Out) + } deriving Show + +data GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs era = + GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs + { eon :: !(ConwayEraOnwards era) + , vkeyColdKeySource :: !(VerificationKeyOrHashOrFile CommitteeColdKey) + , outFile :: !(File () Out) + } deriving Show + renderGovernanceCommitteeCmds :: GovernanceCommitteeCmds era -> Text renderGovernanceCommitteeCmds = \case GovernanceCommitteeKeyGenColdCmd {} -> diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs index 71d91c1c76..f6548bd323 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs @@ -46,9 +46,10 @@ pGovernanceCommitteeKeyGenColdCmd era = do => ConwayEraOnwards era -> Parser (GovernanceCommitteeCmds era) pCmd w = - GovernanceCommitteeKeyGenColdCmd w - <$> pColdVerificationKeyFile - <*> pColdSigningKeyFile + fmap GovernanceCommitteeKeyGenColdCmd $ + GovernanceCommitteeKeyGenColdCmdArgs w + <$> pColdVerificationKeyFile + <*> pColdSigningKeyFile pGovernanceCommitteeKeyGenHotCmd :: () => CardanoEra era @@ -67,9 +68,10 @@ pGovernanceCommitteeKeyGenHotCmd era = do => ConwayEraOnwards era -> Parser (GovernanceCommitteeCmds era) pCmd w = - GovernanceCommitteeKeyGenHotCmd w - <$> pVerificationKeyFileOut - <*> pSigningKeyFileOut + fmap GovernanceCommitteeKeyGenHotCmd $ + GovernanceCommitteeKeyGenHotCmdArgs w + <$> pVerificationKeyFileOut + <*> pSigningKeyFileOut pGovernanceCommitteeKeyHashCmd :: () => CardanoEra era @@ -79,8 +81,9 @@ pGovernanceCommitteeKeyHashCmd era = do pure $ subParser "key-hash" $ Opt.info - ( GovernanceCommitteeKeyHashCmd w - <$> pAnyVerificationKeySource "Constitutional Committee Member key (hot or cold)" + ( fmap GovernanceCommitteeKeyHashCmd $ + GovernanceCommitteeKeyHashCmdArgs w + <$> pAnyVerificationKeySource "Constitutional Committee Member key (hot or cold)" ) $ Opt.progDesc $ mconcat @@ -95,10 +98,11 @@ pGovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd era = do pure $ subParser "create-hot-key-authorization-certificate" $ Opt.info - ( GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd w - <$> pCommitteeColdVerificationKeyOrHashOrFile - <*> pCommitteeHotKeyOrHashOrFile - <*> pOutputFile + ( fmap GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd $ + GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs w + <$> pCommitteeColdVerificationKeyOrHashOrFile + <*> pCommitteeHotKeyOrHashOrFile + <*> pOutputFile ) $ Opt.progDesc $ mconcat @@ -113,9 +117,10 @@ pGovernanceCommitteeCreateColdKeyResignationCertificateCmd era = do pure $ subParser "create-cold-key-resignation-certificate" $ Opt.info - ( GovernanceCommitteeCreateColdKeyResignationCertificateCmd w - <$> pCommitteeColdVerificationKeyOrHashOrFile - <*> pOutputFile + ( fmap GovernanceCommitteeCreateColdKeyResignationCertificateCmd $ + GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs w + <$> pCommitteeColdVerificationKeyOrHashOrFile + <*> pOutputFile ) $ Opt.progDesc $ mconcat diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs index edaba9b20f..e0056f2286 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs @@ -1,5 +1,7 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} module Cardano.CLI.EraBased.Run.Governance.Committee ( runGovernanceCommitteeCmds @@ -10,6 +12,7 @@ import Cardano.Api import Cardano.Api.Shelley import Cardano.CLI.EraBased.Commands.Governance.Committee +import qualified Cardano.CLI.EraBased.Commands.Governance.Committee as Cmd import Cardano.CLI.Types.Errors.GovernanceCommitteeError import Cardano.CLI.Types.Key import Cardano.CLI.Types.Key.VerificationKey @@ -26,23 +29,26 @@ runGovernanceCommitteeCmds :: () => GovernanceCommitteeCmds era -> ExceptT GovernanceCommitteeError IO () runGovernanceCommitteeCmds = \case - GovernanceCommitteeKeyGenColdCmd era vk sk -> - runGovernanceCommitteeKeyGenCold era vk sk - GovernanceCommitteeKeyGenHotCmd era vk sk -> - runGovernanceCommitteeKeyGenHot era vk sk - GovernanceCommitteeKeyHashCmd era vk -> - runGovernanceCommitteeKeyHash era vk - GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd w cvk hvk out -> - runGovernanceCommitteeCreateHotKeyAuthorizationCertificate w cvk hvk out - GovernanceCommitteeCreateColdKeyResignationCertificateCmd w cvk out -> - runGovernanceCommitteeColdKeyResignationCertificate w cvk out + GovernanceCommitteeKeyGenColdCmd cmd -> + runGovernanceCommitteeKeyGenCold cmd + GovernanceCommitteeKeyGenHotCmd cmd -> + runGovernanceCommitteeKeyGenHot cmd + GovernanceCommitteeKeyHashCmd cmd -> + runGovernanceCommitteeKeyHash cmd + GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd cmd -> + runGovernanceCommitteeCreateHotKeyAuthorizationCertificate cmd + GovernanceCommitteeCreateColdKeyResignationCertificateCmd cmd -> + runGovernanceCommitteeColdKeyResignationCertificate cmd runGovernanceCommitteeKeyGenCold :: () - => ConwayEraOnwards era - -> File (VerificationKey ()) Out - -> File (SigningKey ()) Out + => Cmd.GovernanceCommitteeKeyGenColdCmdArgs era -> ExceptT GovernanceCommitteeError IO () -runGovernanceCommitteeKeyGenCold _w vkeyPath skeyPath = do +runGovernanceCommitteeKeyGenCold + Cmd.GovernanceCommitteeKeyGenColdCmdArgs + { Cmd.eon = _eon + , Cmd.vkeyOutFile = vkeyPath + , Cmd.skeyOutFile = skeyPath + } = do skey <- liftIO $ generateSigningKey AsCommitteeColdKey let vkey = getVerificationKey skey @@ -61,11 +67,14 @@ runGovernanceCommitteeKeyGenCold _w vkeyPath skeyPath = do vkeyDesc = "Constitutional Committee Cold Verification Key" runGovernanceCommitteeKeyGenHot :: () - => ConwayEraOnwards era - -> File (VerificationKey ()) Out - -> File (SigningKey ()) Out + => Cmd.GovernanceCommitteeKeyGenHotCmdArgs era -> ExceptT GovernanceCommitteeError IO () -runGovernanceCommitteeKeyGenHot _w vkeyPath skeyPath = do +runGovernanceCommitteeKeyGenHot + Cmd.GovernanceCommitteeKeyGenHotCmdArgs + { Cmd.eon = _eon + , Cmd.vkeyOutFile = vkeyPath + , Cmd.skeyOutFile = skeyPath + } = do skey <- liftIO $ generateSigningKey AsCommitteeHotKey let vkey = getVerificationKey skey @@ -92,10 +101,13 @@ data SomeCommitteeKey f | ACommitteeColdKey (f CommitteeColdKey) runGovernanceCommitteeKeyHash :: () - => ConwayEraOnwards era - -> AnyVerificationKeySource + => Cmd.GovernanceCommitteeKeyHashCmdArgs era -> ExceptT GovernanceCommitteeError IO () -runGovernanceCommitteeKeyHash _w vkeySource = do +runGovernanceCommitteeKeyHash + Cmd.GovernanceCommitteeKeyHashCmdArgs + { Cmd.eon = _w + , Cmd.vkeySource + } = do vkey <- case vkeySource of AnyVerificationKeySourceOfText vkText -> do @@ -126,13 +138,16 @@ runGovernanceCommitteeKeyHash _w vkeySource = do . verificationKeyHash runGovernanceCommitteeCreateHotKeyAuthorizationCertificate :: () - => ConwayEraOnwards era - -> VerificationKeyOrHashOrFile CommitteeColdKey - -> VerificationKeyOrHashOrFile CommitteeHotKey - -> File () Out + => Cmd.GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era -> ExceptT GovernanceCommitteeError IO () -runGovernanceCommitteeCreateHotKeyAuthorizationCertificate w coldVkOrHashOrFp hotVkOrHashOrFp oFp = - conwayEraOnwardsConstraints w $ do +runGovernanceCommitteeCreateHotKeyAuthorizationCertificate + Cmd.GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs + { Cmd.eon = eon + , Cmd.vkeyColdKeySource = coldVkOrHashOrFp + , Cmd.vkeyHotKeySource = hotVkOrHashOrFp + , Cmd.outFile = oFp + } = + conwayEraOnwardsConstraints eon $ do CommitteeColdKeyHash coldVKHash <- lift (readVerificationKeyOrHashOrTextEnvFile AsCommitteeColdKey coldVkOrHashOrFp) & onLeft (left . GovernanceCommitteeCmdKeyReadError) @@ -141,7 +156,7 @@ runGovernanceCommitteeCreateHotKeyAuthorizationCertificate w coldVkOrHashOrFp ho lift (readVerificationKeyOrHashOrTextEnvFile AsCommitteeHotKey hotVkOrHashOrFp) & onLeft (left . GovernanceCommitteeCmdKeyReadError) - makeCommitteeHotKeyAuthorizationCertificate (CommitteeHotKeyAuthorizationRequirements w coldVKHash hotVkHash) + makeCommitteeHotKeyAuthorizationCertificate (CommitteeHotKeyAuthorizationRequirements eon coldVKHash hotVkHash) & textEnvelopeToJSON (Just genKeyDelegCertDesc) & writeLazyByteStringFile oFp & firstExceptT GovernanceCommitteeCmdTextEnvWriteError . newExceptT @@ -151,11 +166,14 @@ runGovernanceCommitteeCreateHotKeyAuthorizationCertificate w coldVkOrHashOrFp ho genKeyDelegCertDesc = "Constitutional Committee Hot Key Registration Certificate" runGovernanceCommitteeColdKeyResignationCertificate :: () - => ConwayEraOnwards era - -> VerificationKeyOrHashOrFile CommitteeColdKey - -> File () Out + => Cmd.GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs era -> ExceptT GovernanceCommitteeError IO () -runGovernanceCommitteeColdKeyResignationCertificate w coldVkOrHashOrFp oFp = +runGovernanceCommitteeColdKeyResignationCertificate + Cmd.GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs + { Cmd.eon = w + , Cmd.vkeyColdKeySource = coldVkOrHashOrFp + , Cmd.outFile = oFp + } = conwayEraOnwardsConstraints w $ do CommitteeColdKeyHash coldVKHash <- lift (readVerificationKeyOrHashOrTextEnvFile AsCommitteeColdKey coldVkOrHashOrFp) From 3f7cf27cddc43716af90fb34288ed949c3636fe5 Mon Sep 17 00:00:00 2001 From: John Ky Date: Wed, 11 Oct 2023 23:11:42 +1100 Subject: [PATCH 2/2] Delete TODOs --- .../Cardano/CLI/EraBased/Commands/Governance/Committee.hs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs index 1d9719d4e9..141a3d77f8 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs @@ -22,8 +22,8 @@ import Data.Text (Text) data GovernanceCommitteeCmds era = GovernanceCommitteeKeyGenColdCmd (GovernanceCommitteeKeyGenColdCmdArgs era) | GovernanceCommitteeKeyGenHotCmd (GovernanceCommitteeKeyGenHotCmdArgs era) - | GovernanceCommitteeKeyHashCmd (GovernanceCommitteeKeyHashCmdArgs era) -- TODO to be moved under the top-level command group "key" - | GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd (GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era) -- TODO to be moved under the top-level command group "key" + | GovernanceCommitteeKeyHashCmd (GovernanceCommitteeKeyHashCmdArgs era) + | GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd (GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era) | GovernanceCommitteeCreateColdKeyResignationCertificateCmd (GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs era) deriving Show @@ -41,14 +41,12 @@ data GovernanceCommitteeKeyGenHotCmdArgs era = , skeyOutFile :: !(File (SigningKey ()) Out) } deriving Show - -- TODO to be moved under the top-level command group "key" data GovernanceCommitteeKeyHashCmdArgs era = GovernanceCommitteeKeyHashCmdArgs { eon :: !(ConwayEraOnwards era) , vkeySource :: !AnyVerificationKeySource } deriving Show --- TODO to be moved under the top-level command group "key" data GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era = GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs { eon :: !(ConwayEraOnwards era)