Skip to content

Commit

Permalink
Add CCM commands
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed May 24, 2023
1 parent 9f8aca6 commit e210089
Show file tree
Hide file tree
Showing 12 changed files with 497 additions and 10 deletions.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Expand Up @@ -82,6 +82,7 @@ library
Cardano.CLI.Shelley.Run
Cardano.CLI.Shelley.Run.Address
Cardano.CLI.Shelley.Run.Address.Info
Cardano.CLI.Shelley.Run.Ccm
Cardano.CLI.Shelley.Run.Genesis
Cardano.CLI.Shelley.Run.Governance
Cardano.CLI.Shelley.Run.Key
Expand Down
35 changes: 35 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
@@ -1,12 +1,14 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE UndecidableInstances #-}

-- | Shelley CLI command types
module Cardano.CLI.Shelley.Commands
( -- * CLI command types
ShelleyCommand (..)
, AddressCmd (..)
, CcmCmd (..)
, StakeAddressCmd (..)
, KeyCmd (..)
, TransactionCmd (..)
Expand Down Expand Up @@ -64,6 +66,7 @@ import Data.Text (Text)
--
data ShelleyCommand
= AddressCmd AddressCmd
| CcmCmd CcmCmd
| StakeAddressCmd StakeAddressCmd
| KeyCmd KeyCmd
| TransactionCmd TransactionCmd
Expand All @@ -78,6 +81,7 @@ renderShelleyCommand :: ShelleyCommand -> Text
renderShelleyCommand sc =
case sc of
AddressCmd cmd -> renderAddressCmd cmd
CcmCmd cmd -> renderCcmCmd cmd
StakeAddressCmd cmd -> renderStakeAddressCmd cmd
KeyCmd cmd -> renderKeyCmd cmd
TransactionCmd cmd -> renderTransactionCmd cmd
Expand Down Expand Up @@ -272,6 +276,37 @@ renderTransactionCmd cmd =
TxGetTxId {} -> "transaction txid"
TxView {} -> "transaction view"

data CcmCmd
= CcmKeyGenCold
(VerificationKeyFile Out)
(SigningKeyFile Out)
(OpCertCounterFile Out)
| CcmKeyGenVRF
(VerificationKeyFile Out)
(SigningKeyFile Out)
| CcmKeyHashVRF
(VerificationKeyOrFile VrfKey)
(Maybe (File () Out))
| CcmNewCounter
ColdVerificationKeyOrFile
Word
(OpCertCounterFile InOut)
| CcmIssueOpCert
(VerificationKeyOrFile KesKey)
(SigningKeyFile In)
(OpCertCounterFile InOut)
KESPeriod
(File () Out)
deriving Show

renderCcmCmd :: CcmCmd -> Text
renderCcmCmd = \case
CcmKeyGenCold {} -> "ccm key-gen"
CcmKeyGenVRF {} -> "ccm key-gen-VRF"
CcmKeyHashVRF {} -> "ccm key-hash-VRF"
CcmNewCounter {} -> "ccm new-counter"
CcmIssueOpCert{} -> "ccm issue-op-cert"

data NodeCmd
= NodeKeyGenCold (VerificationKeyFile Out) (SigningKeyFile Out) (OpCertCounterFile Out)
| NodeKeyGenKES (VerificationKeyFile Out) (SigningKeyFile Out)
Expand Down
67 changes: 67 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -78,6 +78,8 @@ parseShelleyCommands envCli =
, Opt.commandGroup "Era based commands"
, Opt.command "address" $
Opt.info (AddressCmd <$> pAddressCmd envCli) $ Opt.progDesc "Payment address commands"
, Opt.command "ccm" $
Opt.info (CcmCmd <$> pCcmCmd) $ Opt.progDesc "CCM operation commands"
, Opt.command "stake-address" $
Opt.info (StakeAddressCmd <$> pStakeAddressCmd envCli) $ Opt.progDesc "Stake address commands"
, Opt.command "key" $
Expand Down Expand Up @@ -833,6 +835,71 @@ pTransaction envCli =
pTransactionView :: Parser TransactionCmd
pTransactionView = TxView <$> pInputTxOrTxBodyFile


pCcmCmd :: Parser CcmCmd
pCcmCmd =
asum
[ subParser "key-gen" . Opt.info pKeyGenOperator . Opt.progDesc $ mconcat
[ "Create a key pair for a CCM's offline "
, "key and a new certificate issue counter"
]
, subParser "key-gen-VRF" . Opt.info pKeyGenVRF . Opt.progDesc $ mconcat
[ "Create a key pair for a CCM VRF operational key"
]
, subParser "key-hash-VRF". Opt.info pKeyHashVRF . Opt.progDesc $ mconcat
[ "Print hash of a CCM's operational VRF key."
]
, subParser "new-counter" . Opt.info pNewCounter . Opt.progDesc $ mconcat
[ "Create a new certificate issue counter"
]
, subParser "issue-op-cert" . Opt.info pIssueOpCert . Opt.progDesc $ mconcat
[ "Issue a CCM operational certificate"
]
]
where
pKeyGenOperator :: Parser CcmCmd
pKeyGenOperator =
CcmKeyGenCold
<$> pColdVerificationKeyFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile

pKeyGenVRF :: Parser CcmCmd
pKeyGenVRF =
CcmKeyGenVRF
<$> pVerificationKeyFileOut
<*> pSigningKeyFileOut

pKeyHashVRF :: Parser CcmCmd
pKeyHashVRF =
CcmKeyHashVRF
<$> pVerificationKeyOrFile AsVrfKey
<*> pMaybeOutputFile

pNewCounter :: Parser CcmCmd
pNewCounter =
CcmNewCounter
<$> pColdVerificationKeyOrFile
<*> pCounterValue
<*> pOperatorCertIssueCounterFile

pCounterValue :: Parser Word
pCounterValue =
Opt.option Opt.auto $ mconcat
[ Opt.long "counter-value"
, Opt.metavar "INT"
, Opt.help "The next certificate issue counter value to use."
]

pIssueOpCert :: Parser CcmCmd
pIssueOpCert =
CcmIssueOpCert
<$> pKesVerificationKeyOrFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile
<*> pKesPeriod
<*> pOutputFile

pNodeCmd :: Parser NodeCmd
pNodeCmd =
asum
Expand Down
22 changes: 12 additions & 10 deletions cardano-cli/src/Cardano/CLI/Shelley/Run.hs
Expand Up @@ -4,30 +4,29 @@ module Cardano.CLI.Shelley.Run
, runShelleyClientCommand
) where

