Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Feb 19, 2025
1 parent 5330848 commit 2e3e4d7
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 0 deletions.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ library
Cardano.CLI.Compatible.Commands
Cardano.CLI.Compatible.Governance
Cardano.CLI.Compatible.Run
Cardano.CLI.Compatible.StakeAddress.Commands
Cardano.CLI.Compatible.Transaction
Cardano.CLI.Environment
Cardano.CLI.EraBased.Commands.Genesis
Expand Down
1 change: 1 addition & 0 deletions cardano-cli/src/Cardano/CLI/Compatible/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ renderAnyCompatibleCommand = \case
data CompatibleCommand era
= CompatibleTransactionCmd (CompatibleTransactionCmds era)
| CompatibleGovernanceCmds (CompatibleGovernanceCmds era)
| CompatibleStakeAddress (CompatibleStakeAddressCmds era)

renderCompatibleCommand :: CompatibleCommand era -> Text
renderCompatibleCommand = \case
Expand Down
8 changes: 8 additions & 0 deletions cardano-cli/src/Cardano/CLI/Compatible/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ import Data.Text (Text)
data CompatibleCmdError
= CompatibleTransactionError CompatibleTransactionError
| CompatibleGovernanceError CmdError
| CompatibleStakeAddressError CmdError
| CompatibleStakePoolError CmdError

renderCompatibleCmdError :: Text -> CompatibleCmdError -> Doc ann
renderCompatibleCmdError cmdText = \case
CompatibleTransactionError e -> renderAnyCmdError cmdText prettyError e
CompatibleGovernanceError e -> renderCmdError cmdText e
CompatibleStakeAddressError e -> renderCmdError cmdText e
CompatibleStakePoolError e -> renderCmdError cmdText e

runAnyCompatibleCommand :: AnyCompatibleCommand -> ExceptT CompatibleCmdError IO ()
runAnyCompatibleCommand (AnyCompatibleCommand cmd) = runCompatibleCommand cmd
Expand All @@ -35,3 +39,7 @@ runCompatibleCommand (CompatibleTransactionCmd txCmd) =
firstExceptT CompatibleTransactionError $ runCompatibleTransactionCmd txCmd
runCompatibleCommand (CompatibleGovernanceCmds govCmd) =
firstExceptT CompatibleGovernanceError $ runCompatibleGovernanceCmds govCmd
runCompatibleCommand (CompatibleStakeAddressCmds stakeAddressCmd) =
firstExceptT CompatibleStakeAddressError $ runCompatibleStakeAddressCmds govCmd
runCompatibleCommand (CompatibleStakePoolCmds stakeAddressCmd) =
firstExceptT CompatibleStakePoolError $ runCompatibleStakePoolCmds govCmd
38 changes: 38 additions & 0 deletions cardano-cli/src/Cardano/CLI/Compatible/StakeAddress/Commands.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.Compatible.StakeAddress.Commands
( CompatibleStakeAddressCmds (..)
, renderCompatibleStakeAddressCmds
)
where

import Cardano.Api.Ledger (Coin)
import Cardano.Api.Shelley

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

import Prelude

import Data.Text (Text)

data CompatibleStakeAddressCmds era
= CompatibleStakeAddressRegistrationCertificateCmd
(ShelleyBasedEra era)
StakeIdentifier
(Maybe Coin)
(File () Out)
| CompatibleStakeAddressStakeDelegationCertificateCmd
(ShelleyBasedEra era)
StakeIdentifier
(VerificationKeyOrHashOrFile StakePoolKey)
(File () Out)
deriving Show

renderStakeAddressCmds :: StakeAddressCmds era -> Text
renderStakeAddressCmds =
(<>) "stake-address " . \case
CompatibleStakeAddressRegistrationCertificateCmd{} -> "registration-certificate"
CompatibleStakeAddressStakeDelegationCertificateCmd{} -> "stake-delegation-certificate"
82 changes: 82 additions & 0 deletions cardano-cli/src/Cardano/CLI/Compatible/StakeAddress/Options.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}

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

import Cardano.Api

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

import Options.Applicative
import Options.Applicative qualified as Opt

pStakeAddressCmds
:: ()
=> ShelleyBasedEra era
-> EnvCli
-> Maybe (Parser (CompatibleStakeAddressCmds era))
pStakeAddressCmds era envCli =
subInfoParser
"stake-address"
( Opt.progDesc $
mconcat
[ "Stake address commands."
]
)
[ Just (pStakeAddressRegistrationCertificateCmd era)
, Just (pStakeAddressStakeDelegationCertificateCmd era)
]

