Skip to content

Commit

Permalink
Era based addressed commands
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Sep 6, 2023
1 parent 509004a commit f6e474e
Show file tree
Hide file tree
Showing 49 changed files with 1,094 additions and 17 deletions.
2 changes: 2 additions & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ library
Cardano.CLI.Byron.Vote
Cardano.CLI.Environment
Cardano.CLI.EraBased.Commands
Cardano.CLI.EraBased.Commands.Address
Cardano.CLI.EraBased.Commands.Governance
Cardano.CLI.EraBased.Commands.Governance.Actions
Cardano.CLI.EraBased.Commands.Governance.Committee
Expand All @@ -74,6 +75,7 @@ library
Cardano.CLI.EraBased.Commands.Governance.Vote
Cardano.CLI.EraBased.Commands.StakeAddress
Cardano.CLI.EraBased.Commands.Transaction
Cardano.CLI.EraBased.Options.Address
Cardano.CLI.EraBased.Options.Common
Cardano.CLI.EraBased.Options.Governance
Cardano.CLI.EraBased.Options.Governance.Actions
Expand Down
11 changes: 10 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ module Cardano.CLI.EraBased.Commands
import Cardano.Api (CardanoEra (..), ShelleyBasedEra (..))

import Cardano.CLI.Environment
import Cardano.CLI.EraBased.Commands.Address
import Cardano.CLI.EraBased.Commands.StakeAddress
import Cardano.CLI.EraBased.Commands.Transaction
import Cardano.CLI.EraBased.Options.Address
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.EraBased.Options.Governance
import Cardano.CLI.EraBased.Options.StakeAddress
Expand All @@ -34,12 +36,15 @@ renderAnyEraCommand = \case
AnyEraCommandOf _ cmd -> renderEraBasedCommand cmd

data EraBasedCommand era
= EraBasedGovernanceCmds (EraBasedGovernanceCmds era)
= AddressCmds (AddressCmds era)
| EraBasedGovernanceCmds (EraBasedGovernanceCmds era)
| TransactionCmds (TransactionCmds era)
| StakeAddressCmds (StakeAddressCmds era)

renderEraBasedCommand :: EraBasedCommand era -> Text
renderEraBasedCommand = \case
AddressCmds cmd ->
renderAddressCmds cmd
EraBasedGovernanceCmds cmd ->
renderEraBasedGovernanceCmds cmd
StakeAddressCmds cmd ->
Expand Down Expand Up @@ -80,6 +85,10 @@ pEraBasedCommand :: EnvCli -> CardanoEra era -> Parser (EraBasedCommand era)
pEraBasedCommand envCli era =
asum $ catMaybes
[ Just
$ subParser "address"
$ Opt.info (AddressCmds <$> pAddressCmds era envCli)
$ Opt.progDesc "Era-based address commands"
, Just
$ subParser "governance"
$ Opt.info (EraBasedGovernanceCmds <$> pEraBasedGovernanceCmds envCli era)
$ Opt.progDesc "Era-based governance commands"
Expand Down
42 changes: 42 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Address.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.EraBased.Commands.Address
( AddressCmds (..)
, renderAddressCmds
) where

import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..))

import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key

import Prelude

import Data.Text (Text)

data AddressCmds era
= AddressKeyGen
KeyOutputFormat
AddressKeyType
(VerificationKeyFile Out)
(SigningKeyFile Out)
| AddressKeyHash
VerificationKeyTextOrFile
(Maybe (File () Out))
| AddressBuild
PaymentVerifier
(Maybe StakeIdentifier)
NetworkId
(Maybe (File () Out))
| AddressInfo
Text
(Maybe (File () Out))
deriving Show

renderAddressCmds :: AddressCmds era -> Text
renderAddressCmds = \case
AddressKeyGen {} -> "address key-gen"
AddressKeyHash {} -> "address key-hash"
AddressBuild {} -> "address build"
AddressInfo {} -> "address info"
63 changes: 63 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Address.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.CLI.EraBased.Options.Address
( pAddressCmds
) where

import Cardano.Api

import Cardano.CLI.Environment (EnvCli (..))
import Cardano.CLI.EraBased.Commands.Address
import Cardano.CLI.EraBased.Options.Common

