Skip to content

Commit

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

Command types for `node` commands
  • Loading branch information
newhoggy authored Nov 3, 2023
2 parents c2c19d7 + c9f15b4 commit b9579f6
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 318 deletions.
111 changes: 74 additions & 37 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Node.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.EraBased.Commands.Node
( NodeCmds (..)
, renderNodeCmds

, NodeKeyGenColdCmdArgs(..)
, NodeKeyGenKESCmdArgs(..)
, NodeKeyGenVRFCmdArgs(..)
, NodeKeyHashVRFCmdArgs(..)
, NodeNewCounterCmdArgs(..)
, NodeIssueOpCertCmdArgs(..)
) where

import Cardano.Api.Shelley
Expand All @@ -14,44 +22,73 @@ import Cardano.CLI.Types.Key
import Data.Text (Text)

data NodeCmds era
= NodeKeyGenCold
KeyOutputFormat
(VerificationKeyFile Out)
(SigningKeyFile Out)
(OpCertCounterFile Out)
| NodeKeyGenKES
KeyOutputFormat
(VerificationKeyFile Out)
(SigningKeyFile Out)
| NodeKeyGenVRF
KeyOutputFormat
(VerificationKeyFile Out)
(SigningKeyFile Out)
| NodeKeyHashVRF
(VerificationKeyOrFile VrfKey)
(Maybe (File () Out))
| NodeNewCounter
ColdVerificationKeyOrFile
Word
(OpCertCounterFile InOut)
| NodeIssueOpCert
(VerificationKeyOrFile KesKey)
(SigningKeyFile In)
(OpCertCounterFile InOut)
KESPeriod (File () Out)
= NodeKeyGenColdCmd !NodeKeyGenColdCmdArgs
| NodeKeyGenKESCmd !NodeKeyGenKESCmdArgs
| NodeKeyGenVRFCmd !NodeKeyGenVRFCmdArgs
| NodeKeyHashVRFCmd !NodeKeyHashVRFCmdArgs
| NodeNewCounterCmd !NodeNewCounterCmdArgs
| NodeIssueOpCertCmd !NodeIssueOpCertCmdArgs
deriving Show

data NodeKeyGenColdCmdArgs =
NodeKeyGenColdCmdArgs
{ keyOutputFormat :: !KeyOutputFormat
, vkeyFile :: !(VerificationKeyFile Out)
, skeyFile :: !(SigningKeyFile Out)
, operationalCertificateIssueCounter :: !(OpCertCounterFile Out)
}
deriving Show

data NodeKeyGenKESCmdArgs =
NodeKeyGenKESCmdArgs
{ keyOutputFormat :: !KeyOutputFormat
, vkeyFile :: !(VerificationKeyFile Out)
, skeyFile :: !(SigningKeyFile Out)
}
deriving Show

data NodeKeyGenVRFCmdArgs =
NodeKeyGenVRFCmdArgs
{ keyOutputFormat :: !KeyOutputFormat
, vkeyFile :: !(VerificationKeyFile Out)
, skeyFile :: !(SigningKeyFile Out)
}
deriving Show

data NodeKeyHashVRFCmdArgs =
NodeKeyHashVRFCmdArgs
{ vkeySource :: !(VerificationKeyOrFile VrfKey)
, mOutFile :: !(Maybe (File () Out))
}
deriving Show

data NodeNewCounterCmdArgs =
NodeNewCounterCmdArgs
{ coldVkeyFile :: !ColdVerificationKeyOrFile
, counter :: !Word
, mOutFile :: !(OpCertCounterFile InOut)
}
deriving Show

data NodeIssueOpCertCmdArgs =
NodeIssueOpCertCmdArgs
{ kesVkeySource :: !(VerificationKeyOrFile KesKey)
-- ^ The hot KES verification key.
, poolSkeyFile :: !(SigningKeyFile In)
-- ^ The cold signing key.
, operationalCertificateCounterFile :: !(OpCertCounterFile InOut)
-- ^ Counter that establishes the precedence of the operational certificate.
, kesPeriod :: !KESPeriod
-- ^ Start of the validity period for this certificate.
, outFile :: !(File () Out)
}
deriving Show

renderNodeCmds :: NodeCmds era -> Text
renderNodeCmds = \case
NodeKeyGenCold {} ->
"node key-gen"
NodeKeyGenKES {} ->
"node key-gen-KES"
NodeKeyGenVRF {} ->
"node key-gen-VRF"
NodeKeyHashVRF {} ->
"node key-hash-VRF"
NodeNewCounter {} ->
"node new-counter"
NodeIssueOpCert{} ->
"node issue-op-cert"
NodeKeyGenColdCmd {} -> "node key-gen"
NodeKeyGenKESCmd {} -> "node key-gen-KES"
NodeKeyGenVRFCmd {} -> "node key-gen-VRF"
NodeKeyHashVRFCmd {} -> "node key-hash-VRF"
NodeNewCounterCmd {} -> "node new-counter"
NodeIssueOpCertCmd {} -> "node issue-op-cert"
59 changes: 33 additions & 26 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Cardano.CLI.EraBased.Options.Node
import Cardano.Api hiding (QueryInShelleyBasedEra (..))

import Cardano.CLI.EraBased.Commands.Node
import qualified Cardano.CLI.EraBased.Commands.Node as Cmd
import Cardano.CLI.EraBased.Options.Common

import Options.Applicative hiding (help, str)
Expand Down Expand Up @@ -71,38 +72,43 @@ pNodeCmds =

