Skip to content

Commit

Permalink
Merge pull request #275 from input-output-hk/newhoggy/era-based-stake…
Browse files Browse the repository at this point in the history
…-pool-command

Era-based `stake-pool` command
  • Loading branch information
newhoggy authored Sep 14, 2023
2 parents d34580a + 41c4e8f commit 90cfd20
Show file tree
Hide file tree
Showing 47 changed files with 1,467 additions and 17 deletions.
9 changes: 9 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Cardano.CLI.EraBased.Commands.Key
import Cardano.CLI.EraBased.Commands.Node
import Cardano.CLI.EraBased.Commands.Query
import Cardano.CLI.EraBased.Commands.StakeAddress
import Cardano.CLI.EraBased.Commands.StakePool
import Cardano.CLI.EraBased.Commands.TextView
import Cardano.CLI.EraBased.Commands.Transaction
import Cardano.CLI.EraBased.Options.Address
Expand All @@ -29,6 +30,7 @@ import Cardano.CLI.EraBased.Options.Key
import Cardano.CLI.EraBased.Options.Node
import Cardano.CLI.EraBased.Options.Query
import Cardano.CLI.EraBased.Options.StakeAddress
import Cardano.CLI.EraBased.Options.StakePool
import Cardano.CLI.EraBased.Options.TextView
import Cardano.CLI.EraBased.Options.Transaction

Expand All @@ -53,6 +55,7 @@ data Cmds era
| NodeCmds (NodeCmds era)
| QueryCmds (QueryCmds era)
| StakeAddressCmds (StakeAddressCmds era)
| StakePoolCmds (StakePoolCmds era)
| TextViewCmds (TextViewCmds era)
| TransactionCmds (TransactionCmds era)

Expand All @@ -72,6 +75,8 @@ renderCmds = \case
renderQueryCmds cmd
StakeAddressCmds cmd ->
renderStakeAddressCmds cmd
StakePoolCmds cmd ->
renderStakePoolCmds cmd
TextViewCmds cmd ->
renderTextViewCmds cmd
TransactionCmds cmd ->
Expand Down Expand Up @@ -134,6 +139,10 @@ pCmds envCli era =
$ Opt.info (QueryCmds <$> pQueryCmds envCli)
$ Opt.progDesc "Era-based query commands"
, fmap StakeAddressCmds <$> pStakeAddressCmds era envCli
, Just
$ subParser "stake-pool"
$ Opt.info (StakePoolCmds <$> pStakePoolCmds era envCli)
$ Opt.progDesc "Era-based text-view commands"
, Just
$ subParser "text-view"
$ Opt.info (TextViewCmds <$> pTextViewCmds)
Expand Down
4 changes: 4 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Cardano.CLI.EraBased.Run.Key
import Cardano.CLI.EraBased.Run.Node
import Cardano.CLI.EraBased.Run.Query
import Cardano.CLI.EraBased.Run.StakeAddress
import Cardano.CLI.EraBased.Run.StakePool
import Cardano.CLI.EraBased.Run.TextView
import Cardano.CLI.EraBased.Run.Transaction
import Cardano.CLI.Types.Errors.CmdError
Expand Down Expand Up @@ -61,6 +62,9 @@ runCmds = \case
StakeAddressCmds cmd ->
runStakeAddressCmds cmd
& firstExceptT CmdStakeAddressError
StakePoolCmds cmd ->
runStakePoolCmds cmd
& firstExceptT CmdStakePoolError
TextViewCmds cmd ->
runTextViewCmds cmd
& firstExceptT CmdTextViewError
Expand Down
40 changes: 27 additions & 13 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/StakePool.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}