import Data.Foldable
import Options.Applicative hiding (help, str)
import qualified Options.Applicative as Opt

pAddressCmds :: CardanoEra era -> EnvCli -> Parser (AddressCmds era)
pAddressCmds _ envCli =
asum
[ subParser "key-gen"
$ Opt.info pAddressKeyGen
$ Opt.progDesc "Create an address key pair."
, subParser "key-hash"
$ Opt.info pAddressKeyHash
$ Opt.progDesc "Print the hash of an address key."
, subParser "build"
$ Opt.info (pAddressBuild envCli)
$ Opt.progDesc "Build a Shelley payment address, with optional delegation to a stake address."
, subParser "info"
$ Opt.info pAddressInfo
$ Opt.progDesc "Print information about an address."
]

pAddressKeyGen :: Parser (AddressCmds era)
pAddressKeyGen =
AddressKeyGen
<$> pKeyOutputFormat
<*> pAddressKeyType
<*> pVerificationKeyFileOut
<*> pSigningKeyFileOut

pAddressKeyHash :: Parser (AddressCmds era)
pAddressKeyHash =
AddressKeyHash
<$> pPaymentVerificationKeyTextOrFile
<*> pMaybeOutputFile

pAddressBuild :: EnvCli -> Parser (AddressCmds era)
pAddressBuild envCli =
AddressBuild
<$> pPaymentVerifier
<*> Opt.optional pStakeIdentifier
<*> pNetworkId envCli
<*> pMaybeOutputFile

pAddressInfo :: Parser (AddressCmds era)
pAddressInfo =
AddressInfo
<$> pAddress
<*> pMaybeOutputFile
6 changes: 5 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Cardano.Api

import Cardano.CLI.EraBased.Commands
import Cardano.CLI.EraBased.Options.Governance
import Cardano.CLI.EraBased.Run.Address
import Cardano.CLI.EraBased.Run.Governance
import Cardano.CLI.EraBased.Run.Governance.Actions
import Cardano.CLI.EraBased.Run.Governance.Committee
Expand All @@ -33,8 +34,11 @@ runAnyEraCommand = \case
shelleyBasedEraConstraints sbe $ runEraBasedCommand cmd

runEraBasedCommand :: ()
=> EraBasedCommand era -> ExceptT CmdError IO ()
=> EraBasedCommand era
-> ExceptT CmdError IO ()
runEraBasedCommand = \case
AddressCmds cmd ->
runAddressCmds cmd & firstExceptT CmdAddressError
EraBasedGovernanceCmds cmd ->
runEraBasedGovernanceCmds cmd
StakeAddressCmds cmd ->
Expand Down
21 changes: 20 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run/Address.hs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.CLI.EraBased.Run.Address
( runAddressBuildCmd
( runAddressCmds

, runAddressBuildCmd
, runAddressKeyGenCmd
, runAddressKeyHashCmd
) where

import Cardano.Api
import Cardano.Api.Shelley

import Cardano.CLI.EraBased.Commands.Address
import Cardano.CLI.EraBased.Run.Address.Info
import Cardano.CLI.Read
import Cardano.CLI.Types.Key (PaymentVerifier (..), StakeIdentifier (..),
StakeVerifier (..), VerificationKeyTextOrFile, generateKeyPair, readVerificationKeyOrFile,
Expand All @@ -24,8 +29,22 @@ import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, left, newExceptT)
import qualified Data.ByteString.Char8 as BS
import Data.Function
import qualified Data.Text.IO as Text

runAddressCmds :: ()
=> AddressCmds era
-> ExceptT ShelleyAddressCmdError IO ()
runAddressCmds = \case
AddressKeyGen fmt kt vkf skf ->
runAddressKeyGenCmd fmt kt vkf skf
AddressKeyHash vkf mOFp ->
runAddressKeyHashCmd vkf mOFp
AddressBuild paymentVerifier mbStakeVerifier nw mOutFp ->
runAddressBuildCmd paymentVerifier mbStakeVerifier nw mOutFp
AddressInfo txt mOFp ->
runAddressInfoCmd txt mOFp & firstExceptT ShelleyAddressCmdAddressInfoError

runAddressKeyGenCmd
:: KeyOutputFormat
-> AddressKeyType
Expand Down
Loading

0 comments on commit f6e474e

Please sign in to comment.