Skip to content

Commit

Permalink
Merge pull request #425 from input-output-hk/newhoggy/command-argumen…
Browse files Browse the repository at this point in the history
…t-types-for-drep-commands

Command argument types for `drep` commands
  • Loading branch information
newhoggy authored Nov 2, 2023
2 parents 5a0d2f7 + 1eebb16 commit eb8b0a5
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 124 deletions.
81 changes: 54 additions & 27 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/DRep.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.EraBased.Commands.Governance.DRep
( GovernanceDRepCmds (..),
renderGovernanceDRepCmds,
( GovernanceDRepCmds (..)
, renderGovernanceDRepCmds

, GovernanceDRepKeyGenCmdArgs(..)
, GovernanceDRepIdCmdArgs(..)
, GovernanceDRepRegistrationCertificateCmdArgs(..)
, GovernanceDRepRetirementCertificateCmdArgs(..)
, GovernanceDRepMetadataHashCmdArgs(..)
)
where

Expand All @@ -17,36 +24,56 @@ import Cardano.CLI.Types.Key
import Data.Text (Text)

data GovernanceDRepCmds era
= GovernanceDRepGenerateKeyCmd
(ConwayEraOnwards era)
(File (VerificationKey ()) Out)
(File (SigningKey ()) Out)
| GovernanceDRepIdCmd
(ConwayEraOnwards era)
(VerificationKeyOrFile DRepKey)
IdOutputFormat
(Maybe (File () Out))
| GovernanceDRepRegistrationCertificateCmd
(ConwayEraOnwards era)
(VerificationKeyOrHashOrFile DRepKey)
Lovelace
(Maybe (Ledger.Anchor (Ledger.EraCrypto (ShelleyLedgerEra era))))
(File () Out)
| GovernanceDRepRetirementCertificateCmd
(ConwayEraOnwards era)
(VerificationKeyOrHashOrFile DRepKey)
Lovelace
(File () Out)
| GovernanceDRepMetadataHashCmd
(ConwayEraOnwards era)
(DRepMetadataFile In)
(Maybe (File () Out))
= GovernanceDRepKeyGenCmd !(GovernanceDRepKeyGenCmdArgs era)
| GovernanceDRepIdCmd !(GovernanceDRepIdCmdArgs era)
| GovernanceDRepRegistrationCertificateCmd !(GovernanceDRepRegistrationCertificateCmdArgs era)
| GovernanceDRepRetirementCertificateCmd !(GovernanceDRepRetirementCertificateCmdArgs era)
| GovernanceDRepMetadataHashCmd !(GovernanceDRepMetadataHashCmdArgs era)

data GovernanceDRepKeyGenCmdArgs era =
GovernanceDRepKeyGenCmdArgs
{ eon :: !(ConwayEraOnwards era)
, vkeyFile :: !(File (VerificationKey ()) Out)
, skeyFile :: !(File (SigningKey ()) Out)
}

data GovernanceDRepIdCmdArgs era =
GovernanceDRepIdCmdArgs
{ eon :: !(ConwayEraOnwards era)
, vkeySource :: !(VerificationKeyOrFile DRepKey)
, idOutputFormat :: !IdOutputFormat
, mOutFile :: !(Maybe (File () Out))
}

data GovernanceDRepRegistrationCertificateCmdArgs era =
GovernanceDRepRegistrationCertificateCmdArgs
{ eon :: !(ConwayEraOnwards era)
, drepVkeyHashSource :: !(VerificationKeyOrHashOrFile DRepKey)
, deposit :: !Lovelace
, mAnchor :: !(Maybe (Ledger.Anchor (Ledger.EraCrypto (ShelleyLedgerEra era))))
, outFile :: !(File () Out)
}

data GovernanceDRepRetirementCertificateCmdArgs era =
GovernanceDRepRetirementCertificateCmdArgs
{ eon :: !(ConwayEraOnwards era)
, vkeyHashSource :: !(VerificationKeyOrHashOrFile DRepKey)
, deposit :: !Lovelace
, outFile :: !(File () Out)
}

data GovernanceDRepMetadataHashCmdArgs era =
GovernanceDRepMetadataHashCmdArgs
{ eon :: !(ConwayEraOnwards era)
, metadataFile :: !(DRepMetadataFile In)
, mOutFile :: !(Maybe (File () Out))
}

renderGovernanceDRepCmds :: ()
=> GovernanceDRepCmds era
-> Text
renderGovernanceDRepCmds = \case
GovernanceDRepGenerateKeyCmd {} ->
GovernanceDRepKeyGenCmd {} ->
"governance drep key-gen"
GovernanceDRepIdCmd {} ->
"governance drep id"
Expand Down
38 changes: 22 additions & 16 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ pGovernanceDRepKeyGenCmd era = do
pure
$ subParser "key-gen"
$ Opt.info
( GovernanceDRepGenerateKeyCmd w
<$> pVerificationKeyFileOut
<*> pSigningKeyFileOut
( fmap GovernanceDRepKeyGenCmd $
GovernanceDRepKeyGenCmdArgs w
<$> pVerificationKeyFileOut
<*> pSigningKeyFileOut
)
$ Opt.progDesc "Generate Delegate Representative verification and signing keys."

Expand All @@ -66,10 +67,11 @@ pGovernanceDRepKeyIdCmd era = do
pure
$ subParser "id"
$ Opt.info
( GovernanceDRepIdCmd w
<$> pDRepVerificationKeyOrFile
<*> pDRepIdOutputFormat
<*> optional pOutputFile
( fmap GovernanceDRepIdCmd $
GovernanceDRepIdCmdArgs w
<$> pDRepVerificationKeyOrFile
<*> pDRepIdOutputFormat
<*> optional pOutputFile
)
$ Opt.progDesc "Generate a drep id."

Expand Down Expand Up @@ -97,7 +99,9 @@ pRegistrationCertificateCmd era = do
$ Opt.info (conwayEraOnwardsConstraints w $ mkParser w)
$ Opt.progDesc "Create a registration certificate."
where
mkParser w = GovernanceDRepRegistrationCertificateCmd w
mkParser w =
fmap GovernanceDRepRegistrationCertificateCmd $
GovernanceDRepRegistrationCertificateCmdArgs w
<$> pDRepVerificationKeyOrHashOrFile
<*> pKeyRegistDeposit
<*> pDRepMetadata
Expand Down Expand Up @@ -131,10 +135,11 @@ pRetirementCertificateCmd era = do
pure
$ subParser "retirement-certificate"
$ Opt.info
( GovernanceDRepRetirementCertificateCmd w
<$> pDRepVerificationKeyOrHashOrFile
<*> pDrepDeposit
<*> pOutputFile
( fmap GovernanceDRepRetirementCertificateCmd $
GovernanceDRepRetirementCertificateCmdArgs w
<$> pDRepVerificationKeyOrHashOrFile
<*> pDrepDeposit
<*> pOutputFile
)
$ Opt.progDesc "Create a DRep retirement certificate."

Expand All @@ -146,10 +151,11 @@ pGovernanceDrepMetadataHashCmd era = do
pure
$ subParser "metadata-hash"
$ Opt.info
( GovernanceDRepMetadataHashCmd w
<$> pFileInDirection "drep-metadata-file" "JSON Metadata file to hash."
<*> pMaybeOutputFile
)
( fmap GovernanceDRepMetadataHashCmd $
GovernanceDRepMetadataHashCmdArgs w
<$> pFileInDirection "drep-metadata-file" "JSON Metadata file to hash."
<*> pMaybeOutputFile
)
$ Opt.progDesc "Calculate the hash of a metadata file."

--------------------------------------------------------------------------------
Expand Down
18 changes: 0 additions & 18 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@
module Cardano.CLI.EraBased.Run.Governance
( runGovernanceMIRCertificatePayStakeAddrs
, runGovernanceMIRCertificateTransfer
, runGovernanceDRepKeyGen
) where

import Cardano.Api
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley

import qualified Cardano.CLI.EraBased.Run.Key as Key
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Errors.GovernanceCmdError
import qualified Cardano.Ledger.Shelley.TxBody as Shelley

import Control.Monad
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -81,18 +78,3 @@ runGovernanceMIRCertificateTransfer w ll oFp direction = do
mirCertDesc :: TransferDirection -> TextEnvelopeDescr
mirCertDesc TransferToTreasury = "MIR Certificate Send To Treasury"
mirCertDesc TransferToReserves = "MIR Certificate Send To Reserves"

runGovernanceDRepKeyGen
:: ConwayEraOnwards era
-> VerificationKeyFile Out
-> SigningKeyFile Out
-> ExceptT GovernanceCmdError IO ()
runGovernanceDRepKeyGen _w vkeyPath skeyPath = firstExceptT GovernanceCmdWriteFileError $ do
skey <- liftIO $ generateSigningKey AsDRepKey
let vkey = getVerificationKey skey
newExceptT $ writeLazyByteStringFile skeyPath (textEnvelopeToJSON (Just skeyDesc) skey)
newExceptT $ writeLazyByteStringFile vkeyPath (textEnvelopeToJSON (Just Key.drepKeyEnvelopeDescr) vkey)
where
skeyDesc :: TextEnvelopeDescr
skeyDesc = "Delegate Representative Signing Key"

Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ runGovernanceCommitteeKeyGenCold :: ()
-> ExceptT GovernanceCommitteeError IO ()
runGovernanceCommitteeKeyGenCold
Cmd.GovernanceCommitteeKeyGenColdCmdArgs
{ Cmd.eon = _eon
, Cmd.vkeyOutFile = vkeyPath
{ Cmd.vkeyOutFile = vkeyPath
, Cmd.skeyOutFile = skeyPath
} = do
skey <- liftIO $ generateSigningKey AsCommitteeColdKey
Expand Down Expand Up @@ -105,8 +104,7 @@ runGovernanceCommitteeKeyHash :: ()
-> ExceptT GovernanceCommitteeError IO ()
runGovernanceCommitteeKeyHash
Cmd.GovernanceCommitteeKeyHashCmdArgs
{ Cmd.eon = _w
, Cmd.vkeySource
{ Cmd.vkeySource
} = do
vkey <-
case vkeySource of
Expand Down
Loading

0 comments on commit eb8b0a5

Please sign in to comment.