module Cardano.CLI.EraBased.Run.StakePool
( runStakePoolIdCmd
( runStakePoolCmds

, runStakePoolIdCmd
, runStakePoolMetadataHashCmd
, runStakePoolRegistrationCertificateCmd
, runStakePoolRetirementCertificateCmd
Expand All @@ -13,6 +16,7 @@ import Cardano.Api
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley

import Cardano.CLI.EraBased.Commands.StakePool
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Errors.StakePoolCmdError
import Cardano.CLI.Types.Key (VerificationKeyOrFile, readVerificationKeyOrFile)
Expand All @@ -26,6 +30,19 @@ import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT
import qualified Data.ByteString.Char8 as BS
import Data.Function ((&))

runStakePoolCmds :: ()
=> StakePoolCmds era
-> ExceptT StakePoolCmdError IO ()
runStakePoolCmds = \case
StakePoolDeregistrationCertificateCmd sbe sPvkeyFp retireEpoch outfp ->
runStakePoolRetirementCertificateCmd sbe sPvkeyFp retireEpoch outfp
StakePoolIdCmd sPvkey outputFormat mOutFile ->
runStakePoolIdCmd sPvkey outputFormat mOutFile
StakePoolMetadataHashCmd poolMdFile mOutFile ->
runStakePoolMetadataHashCmd poolMdFile mOutFile
StakePoolRegistrationCertificateCmd sbe sPvkey vrfVkey pldg pCost pMrgn rwdVerFp ownerVerFps relays mbMetadata network outfp ->
runStakePoolRegistrationCertificateCmd sbe sPvkey vrfVkey pldg pCost pMrgn rwdVerFp ownerVerFps relays mbMetadata network outfp

--
-- Stake pool command implementations
--
Expand All @@ -34,7 +51,7 @@ import Data.Function ((&))
-- TODO: Metadata and more stake pool relay support to be
-- added in the future.
runStakePoolRegistrationCertificateCmd
:: AnyShelleyBasedEra
:: ShelleyBasedEra era
-> VerificationKeyOrFile StakePoolKey
-- ^ Stake pool verification key.
-> VerificationKeyOrFile VrfKey
Expand All @@ -57,7 +74,7 @@ runStakePoolRegistrationCertificateCmd
-> File () Out
-> ExceptT StakePoolCmdError IO ()
runStakePoolRegistrationCertificateCmd
anyEra
sbe
stakePoolVerKeyOrFile
vrfVerKeyOrFile
pldg
Expand All @@ -68,9 +85,7 @@ runStakePoolRegistrationCertificateCmd
relays
mbMetadata
network
outfp = do
AnyShelleyBasedEra sbe <- pure anyEra

outfp = shelleyBasedEraConstraints sbe $ do
-- Pool verification key
stakePoolVerKey <- firstExceptT StakePoolCmdReadKeyFileError
. newExceptT
Expand Down Expand Up @@ -126,8 +141,8 @@ runStakePoolRegistrationCertificateCmd
registrationCertDesc :: TextEnvelopeDescr
registrationCertDesc = "Stake Pool Registration Certificate"

createStakePoolRegistrationRequirements
:: ShelleyBasedEra era
createStakePoolRegistrationRequirements :: ()
=> ShelleyBasedEra era
-> Ledger.PoolParams (Ledger.EraCrypto (ShelleyLedgerEra era))
-> StakePoolRegistrationRequirements era
createStakePoolRegistrationRequirements sbe pparams =
Expand All @@ -146,15 +161,14 @@ createStakePoolRegistrationRequirements sbe pparams =
StakePoolRegistrationRequirementsConwayOnwards ConwayEraOnwardsConway pparams


runStakePoolRetirementCertificateCmd
:: AnyShelleyBasedEra
runStakePoolRetirementCertificateCmd :: ()
=> ShelleyBasedEra era
-> VerificationKeyOrFile StakePoolKey
-> Shelley.EpochNo
-> File () Out
-> ExceptT StakePoolCmdError IO ()
runStakePoolRetirementCertificateCmd anyEra stakePoolVerKeyOrFile retireEpoch outfp = do
AnyShelleyBasedEra sbe <- pure anyEra

runStakePoolRetirementCertificateCmd sbe stakePoolVerKeyOrFile retireEpoch outfp =
shelleyBasedEraConstraints sbe $ do
-- Pool verification key
stakePoolVerKey <- firstExceptT StakePoolCmdReadKeyFileError
. newExceptT
Expand Down
10 changes: 6 additions & 4 deletions cardano-cli/src/Cardano/CLI/Legacy/Run/StakePool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,19 @@ runLegacyStakePoolRegistrationCertificateCmd :: ()
-> NetworkId
-> File () Out
-> ExceptT StakePoolCmdError IO ()
runLegacyStakePoolRegistrationCertificateCmd =
runStakePoolRegistrationCertificateCmd
runLegacyStakePoolRegistrationCertificateCmd = \case
AnyShelleyBasedEra sbe ->
runStakePoolRegistrationCertificateCmd sbe

runLegacyStakePoolDeregistrationCertificateCmd :: ()
=> AnyShelleyBasedEra
-> VerificationKeyOrFile StakePoolKey
-> Shelley.EpochNo
-> File () Out
-> ExceptT StakePoolCmdError IO ()
runLegacyStakePoolDeregistrationCertificateCmd =
runStakePoolRetirementCertificateCmd
runLegacyStakePoolDeregistrationCertificateCmd = \case
AnyShelleyBasedEra sbe ->
runStakePoolRetirementCertificateCmd sbe

runLegacyStakePoolIdCmd :: ()
=> VerificationKeyOrFile StakePoolKey
Expand Down
Loading

0 comments on commit 90cfd20

Please sign in to comment.