Skip to content

Commit

Permalink
Implement era-based stake-address command group
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Sep 4, 2023
1 parent ffacb8d commit 8b33fa8
Show file tree
Hide file tree
Showing 61 changed files with 1,809 additions and 16 deletions.
17 changes: 13 additions & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ module Cardano.CLI.EraBased.Commands
import Cardano.Api (CardanoEra (..), ShelleyBasedEra (..))

import Cardano.CLI.Environment
import Cardano.CLI.EraBased.Commands.StakeAddress
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.EraBased.Options.Governance
import Cardano.CLI.EraBased.Options.StakeAddress

import Data.Foldable
import Data.Maybe
import Data.Text (Text)
import Options.Applicative (Parser)
import qualified Options.Applicative as Opt
Expand All @@ -28,12 +31,16 @@ renderAnyEraCommand :: AnyEraCommand -> Text
renderAnyEraCommand = \case
AnyEraCommandOf _ cmd -> renderEraBasedCommand cmd

newtype EraBasedCommand era
data EraBasedCommand era
= EraBasedGovernanceCmds (EraBasedGovernanceCmds era)
| StakeAddressCmds (StakeAddressCmds era)

renderEraBasedCommand :: EraBasedCommand era -> Text
renderEraBasedCommand = \case
EraBasedGovernanceCmds cmd -> renderEraBasedGovernanceCmds cmd
EraBasedGovernanceCmds cmd ->
renderEraBasedGovernanceCmds cmd
StakeAddressCmds cmd ->
renderStakeAddressCmds cmd

pAnyEraCommand :: EnvCli -> Parser AnyEraCommand
pAnyEraCommand envCli =
Expand Down Expand Up @@ -66,8 +73,10 @@ pAnyEraCommand envCli =

pEraBasedCommand :: EnvCli -> CardanoEra era -> Parser (EraBasedCommand era)
pEraBasedCommand envCli era =
asum
[ subParser "governance"
asum $ catMaybes
[ Just
$ subParser "governance"
$ Opt.info (EraBasedGovernanceCmds <$> pEraBasedGovernanceCmds envCli era)
$ Opt.progDesc "Era-based governance commands"
, fmap StakeAddressCmds <$> pStakeAddressCmds era envCli
]
125 changes: 125 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}

module Cardano.CLI.EraBased.Options.StakeAddress
( pStakeAddressCmds
) where

import Cardano.Api

import Cardano.CLI.Environment
import Cardano.CLI.EraBased.Commands.StakeAddress
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.Orphans ()

import Options.Applicative
import qualified Options.Applicative as Opt

pStakeAddressCmds :: ()
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (StakeAddressCmds era))
pStakeAddressCmds era envCli =
subInfoParser "stake-address"
( Opt.progDesc
$ mconcat
[ "Stake address commands."
]
)
[ pStakeAddressKeyGenCmd era
, pStakeAddressKeyHashCmd era
, pStakeAddressBuildCmd era envCli
, pStakeAddressRegistrationCertificateCmd era
, pStakeAddressDeregistrationCertificateCmd era
, pStakeAddressDelegationCertificateCmd era
]

pStakeAddressKeyGenCmd :: ()
=> CardanoEra era
-> Maybe (Parser (StakeAddressCmds era))
pStakeAddressKeyGenCmd era = do
w <- maybeFeatureInEra era
pure
$ subParser "key-gen"
$ Opt.info
( StakeAddressKeyGen w
<$> pKeyOutputFormat
<*> pVerificationKeyFileOut
<*> pSigningKeyFileOut
)
$ Opt.progDesc "Create a stake address key pair"

pStakeAddressKeyHashCmd :: ()
=> CardanoEra era
-> Maybe (Parser (StakeAddressCmds era))
pStakeAddressKeyHashCmd era = do
w <- maybeFeatureInEra era
pure
$ subParser "key-hash"
$ Opt.info
( StakeAddressKeyHash w
<$> pStakeVerificationKeyOrFile
<*> pMaybeOutputFile
)
$ Opt.progDesc "Print the hash of a stake address key"

pStakeAddressBuildCmd :: ()
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (StakeAddressCmds era))
pStakeAddressBuildCmd era envCli = do
w <- maybeFeatureInEra era
pure
$ subParser "build"
$ Opt.info
( StakeAddressBuild w
<$> pStakeVerifier
<*> pNetworkId envCli
<*> pMaybeOutputFile
)
$ Opt.progDesc "Build a stake address"