pStakeAddressRegistrationCertificateCmd
:: ()
=> ShelleyBasedEra era
-> Parser (CompatibleStakeAddressCmds era)
pStakeAddressRegistrationCertificateCmd sbe = do
caseShelleyToBabbageOrConwayEraOnwards
( const $
subParser "registration-certificate" $
Opt.info
( CompatibleStakeAddressRegistrationCertificateCmd sbe
<$> pStakeIdentifier Nothing
<*> pure Nothing
<*> pOutputFile
)
desc
)
( const $
subParser "registration-certificate" $
Opt.info
( CompatibleStakeAddressRegistrationCertificateCmd sbe
<$> pStakeIdentifier Nothing
<*> fmap Just pKeyRegistDeposit
<*> pOutputFile
)
desc
)
sbe
where
desc = Opt.progDesc "Create a stake address registration certificate"

pStakeAddressStakeDelegationCertificateCmd
:: ()
=> ShelleyBasedEra era
-> Parser (CompatibleStakeAddressCmds era)
pStakeAddressStakeDelegationCertificateCmd sbe = do
subParser "stake-delegation-certificate"
$ Opt.info
( CompatibleStakeAddressStakeDelegationCertificateCmd sbe
<$> pStakeIdentifier Nothing
<*> pStakePoolVerificationKeyOrHashOrFile Nothing
<*> pOutputFile
)
$ Opt.progDesc
$ mconcat
[ "Create a stake address stake delegation certificate, which when submitted in a transaction "
, "delegates stake to a stake pool."
]
59 changes: 59 additions & 0 deletions cardano-cli/src/Cardano/CLI/Compatible/StakePool/Commands.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.Compatible.StakePool.Commands
( CompatibleStakePoolCmds (..)
, renderCompatibleStakePoolCmds
, CompatibleStakePoolRegistrationCertificateCmdArgs (..)
)
where

import Cardano.Api.Ledger (Coin)
import Cardano.Api.Ledger qualified as L
import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..))

import Cardano.CLI.Commands.Hash (HashGoal)
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key

import Prelude

import Data.Text (Text)

data CompatibleStakePoolCmds era
= CompatibleStakePoolRegistrationCertificateCmd !(CompatibleStakePoolRegistrationCertificateCmdArgs era)
deriving Show

Check notice

Code scanning / HLint

Use newtype instead of data Note

cardano-cli/src/Cardano/CLI/Compatible/StakePool/Commands.hs:(22,1)-(25,15): Suggestion: Use newtype instead of data
  
Found:
  data CompatibleStakePoolCmds era
    = CompatibleStakePoolRegistrationCertificateCmd !(CompatibleStakePoolRegistrationCertificateCmdArgs era)
    deriving Show
  
Perhaps:
  newtype CompatibleStakePoolCmds era
    = CompatibleStakePoolRegistrationCertificateCmd (CompatibleStakePoolRegistrationCertificateCmdArgs era)
    deriving Show

data CompatibleStakePoolRegistrationCertificateCmdArgs era
= CompatibleStakePoolRegistrationCertificateCmdArgs
{ sbe :: !(ShelleyBasedEra era)
-- ^ Era in which to register the stake pool.
, poolVerificationKeyOrFile :: !(VerificationKeyOrFile StakePoolKey)
-- ^ Stake pool verification key.
, vrfVerificationKeyOrFile :: !(VerificationKeyOrFile VrfKey)
-- ^ VRF Verification key.
, poolPledge :: !Coin
-- ^ Pool pledge.
, poolCost :: !Coin
-- ^ Pool cost.
, poolMargin :: !Rational
-- ^ Pool margin.
, rewardStakeVerificationKeyOrFile :: !(VerificationKeyOrFile StakeKey)
-- ^ Reward account verification staking key.
, ownerStakeVerificationKeyOrFiles :: ![VerificationKeyOrFile StakeKey]
-- ^ Pool owner verification staking key(s).
, relays :: ![StakePoolRelay]
-- ^ Stake pool relays.
, mMetadata
:: !(Maybe (PotentiallyCheckedAnchor StakePoolMetadataReference StakePoolMetadataReference))
-- ^ Stake pool metadata.
, network :: !NetworkId
, outFile :: !(File () Out)
}
deriving Show

renderStakePoolCmds :: StakePoolCmds era -> Text
renderStakePoolCmds = (<>) "stake-pool " . \case
StakePoolRegistrationCertificateCmd{} ->
"registration-certificate"

0 comments on commit 2e3e4d7

Please sign in to comment.