pKeyGenOperator :: Parser (NodeCmds era)
pKeyGenOperator =
NodeKeyGenCold
<$> pKeyOutputFormat
<*> pColdVerificationKeyFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile
fmap Cmd.NodeKeyGenColdCmd $
Cmd.NodeKeyGenColdCmdArgs
<$> pKeyOutputFormat
<*> pColdVerificationKeyFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile

pKeyGenKES :: Parser (NodeCmds era)
pKeyGenKES =
NodeKeyGenKES
<$> pKeyOutputFormat
<*> pVerificationKeyFileOut
<*> pSigningKeyFileOut
fmap Cmd.NodeKeyGenKESCmd $
Cmd.NodeKeyGenKESCmdArgs
<$> pKeyOutputFormat
<*> pVerificationKeyFileOut
<*> pSigningKeyFileOut

pKeyGenVRF :: Parser (NodeCmds era)
pKeyGenVRF =
NodeKeyGenVRF
<$> pKeyOutputFormat
<*> pVerificationKeyFileOut
<*> pSigningKeyFileOut
fmap Cmd.NodeKeyGenVRFCmd $
Cmd.NodeKeyGenVRFCmdArgs
<$> pKeyOutputFormat
<*> pVerificationKeyFileOut
<*> pSigningKeyFileOut

pKeyHashVRF :: Parser (NodeCmds era)
pKeyHashVRF =
NodeKeyHashVRF
<$> pVerificationKeyOrFileIn AsVrfKey
<*> pMaybeOutputFile
fmap Cmd.NodeKeyHashVRFCmd $
Cmd.NodeKeyHashVRFCmdArgs
<$> pVerificationKeyOrFileIn AsVrfKey
<*> pMaybeOutputFile

pNewCounter :: Parser (NodeCmds era)
pNewCounter =
NodeNewCounter
<$> pColdVerificationKeyOrFile Nothing
<*> pCounterValue
<*> pOperatorCertIssueCounterFile
fmap Cmd.NodeNewCounterCmd $
Cmd.NodeNewCounterCmdArgs
<$> pColdVerificationKeyOrFile Nothing
<*> pCounterValue
<*> pOperatorCertIssueCounterFile

pCounterValue :: Parser Word
pCounterValue =
Expand All @@ -114,9 +120,10 @@ pCounterValue =

pIssueOpCert :: Parser (NodeCmds era)
pIssueOpCert =
NodeIssueOpCert
<$> pKesVerificationKeyOrFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile
<*> pKesPeriod
<*> pOutputFile
fmap Cmd.NodeIssueOpCertCmd $
Cmd.NodeIssueOpCertCmdArgs
<$> pKesVerificationKeyOrFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile
<*> pKesPeriod
<*> pOutputFile
13 changes: 7 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import Cardano.CLI.Byron.Delegation
import Cardano.CLI.Byron.Genesis as Byron
import qualified Cardano.CLI.Byron.Key as Byron
import Cardano.CLI.EraBased.Commands.Genesis as Cmd
import qualified Cardano.CLI.EraBased.Commands.Node as Cmd
import qualified Cardano.CLI.EraBased.Run.Key as Key
import Cardano.CLI.EraBased.Run.Node (runNodeIssueOpCertCmd, runNodeKeyGenColdCmd,
runNodeKeyGenKesCmd, runNodeKeyGenVrfCmd)
Expand Down Expand Up @@ -803,11 +804,11 @@ createDelegateKeys fmt dir index = do
(File @(VerificationKey ()) $ dir </> "delegate" ++ strIndex ++ ".vrf.vkey")
(File @(SigningKey ()) $ dir </> "delegate" ++ strIndex ++ ".vrf.skey")
firstExceptT GenesisCmdNodeCmdError $ do
runNodeKeyGenKesCmd
runNodeKeyGenKesCmd $ Cmd.NodeKeyGenKESCmdArgs
fmt
(onlyOut kesVK)
(File @(SigningKey ()) $ dir </> "delegate" ++ strIndex ++ ".kes.skey")
runNodeIssueOpCertCmd
runNodeIssueOpCertCmd $ Cmd.NodeIssueOpCertCmdArgs
(VerificationKeyFilePath (onlyIn kesVK))
(onlyIn coldSK)
opCertCtr
Expand Down Expand Up @@ -843,20 +844,20 @@ createPoolCredentials :: KeyOutputFormat -> FilePath -> Word -> ExceptT GenesisC
createPoolCredentials fmt dir index = do
liftIO $ createDirectoryIfMissing False dir
firstExceptT GenesisCmdNodeCmdError $ do
runNodeKeyGenKesCmd
runNodeKeyGenKesCmd $ Cmd.NodeKeyGenKESCmdArgs
fmt
(onlyOut kesVK)
(File @(SigningKey ()) $ dir </> "kes" ++ strIndex ++ ".skey")
runNodeKeyGenVrfCmd
runNodeKeyGenVrfCmd $ Cmd.NodeKeyGenVRFCmdArgs
fmt
(File @(VerificationKey ()) $ dir </> "vrf" ++ strIndex ++ ".vkey")
(File @(SigningKey ()) $ dir </> "vrf" ++ strIndex ++ ".skey")
runNodeKeyGenColdCmd
runNodeKeyGenColdCmd $ Cmd.NodeKeyGenColdCmdArgs
fmt
(File @(VerificationKey ()) $ dir </> "cold" ++ strIndex ++ ".vkey")
(onlyOut coldSK)
(onlyOut opCertCtr)
runNodeIssueOpCertCmd
runNodeIssueOpCertCmd $ Cmd.NodeIssueOpCertCmdArgs
(VerificationKeyFilePath (onlyIn kesVK))
(onlyIn coldSK)
opCertCtr
Expand Down
Loading

0 comments on commit b9579f6

Please sign in to comment.