pStakeAddressRegistrationCertificateCmd :: ()
=> CardanoEra era
-> Maybe (Parser (StakeAddressCmds era))
pStakeAddressRegistrationCertificateCmd era = do
w <- maybeFeatureInEra era
pure
$ subParser "registration-certificate"
$ Opt.info
( StakeRegistrationCert w
<$> pStakeIdentifier
<*> optional pKeyRegistDeposit
<*> pOutputFile
)
$ Opt.progDesc "Create a stake address registration certificate"

pStakeAddressDeregistrationCertificateCmd :: ()
=> CardanoEra era
-> Maybe (Parser (StakeAddressCmds era))
pStakeAddressDeregistrationCertificateCmd era = do
w <- maybeFeatureInEra era
pure
$ subParser "deregistration-certificate"
$ Opt.info
( StakeCredentialDeRegistrationCert w
<$> pStakeIdentifier
<*> optional pKeyRegistDeposit
<*> pOutputFile
)
$ Opt.progDesc "Create a stake address deregistration certificate"

pStakeAddressDelegationCertificateCmd :: ()
=> CardanoEra era
-> Maybe (Parser (StakeAddressCmds era))
pStakeAddressDelegationCertificateCmd era = do
w <- maybeFeatureInEra era
pure
$ subParser "delegation-certificate"
$ Opt.info
( StakeCredentialDelegationCert w
<$> pStakeIdentifier
<*> pDelegationTarget
<*> pOutputFile
)
$ Opt.progDesc "Create a stake address pool delegation certificate"
7 changes: 6 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Cardano.CLI.EraBased.Run.Governance.Committee
import Cardano.CLI.EraBased.Run.Governance.DRep
import Cardano.CLI.EraBased.Run.Governance.Query
import Cardano.CLI.EraBased.Run.Governance.Vote
import Cardano.CLI.EraBased.Run.StakeAddress
import Cardano.CLI.Types.Errors.CmdError

import Control.Monad.Trans.Except
Expand All @@ -33,7 +34,11 @@ runAnyEraCommand = \case
runEraBasedCommand :: ()
=> EraBasedCommand era -> ExceptT CmdError IO ()
runEraBasedCommand = \case
EraBasedGovernanceCmds cmd -> runEraBasedGovernanceCmds cmd
EraBasedGovernanceCmds cmd ->
runEraBasedGovernanceCmds cmd
StakeAddressCmds cmd ->
runStakeAddressCmds cmd
& firstExceptT CmdStakeAddressError

runEraBasedGovernanceCmds :: ()
=> EraBasedGovernanceCmds era
Expand Down
24 changes: 20 additions & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
{- HLINT ignore "Monad law, left identity" -}

module Cardano.CLI.EraBased.Run.StakeAddress
( runStakeAddressBuildCmd
( runStakeAddressCmds

, runStakeAddressBuildCmd
, runStakeAddressKeyGenToFileCmd
, runStakeAddressKeyHashCmd
, runStakeCredentialDelegationCertCmd
Expand All @@ -19,6 +21,7 @@ import Cardano.Api
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley

import Cardano.CLI.EraBased.Commands.StakeAddress
import Cardano.CLI.Read
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError
Expand All @@ -37,9 +40,22 @@ import qualified Data.ByteString.Char8 as BS
import Data.Function ((&))
import qualified Data.Text.IO as Text

--
-- Stake address command implementations
--
runStakeAddressCmds :: ()
=> StakeAddressCmds era
-> ExceptT ShelleyStakeAddressCmdError IO ()
runStakeAddressCmds = \case
StakeAddressKeyGen _ fmt vk sk ->
runStakeAddressKeyGenToFileCmd fmt vk sk
StakeAddressKeyHash _ vk mOutputFp ->
runStakeAddressKeyHashCmd vk mOutputFp
StakeAddressBuild _ stakeVerifier nw mOutputFp ->
runStakeAddressBuildCmd stakeVerifier nw mOutputFp
StakeRegistrationCert sbe stakeIdentifier mDeposit outputFp ->
runStakeCredentialRegistrationCertCmd sbe stakeIdentifier mDeposit outputFp
StakeCredentialDelegationCert sbe stakeIdentifier stkPoolVerKeyHashOrFp outputFp ->
runStakeCredentialDelegationCertCmd sbe stakeIdentifier stkPoolVerKeyHashOrFp outputFp
StakeCredentialDeRegistrationCert sbe stakeIdentifier mDeposit outputFp ->
runStakeCredentialDeRegistrationCertCmd sbe stakeIdentifier mDeposit outputFp

runStakeAddressKeyGenToFileCmd :: ()
=> KeyOutputFormat
Expand Down
Loading

0 comments on commit 8b33fa8

Please sign in to comment.