Skip to content

Commit

Permalink
Merge pull request #398 from input-output-hk/ch/genesis-command-arg-t…
Browse files Browse the repository at this point in the history
…ypes

Command argument types for `genesis` commands
  • Loading branch information
carlhammann authored Oct 23, 2023
2 parents 30373af + f62ad62 commit 5ab4949
Show file tree
Hide file tree
Showing 4 changed files with 389 additions and 256 deletions.
161 changes: 98 additions & 63 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.EraBased.Commands.Genesis
( GenesisCmds (..)
, GenesisCreateCmdArgs (..)
, GenesisCreateCardanoCmdArgs (..)
, GenesisCreateStakedCmdArgs (..)
, GenesisKeyGenGenesisCmdArgs (..)
, GenesisKeyGenDelegateCmdArgs (..)
, GenesisKeyGenUTxOCmdArgs (..)
, GenesisVerKeyCmdArgs (..)
, GenesisTxInCmdArgs (..)
, GenesisAddrCmdArgs (..)
, renderGenesisCmds
) where

Expand All @@ -14,71 +24,96 @@ import Cardano.CLI.Types.Common
import Data.Text (Text)

data GenesisCmds era
= GenesisCreate
KeyOutputFormat
GenesisDir
Word
Word
(Maybe SystemStart)
(Maybe Lovelace)
NetworkId
| GenesisCreateCardano
GenesisDir
Word
Word
(Maybe SystemStart)
(Maybe Lovelace)
BlockCount
Word
Rational
NetworkId
FilePath
FilePath
FilePath
FilePath
(Maybe FilePath)
| GenesisCreateStaked
KeyOutputFormat
GenesisDir
Word
Word
Word
Word
(Maybe SystemStart)
(Maybe Lovelace)
Lovelace
NetworkId
Word
Word
Word
(Maybe FilePath) -- ^ Relay specification filepath
| GenesisKeyGenGenesis
(VerificationKeyFile Out)
(SigningKeyFile Out)
| GenesisKeyGenDelegate
(VerificationKeyFile Out)
(SigningKeyFile Out)
(OpCertCounterFile Out)
| GenesisKeyGenUTxO
(VerificationKeyFile Out)
(SigningKeyFile Out)
| GenesisCmdKeyHash
(VerificationKeyFile In)
| GenesisVerKey
(VerificationKeyFile Out)
(SigningKeyFile In)
| GenesisTxIn
(VerificationKeyFile In)
NetworkId
(Maybe (File () Out))
| GenesisAddr
(VerificationKeyFile In)
NetworkId
(Maybe (File () Out))
| GenesisHashFile
GenesisFile
= GenesisCreate !GenesisCreateCmdArgs
| GenesisCreateCardano !GenesisCreateCardanoCmdArgs
| GenesisCreateStaked !GenesisCreateStakedCmdArgs
| GenesisKeyGenGenesis !GenesisKeyGenGenesisCmdArgs
| GenesisKeyGenDelegate !GenesisKeyGenDelegateCmdArgs
| GenesisKeyGenUTxO !GenesisKeyGenUTxOCmdArgs
| GenesisCmdKeyHash !(VerificationKeyFile In)
| GenesisVerKey !GenesisVerKeyCmdArgs
| GenesisTxIn !GenesisTxInCmdArgs
| GenesisAddr !GenesisAddrCmdArgs
| GenesisHashFile !GenesisFile
deriving Show

data GenesisCreateCmdArgs = GenesisCreateCmdArgs
{ keyOutputFormat :: !KeyOutputFormat
, genesisDir :: !GenesisDir
, numGenesisKeys :: !Word
, numUTxOKeys :: !Word
, mSystemStart :: !(Maybe SystemStart)
, mSupply :: !(Maybe Lovelace)
, network :: !NetworkId
} deriving Show

data GenesisCreateCardanoCmdArgs = GenesisCreateCardanoCmdArgs
{ genesisDir :: !GenesisDir
, numGenesisKeys :: !Word
, numUTxOKeys :: !Word
, mSystemStart :: !(Maybe SystemStart)
, mSupply :: !(Maybe Lovelace)
, security :: !BlockCount
, slotLength :: !Word
, slotCoeff :: !Rational
, network :: !NetworkId
, byronGenesisTemplate :: !FilePath
, shelleyGenesisTemplate :: !FilePath
, alonzoGenesisTemplate :: !FilePath
, conwayGenesisTemplate :: !FilePath
, mNodeConfigTemplate :: !(Maybe FilePath)
} deriving Show

data GenesisCreateStakedCmdArgs = GenesisCreateStakedCmdArgs
{ keyOutputFormat :: !KeyOutputFormat
, genesisDir :: !GenesisDir
, numGenesisKeys :: !Word
, numUTxOKeys :: !Word
, numPools :: !Word
, numStakeDelegators :: !Word
, mSystemStart :: !(Maybe SystemStart)
, mNonDelegatedSupply :: !(Maybe Lovelace)
, delegatedSupply :: !Lovelace
, network :: !NetworkId
, numBulkPoolCredFiles :: !Word
, numBulkPoolsPerFile :: !Word
, numStuffedUtxo :: !Word
, mStakePoolRelaySpecFile :: !(Maybe FilePath) -- ^ Relay specification filepath
} deriving Show

