Skip to content

Commit

Permalink
Move drep command to under governance command group
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed May 26, 2023
1 parent 06748d7 commit 5a8cadb
Show file tree
Hide file tree
Showing 28 changed files with 387 additions and 258 deletions.
2 changes: 1 addition & 1 deletion cardano-cli/cardano-cli.cabal
Expand Up @@ -82,10 +82,10 @@ library
Cardano.CLI.Shelley.Run
Cardano.CLI.Shelley.Run.Address
Cardano.CLI.Shelley.Run.Address.Info
Cardano.CLI.Shelley.Run.DRep
Cardano.CLI.Shelley.Run.Genesis
Cardano.CLI.Shelley.Run.Governance
Cardano.CLI.Shelley.Run.Governance.Committee
Cardano.CLI.Shelley.Run.Governance.DRep
Cardano.CLI.Shelley.Run.Key
Cardano.CLI.Shelley.Run.Node
Cardano.CLI.Shelley.Run.Pool
Expand Down
12 changes: 2 additions & 10 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Expand Up @@ -76,7 +76,6 @@ import Data.Text (Text)
--
data ShelleyCommand
= AddressCmd AddressCmd
| DRepCmd DRepCmd
| StakeAddressCmd StakeAddressCmd
| KeyCmd KeyCmd
| TransactionCmd TransactionCmd
Expand All @@ -91,7 +90,6 @@ renderShelleyCommand :: ShelleyCommand -> Text
renderShelleyCommand sc =
case sc of
AddressCmd cmd -> renderAddressCmd cmd
DRepCmd cmd -> renderDRepCmd cmd
StakeAddressCmd cmd -> renderStakeAddressCmd cmd
KeyCmd cmd -> renderKeyCmd cmd
TransactionCmd cmd -> renderTransactionCmd cmd
Expand Down Expand Up @@ -400,14 +398,6 @@ renderPoolCmd cmd =
PoolGetId {} -> "stake-pool id"
PoolMetadataHash {} -> "stake-pool metadata-hash"

renderDRepCmd :: DRepCmd -> Text
renderDRepCmd cmd =
case cmd of
DRepRegistrationCert {} -> "drep registration-certificate"
DRepRetirementCert {} -> "drep deregistration-certificate"
DRepGetId {} -> "drep id"
DRepMetadataHash {} -> "drep metadata-hash"

