Skip to content

Commit

Permalink
Merge pull request #364 from input-output-hk/newhoggy/command-arg-typ…
Browse files Browse the repository at this point in the history
…es-for-governance-key-commands

Command argument types for governance key commands
  • Loading branch information
newhoggy authored Oct 11, 2023
2 parents eb0e52b + 3f7cf27 commit 4487ca9
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -14,28 +20,48 @@ 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)
| GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd (GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era)
| 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

data GovernanceCommitteeKeyHashCmdArgs era =
GovernanceCommitteeKeyHashCmdArgs
{ eon :: !(ConwayEraOnwards era)
, vkeySource :: !AnyVerificationKeySource
} deriving Show

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 {} ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
82 changes: 50 additions & 32 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}

module Cardano.CLI.EraBased.Run.Governance.Committee
( runGovernanceCommitteeCmds
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 4487ca9

Please sign in to comment.