data GenesisKeyGenGenesisCmdArgs = GenesisKeyGenGenesisCmdArgs
{ verificationKeyPath :: !(VerificationKeyFile Out)
, signingKeyPath :: !(SigningKeyFile Out)
} deriving Show

data GenesisKeyGenDelegateCmdArgs = GenesisKeyGenDelegateCmdArgs
{ verificationKeyPath :: !(VerificationKeyFile Out)
, signingKeyPath :: !(SigningKeyFile Out)
, opCertCounterPath :: !(OpCertCounterFile Out)
} deriving Show

data GenesisKeyGenUTxOCmdArgs = GenesisKeyGenUTxOCmdArgs
{ verificationKeyPath :: !(VerificationKeyFile Out)
, signingKeyPath :: !(SigningKeyFile Out)
} deriving Show

data GenesisVerKeyCmdArgs = GenesisVerKeyCmdArgs
{ verificationKeyPath :: !(VerificationKeyFile Out)
, signingKeyPath :: !(SigningKeyFile In)
} deriving Show

data GenesisTxInCmdArgs = GenesisTxInCmdArgs
{ verificationKeyPath :: !(VerificationKeyFile In)
, network :: !NetworkId
, mOutFile :: !(Maybe (File () Out))
} deriving Show

data GenesisAddrCmdArgs = GenesisAddrCmdArgs
{ verificationKeyPath :: !(VerificationKeyFile In)
, network :: !NetworkId
, mOutFile :: !(Maybe (File () Out))
} deriving Show

renderGenesisCmds :: GenesisCmds era -> Text
renderGenesisCmds = \case
GenesisCreate {} ->
Expand Down
18 changes: 9 additions & 9 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ pGenesisCmds envCli =

pGenesisKeyGen :: Parser (GenesisCmds era)
pGenesisKeyGen =
GenesisKeyGenGenesis
fmap GenesisKeyGenGenesis $ GenesisKeyGenGenesisCmdArgs
<$> pVerificationKeyFileOut
<*> pSigningKeyFileOut

pGenesisDelegateKeyGen :: Parser (GenesisCmds era)
pGenesisDelegateKeyGen =
GenesisKeyGenDelegate
fmap GenesisKeyGenDelegate $ GenesisKeyGenDelegateCmdArgs
<$> pVerificationKeyFileOut
<*> pSigningKeyFileOut
<*> pOperatorCertIssueCounterFile

pGenesisUTxOKeyGen :: Parser (GenesisCmds era)
pGenesisUTxOKeyGen =
GenesisKeyGenUTxO
fmap GenesisKeyGenUTxO $ GenesisKeyGenUTxOCmdArgs
<$> pVerificationKeyFileOut
<*> pSigningKeyFileOut

Expand All @@ -118,27 +118,27 @@ pGenesisKeyHash =

pGenesisVerKey :: Parser (GenesisCmds era)
pGenesisVerKey =
GenesisVerKey
fmap GenesisVerKey $ GenesisVerKeyCmdArgs
<$> pVerificationKeyFileOut
<*> pSigningKeyFileIn

pGenesisAddr :: EnvCli -> Parser (GenesisCmds era)
pGenesisAddr envCli =
GenesisAddr
fmap GenesisAddr $ GenesisAddrCmdArgs
<$> pVerificationKeyFileIn
<*> pNetworkId envCli
<*> pMaybeOutputFile

pGenesisTxIn :: EnvCli -> Parser (GenesisCmds era)
pGenesisTxIn envCli =
GenesisTxIn
fmap GenesisTxIn $ GenesisTxInCmdArgs
<$> pVerificationKeyFileIn
<*> pNetworkId envCli
<*> pMaybeOutputFile

pGenesisCreateCardano :: EnvCli -> Parser (GenesisCmds era)
pGenesisCreateCardano envCli =
GenesisCreateCardano
fmap GenesisCreateCardano $ GenesisCreateCardanoCmdArgs
<$> pGenesisDir
<*> pGenesisNumGenesisKeys
<*> pGenesisNumUTxOKeys
Expand All @@ -164,7 +164,7 @@ pGenesisCreateCardano envCli =

pGenesisCreate :: EnvCli -> Parser (GenesisCmds era)
pGenesisCreate envCli =
GenesisCreate
fmap GenesisCreate $ GenesisCreateCmdArgs
<$> pKeyOutputFormat
<*> pGenesisDir
<*> pGenesisNumGenesisKeys
Expand All @@ -175,7 +175,7 @@ pGenesisCreate envCli =

pGenesisCreateStaked :: EnvCli -> Parser (GenesisCmds era)
pGenesisCreateStaked envCli =
GenesisCreateStaked
fmap GenesisCreateStaked $ GenesisCreateStakedCmdArgs
<$> pKeyOutputFormat
<*> pGenesisDir
<*> pGenesisNumGenesisKeys
Expand Down
Loading

0 comments on commit 5ab4949

Please sign in to comment.