data QueryCmd =
QueryLeadershipSchedule
SocketPath
Expand Down Expand Up @@ -537,6 +527,7 @@ data GovernanceCmd
(File () Out)
| GovernanceMIRTransfer Lovelace (File () Out) TransferDirection
| GovernanceCommitteeCmd CommitteeCmd
| GovernanceDRepCmd DRepCmd
| GovernanceGenesisKeyDelegationCertificate
(VerificationKeyOrHashOrFile GenesisKey)
(VerificationKeyOrHashOrFile GenesisDelegateKey)
Expand Down Expand Up @@ -571,6 +562,7 @@ renderGovernanceCmd cmd =
GovernanceMIRTransfer _ _ TransferToTreasury -> "governance create-mir-certificate transfer-to-treasury"
GovernanceMIRTransfer _ _ TransferToReserves -> "governance create-mir-certificate transfer-to-reserves"
GovernanceCommitteeCmd {} -> "governance committee"
GovernanceDRepCmd {} -> "governance drep"
GovernanceActionCmd {} -> "governance action"
GovernanceVoteCmd {} -> "governance vote"
GovernanceUpdateProposal {} -> "governance create-update-proposal"
Expand Down
14 changes: 10 additions & 4 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -88,8 +88,6 @@ parseShelleyCommands envCli =
Opt.info (NodeCmd <$> pNodeCmd) $ Opt.progDesc "Node operation commands"
, Opt.command "stake-pool" $
Opt.info (PoolCmd <$> pPoolCmd envCli) $ Opt.progDesc "Stake pool commands"
, Opt.command "drep" $
Opt.info (DRepCmd <$> pDRepCmd envCli) $ Opt.progDesc "DRep commands"
, Opt.command "query" $
Opt.info (QueryCmd <$> pQueryCmd envCli) . Opt.progDesc $ mconcat
[ "Node query commands. Will query the local node whose Unix domain socket "
Expand Down Expand Up @@ -976,8 +974,8 @@ pPoolCmd envCli =
pPoolMetadataHashSubCmd :: Parser PoolCmd
pPoolMetadataHashSubCmd = PoolMetadataHash <$> pPoolMetadataFile <*> pMaybeOutputFile

pDRepCmd :: EnvCli -> Parser DRepCmd
pDRepCmd envCli =
pGovernanceDRepCmd :: EnvCli -> Parser DRepCmd
pGovernanceDRepCmd envCli =
asum
[ subParser "registration-certificate"
(Opt.info (pDRepRegistrationCert envCli) $ Opt.progDesc "Create a DRep registration certificate")
Expand Down Expand Up @@ -1381,6 +1379,9 @@ pGovernanceCmd envCli =
, subParser "committee"
$ Opt.info pCommitteeCmd
$ Opt.progDesc "Constitutional Committee operation commands"
, subParser "drep"
$ Opt.info pDRepCmd
$ Opt.progDesc "DRep operation commands"
, subParser "vote"
$ Opt.info pVoteCmd
$ Opt.progDesc "Commands related to governance votes"
Expand Down Expand Up @@ -1460,6 +1461,11 @@ pGovernanceCmd envCli =
GovernanceCommitteeCmd
<$> pGovernanceCommitteeCmd

pDRepCmd :: Parser GovernanceCmd
pDRepCmd =
GovernanceDRepCmd
<$> pGovernanceDRepCmd envCli

pUpdateProposal :: Parser GovernanceCmd
pUpdateProposal = GovernanceUpdateProposal
<$> pOutputFile
Expand Down
5 changes: 0 additions & 5 deletions cardano-cli/src/Cardano/CLI/Shelley/Run.hs
Expand Up @@ -8,7 +8,6 @@ import Cardano.Api

import Cardano.CLI.Shelley.Parsers
import Cardano.CLI.Shelley.Run.Address
import Cardano.CLI.Shelley.Run.DRep
import Cardano.CLI.Shelley.Run.Genesis
import Cardano.CLI.Shelley.Run.Governance
import Cardano.CLI.Shelley.Run.Key
Expand All @@ -26,7 +25,6 @@ import qualified Data.Text as Text

data ShelleyClientCmdError
= ShelleyCmdAddressError !ShelleyAddressCmdError
| ShelleyCmdDRepError !ShelleyDRepCmdError
| ShelleyCmdGenesisError !ShelleyGenesisCmdError
| ShelleyCmdGovernanceError !ShelleyGovernanceCmdError
| ShelleyCmdNodeError !ShelleyNodeCmdError
Expand All @@ -42,8 +40,6 @@ renderShelleyClientCmdError cmd err =
case err of
ShelleyCmdAddressError addrCmdErr ->
renderError cmd renderShelleyAddressCmdError addrCmdErr
ShelleyCmdDRepError addrCmdErr ->
renderError cmd renderShelleyDRepCmdError addrCmdErr
ShelleyCmdGenesisError genesisCmdErr ->
renderError cmd (Text.pack . displayError) genesisCmdErr
ShelleyCmdGovernanceError govCmdErr ->
Expand Down Expand Up @@ -78,7 +74,6 @@ renderShelleyClientCmdError cmd err =

runShelleyClientCommand :: ShelleyCommand -> ExceptT ShelleyClientCmdError IO ()
runShelleyClientCommand (AddressCmd cmd) = firstExceptT ShelleyCmdAddressError $ runAddressCmd cmd
runShelleyClientCommand (DRepCmd cmd) = firstExceptT ShelleyCmdDRepError $ runDRepCmd cmd
runShelleyClientCommand (StakeAddressCmd cmd) = firstExceptT ShelleyCmdStakeAddressError $ runStakeAddressCmd cmd
runShelleyClientCommand (KeyCmd cmd) = firstExceptT ShelleyCmdKeyError $ runKeyCmd cmd
runShelleyClientCommand (TransactionCmd cmd) = firstExceptT ShelleyCmdTransactionError $ runTransactionCmd cmd
Expand Down
4 changes: 4 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs
Expand Up @@ -17,6 +17,7 @@ import Cardano.CLI.Shelley.Key (VerificationKeyOrHashOrFile,
readVerificationKeyOrHashOrFile, readVerificationKeyOrHashOrTextEnvFile)
import Cardano.CLI.Shelley.Parsers
import Cardano.CLI.Shelley.Run.Governance.Committee
import Cardano.CLI.Shelley.Run.Governance.DRep
import Cardano.CLI.Shelley.Run.Read (CddlError, fileOrPipe, readFileTx)
import Cardano.CLI.Types
import qualified Cardano.Ledger.Shelley.TxBody as Shelley
Expand Down Expand Up @@ -67,6 +68,7 @@ data ShelleyGovernanceCmdError
| ShelleyGovernanceCmdVerifyPollError !GovernancePollError
| ShelleyGovernanceCmdWriteFileError !(FileError ())
| ShelleyGovernanceCommitteeCmdError !ShelleyGovernanceCommitteeCmdError
| ShelleyGovernanceDRepCmdError !ShelleyGovernanceDRepCmdError
deriving Show

renderShelleyGovernanceError :: ShelleyGovernanceCmdError -> Text
Expand Down Expand Up @@ -103,6 +105,7 @@ renderShelleyGovernanceError err =
renderGovernancePollError pollError
ShelleyGovernanceCmdWriteFileError fileErr -> Text.pack (displayError fileErr)
ShelleyGovernanceCommitteeCmdError e -> renderShelleyGovernanceCommitteeCmdError e
ShelleyGovernanceDRepCmdError e -> renderShelleyGovernanceDRepCmdError e

runGovernanceActionCmd :: GovernanceActionCmd -> ExceptT ShelleyGovernanceCmdError IO ()
runGovernanceActionCmd = \case
Expand Down Expand Up @@ -134,6 +137,7 @@ runGovernanceCmd = \case
runGovernanceGenesisKeyDelegationCertificate genVk genDelegVk vrfVk out
GovernanceActionCmd cmd -> runGovernanceActionCmd cmd
GovernanceCommitteeCmd cmd -> firstExceptT ShelleyGovernanceCommitteeCmdError $ runGovernanceCommitteeCmd cmd
GovernanceDRepCmd cmd -> firstExceptT ShelleyGovernanceDRepCmdError $ runGovernanceDRepCmd cmd
GovernanceVoteCmd cmd -> runGovernanceVoteCmd cmd
GovernanceUpdateProposal out eNo genVKeys ppUp mCostModelFp ->
runGovernanceUpdateProposal out eNo genVKeys ppUp mCostModelFp
Expand Down
@@ -1,9 +1,9 @@
{-# LANGUAGE DataKinds #-}

module Cardano.CLI.Shelley.Run.DRep
( ShelleyDRepCmdError(ShelleyDRepCmdReadFileError)
, renderShelleyDRepCmdError
, runDRepCmd
module Cardano.CLI.Shelley.Run.Governance.DRep
( ShelleyGovernanceDRepCmdError(ShelleyDRepCmdReadFileError)
, renderShelleyGovernanceDRepCmdError
, runGovernanceDRepCmd
) where

import Cardano.Api
Expand All @@ -24,15 +24,15 @@ import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text

data ShelleyDRepCmdError
data ShelleyGovernanceDRepCmdError
= ShelleyDRepCmdReadFileError !(FileError TextEnvelopeError)
| ShelleyDRepCmdReadKeyFileError !(FileError InputDecodeError)
| ShelleyDRepCmdWriteFileError !(FileError ())
| ShelleyDRepCmdMetadataValidationError !DRepMetadataValidationError
deriving Show

renderShelleyDRepCmdError :: ShelleyDRepCmdError -> Text
renderShelleyDRepCmdError err =
renderShelleyGovernanceDRepCmdError :: ShelleyGovernanceDRepCmdError -> Text
renderShelleyGovernanceDRepCmdError err =
case err of
ShelleyDRepCmdReadFileError fileErr -> Text.pack (displayError fileErr)
ShelleyDRepCmdReadKeyFileError fileErr -> Text.pack (displayError fileErr)
Expand All @@ -42,13 +42,13 @@ renderShelleyDRepCmdError err =



runDRepCmd :: DRepCmd -> ExceptT ShelleyDRepCmdError IO ()
runDRepCmd (DRepRegistrationCert network sPvkey mbMetadata outfp) =
runGovernanceDRepCmd :: DRepCmd -> ExceptT ShelleyGovernanceDRepCmdError IO ()
runGovernanceDRepCmd (DRepRegistrationCert network sPvkey mbMetadata outfp) =
runDRepRegistrationCert network sPvkey mbMetadata outfp
runDRepCmd (DRepRetirementCert sPvkeyFp retireEpoch outfp) =
runGovernanceDRepCmd (DRepRetirementCert sPvkeyFp retireEpoch outfp) =
runDRepRetirementCert sPvkeyFp retireEpoch outfp
runDRepCmd (DRepGetId sPvkey outputFormat) = runDRepId sPvkey outputFormat
runDRepCmd (DRepMetadataHash drepMetadataFile mOutFile) = runDRepMetadataHash drepMetadataFile mOutFile
runGovernanceDRepCmd (DRepGetId sPvkey outputFormat) = runDRepId sPvkey outputFormat
runGovernanceDRepCmd (DRepMetadataHash drepMetadataFile mOutFile) = runDRepMetadataHash drepMetadataFile mOutFile

--
-- DRep command implementations
Expand All @@ -65,7 +65,7 @@ runDRepRegistrationCert
-> Maybe DRepMetadataReference
-- ^ DRep metadata.
-> File Certificate Out
-> ExceptT ShelleyDRepCmdError IO ()
-> ExceptT ShelleyGovernanceDRepCmdError IO ()
runDRepRegistrationCert
_network
_drepVerKeyOrFile
Expand All @@ -76,13 +76,13 @@ runDRepRetirementCert
:: VerificationKeyOrFile DRepKey
-> Shelley.EpochNo
-> File Certificate Out
-> ExceptT ShelleyDRepCmdError IO ()
-> ExceptT ShelleyGovernanceDRepCmdError IO ()
runDRepRetirementCert _drepVerKeyOrFile _retireEpoch _outfp = error "Not implemented"

runDRepId
:: VerificationKeyOrFile DRepKey
-> OutputFormat
-> ExceptT ShelleyDRepCmdError IO ()
-> ExceptT ShelleyGovernanceDRepCmdError IO ()
runDRepId verKeyOrFile outputFormat = do
drepVerKey <- firstExceptT ShelleyDRepCmdReadKeyFileError
. newExceptT
Expand All @@ -94,7 +94,7 @@ runDRepId verKeyOrFile outputFormat = do
OutputFormatBech32 ->
Text.putStrLn $ serialiseToBech32 (verificationKeyHash drepVerKey)

runDRepMetadataHash :: File DRepMetadata In -> Maybe (File () Out) -> ExceptT ShelleyDRepCmdError IO ()
runDRepMetadataHash :: File DRepMetadata In -> Maybe (File () Out) -> ExceptT ShelleyGovernanceDRepCmdError IO ()
runDRepMetadataHash drepMDPath mOutFile = do
metadataBytes <- lift (readByteStringFile drepMDPath)
& onLeft (left . ShelleyDRepCmdReadFileError)
Expand Down

0 comments on commit 5a8cadb

Please sign in to comment.