import Control.Monad.Trans.Except (ExceptT)
import Data.Text (Text)

import Cardano.Api

import Control.Monad.Trans.Except.Extra (firstExceptT)
import qualified Data.Text as Text

import Cardano.CLI.Shelley.Parsers

import Cardano.CLI.Shelley.Run.Address
import Cardano.CLI.Shelley.Run.Ccm
import Cardano.CLI.Shelley.Run.Genesis
import Cardano.CLI.Shelley.Run.Governance
import Cardano.CLI.Shelley.Run.Key
import Cardano.CLI.Shelley.Run.Node
import Cardano.CLI.Shelley.Run.Pool
import Cardano.CLI.Shelley.Run.Query
import Cardano.CLI.Shelley.Run.StakeAddress
import Cardano.CLI.Shelley.Run.Transaction
-- Block, System, DevOps
import Cardano.CLI.Shelley.Run.Genesis
import Cardano.CLI.Shelley.Run.TextView
import Cardano.CLI.Shelley.Run.Transaction

import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT)
import Data.Text (Text)
import qualified Data.Text as Text

data ShelleyClientCmdError
= ShelleyCmdAddressError !ShelleyAddressCmdError
| ShelleyCmdCcmError !ShelleyCcmCmdError
| ShelleyCmdGenesisError !ShelleyGenesisCmdError
| ShelleyCmdGovernanceError !ShelleyGovernanceCmdError
| ShelleyCmdNodeError !ShelleyNodeCmdError
Expand All @@ -43,6 +42,8 @@ renderShelleyClientCmdError cmd err =
case err of
ShelleyCmdAddressError addrCmdErr ->
renderError cmd renderShelleyAddressCmdError addrCmdErr
ShelleyCmdCcmError nodeCmdErr ->
renderError cmd renderShelleyCcmCmdError nodeCmdErr
ShelleyCmdGenesisError genesisCmdErr ->
renderError cmd (Text.pack . displayError) genesisCmdErr
ShelleyCmdGovernanceError govCmdErr ->
Expand Down Expand Up @@ -77,6 +78,7 @@ renderShelleyClientCmdError cmd err =

runShelleyClientCommand :: ShelleyCommand -> ExceptT ShelleyClientCmdError IO ()
runShelleyClientCommand (AddressCmd cmd) = firstExceptT ShelleyCmdAddressError $ runAddressCmd cmd
runShelleyClientCommand (CcmCmd cmd) = firstExceptT ShelleyCmdCcmError $ runCcmCmd cmd
runShelleyClientCommand (StakeAddressCmd cmd) = firstExceptT ShelleyCmdStakeAddressError $ runStakeAddressCmd cmd
runShelleyClientCommand (KeyCmd cmd) = firstExceptT ShelleyCmdKeyError $ runKeyCmd cmd
runShelleyClientCommand (TransactionCmd cmd) = firstExceptT ShelleyCmdTransactionError $ runTransactionCmd cmd
Expand Down

0 comments on commit e210089

Please sign in to comment.