Skip to content

Commit ca174fe

Browse files
authored
Merge pull request #1070 from IntersectMBO/mgalazyn/feature/add-more-compatible-commands
Add stake address registration and delegation certificate and stake pool delegation certificate to compatible commands
2 parents a1d8c95 + a78730c commit ca174fe

File tree

68 files changed

+2408
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2408
-283
lines changed

cardano-cli/cardano-cli.cabal

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ library
6868
Cardano.CLI.Compatible.Governance.Run
6969
Cardano.CLI.Compatible.Option
7070
Cardano.CLI.Compatible.Run
71+
Cardano.CLI.Compatible.StakeAddress.Command
72+
Cardano.CLI.Compatible.StakeAddress.Option
73+
Cardano.CLI.Compatible.StakeAddress.Run
74+
Cardano.CLI.Compatible.StakePool.Command
75+
Cardano.CLI.Compatible.StakePool.Option
76+
Cardano.CLI.Compatible.StakePool.Run
7177
Cardano.CLI.Compatible.Transaction.Command
7278
Cardano.CLI.Compatible.Transaction.Option
7379
Cardano.CLI.Compatible.Transaction.Run
@@ -122,6 +128,7 @@ library
122128
Cardano.CLI.EraBased.StakeAddress.Option
123129
Cardano.CLI.EraBased.StakeAddress.Run
124130
Cardano.CLI.EraBased.StakePool.Command
131+
Cardano.CLI.EraBased.StakePool.Internal.Metadata
125132
Cardano.CLI.EraBased.StakePool.Option
126133
Cardano.CLI.EraBased.StakePool.Run
127134
Cardano.CLI.EraBased.TextView.Command
@@ -361,7 +368,12 @@ test-suite cardano-cli-test
361368
build-tool-depends: tasty-discover:tasty-discover
362369
other-modules:
363370
Test.Cli.AddCostModels
371+
Test.Cli.Certificates.StakePool
364372
Test.Cli.CheckNodeConfiguration
373+
Test.Cli.Compatible.StakeAddress.DelegationCertificate
374+
Test.Cli.Compatible.StakeAddress.RegistrationCertificate
375+
Test.Cli.Compatible.StakePool.RegistrationCertificate
376+
Test.Cli.Compatible.Transaction.Build
365377
Test.Cli.CreateCardano
366378
Test.Cli.CreateTestnetData
367379
Test.Cli.DRepMetadata
@@ -382,11 +394,9 @@ test-suite cardano-cli-test
382394
Test.Cli.Pioneers.Exercise5
383395
Test.Cli.Pioneers.Exercise6
384396
Test.Cli.Pipes
385-
Test.Cli.Shelley.Certificates.StakePool
386-
Test.Cli.Shelley.Run.Hash
387-
Test.Cli.Shelley.Run.Query
388-
Test.Cli.Shelley.Transaction.Build
389-
Test.Cli.Shelley.Transaction.Compatible.Build
397+
Test.Cli.Run.Hash
398+
Test.Cli.Run.Query
399+
Test.Cli.Transaction.Build
390400
Test.Cli.VerificationKey
391401

392402
ghc-options:

cardano-cli/src/Cardano/CLI/Compatible/Command.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module Cardano.CLI.Compatible.Command
1515
where
1616

1717
import Cardano.CLI.Compatible.Governance.Command
18+
import Cardano.CLI.Compatible.StakeAddress.Command
19+
import Cardano.CLI.Compatible.StakePool.Command
1820
import Cardano.CLI.Compatible.Transaction.Command
1921

2022
import Data.Text
@@ -27,10 +29,14 @@ renderAnyCompatibleCommand = \case
2729
AnyCompatibleCommand cmd -> renderCompatibleCommand cmd
2830

2931
data CompatibleCommand era
30-
= CompatibleTransactionCmd (CompatibleTransactionCmds era)
32+
= CompatibleTransactionCmds (CompatibleTransactionCmds era)
3133
| CompatibleGovernanceCmds (CompatibleGovernanceCmds era)
34+
| CompatibleStakeAddressCmds (CompatibleStakeAddressCmds era)
35+
| CompatibleStakePoolCmds (CompatibleStakePoolCmds era)
3236

3337
renderCompatibleCommand :: CompatibleCommand era -> Text
3438
renderCompatibleCommand = \case
35-
CompatibleTransactionCmd cmd -> renderCompatibleTransactionCmd cmd
39+
CompatibleTransactionCmds cmd -> renderCompatibleTransactionCmd cmd
3640
CompatibleGovernanceCmds cmd -> renderCompatibleGovernanceCmds cmd
41+
CompatibleStakeAddressCmds cmd -> renderCompatibleStakeAddressCmds cmd
42+
CompatibleStakePoolCmds cmd -> renderCompatibleStakePoolCmds cmd

cardano-cli/src/Cardano/CLI/Compatible/Exception.hs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Cardano.CLI.Compatible.Exception
99
, throwCliError
1010
, fromEitherCli
1111
, fromEitherIOCli
12+
, fromExceptTCli
1213
)
1314
where
1415

@@ -25,8 +26,8 @@ type CIO e a = HasCallStack => RIO e a
2526
-- in `cardano-cl` should be wrapped in this exception type.
2627
data CustomCliException where
2728
CustomCliException
28-
:: (HasCallStack, Show error, Typeable error, Error error)
29-
=> error -> CustomCliException
29+
:: (HasCallStack, Show err, Typeable err, Error err)
30+
=> err -> CustomCliException
3031

3132
deriving instance Show CustomCliException
3233

@@ -37,13 +38,34 @@ instance Exception CustomCliException where
3738
, prettyCallStack callStack
3839
]
3940

40-
throwCliError :: MonadIO m => CustomCliException -> m a
41-
throwCliError = throwIO
41+
-- | Wrapper function which allows throwing of types of instance `Error`, attaching call stack
42+
-- from the call site
43+
throwCliError
44+
:: forall e m a
45+
. (HasCallStack, Show e, Typeable e, Error e, MonadIO m)
46+
=> e
47+
-> m a
48+
throwCliError = withFrozenCallStack $ throwIO . CustomCliException
4249

43-
fromEitherCli :: (HasCallStack, MonadIO m, Show e, Typeable e, Error e) => Either e a -> m a
50+
fromEitherCli
51+
:: forall e m a
52+
. (HasCallStack, MonadIO m, Show e, Typeable e, Error e)
53+
=> Either e a
54+
-> m a
4455
fromEitherCli = withFrozenCallStack $ \case
45-
Left e -> throwCliError $ CustomCliException e
56+
Left e -> throwCliError e
4657
Right a -> return a
4758

48-
fromEitherIOCli :: (HasCallStack, MonadIO m, Show e, Typeable e, Error e) => IO (Either e a) -> m a
49-
fromEitherIOCli action = liftIO action >>= fromEitherCli
59+
fromEitherIOCli
60+
:: forall e m a
61+
. (HasCallStack, MonadIO m, Show e, Typeable e, Error e)
62+
=> IO (Either e a)
63+
-> m a
64+
fromEitherIOCli action = withFrozenCallStack $ liftIO action >>= fromEitherCli
65+
66+
fromExceptTCli
67+
:: forall e m a
68+
. (HasCallStack, MonadIO m, Show e, Typeable e, Error e)
69+
=> ExceptT e IO a
70+
-> m a
71+
fromExceptTCli = withFrozenCallStack $ fromEitherIOCli . runExceptT
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
{-# LANGUAGE DataKinds #-}
22
{-# LANGUAGE LambdaCase #-}
3+
{-# LANGUAGE RankNTypes #-}
34

45
module Cardano.CLI.Compatible.Governance.Run
56
( runCompatibleGovernanceCmds
67
)
78
where
89

9-
import Cardano.Api
10-
10+
import Cardano.CLI.Compatible.Exception
1111
import Cardano.CLI.Compatible.Governance.Command
1212
import Cardano.CLI.EraBased.Governance.Run
13-
import Cardano.CLI.Type.Error.CmdError
1413

15-
runCompatibleGovernanceCmds :: CompatibleGovernanceCmds era -> ExceptT CmdError IO ()
14+
runCompatibleGovernanceCmds :: CompatibleGovernanceCmds era -> CIO e ()
1615
runCompatibleGovernanceCmds = \case
17-
CreateCompatibleProtocolUpdateCmd cmd -> runGovernanceCmds cmd
16+
CreateCompatibleProtocolUpdateCmd cmd -> fromExceptTCli $ runGovernanceCmds cmd

cardano-cli/src/Cardano/CLI/Compatible/Option.hs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ import Cardano.Api
1515

1616
import Cardano.CLI.Compatible.Command
1717
import Cardano.CLI.Compatible.Governance.Option
18+
import Cardano.CLI.Compatible.StakeAddress.Option
19+
import Cardano.CLI.Compatible.StakePool.Option
1820
import Cardano.CLI.Compatible.Transaction.Option
1921
import Cardano.CLI.Environment
2022
import Cardano.CLI.Parser
2123

22-
import Data.Foldable
23-
import Options.Applicative
24+
import Data.Foldable (asum)
25+
import Data.Maybe
26+
import Options.Applicative (Parser)
2427
import Options.Applicative qualified as Opt
2528

2629
pAnyCompatibleCommand :: EnvCli -> Parser AnyCompatibleCommand
@@ -49,7 +52,10 @@ pAnyCompatibleCommand envCli =
4952

5053
pCompatibleCommand :: ShelleyBasedEra era -> EnvCli -> Parser (CompatibleCommand era)
5154
pCompatibleCommand era env =
52-
asum
53-
[ CompatibleTransactionCmd <$> pAllCompatibleTransactionCommands env era
54-
, CompatibleGovernanceCmds <$> pCompatibleGovernanceCmds era
55-
]
55+
asum $
56+
catMaybes
57+
[ Just $ CompatibleTransactionCmds <$> pAllCompatibleTransactionCommands env era
58+
, Just $ CompatibleGovernanceCmds <$> pCompatibleGovernanceCmds era
59+
, fmap CompatibleStakeAddressCmds <$> pCompatibleStakeAddressCmds era
60+
, fmap CompatibleStakePoolCmds <$> pCompatibleStakePoolCmds era env
61+
]

cardano-cli/src/Cardano/CLI/Compatible/Run.hs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,28 @@
33
{-# LANGUAGE ScopedTypeVariables #-}
44

55
module Cardano.CLI.Compatible.Run
6-
( CompatibleCmdError
7-
, renderCompatibleCmdError
8-
, runAnyCompatibleCommand
6+
( runAnyCompatibleCommand
97
, runCompatibleCommand
108
)
119
where
1210

13-
import Cardano.Api
14-
1511
import Cardano.CLI.Compatible.Command
12+
import Cardano.CLI.Compatible.Exception
1613
import Cardano.CLI.Compatible.Governance.Run
14+
import Cardano.CLI.Compatible.StakeAddress.Run
15+
import Cardano.CLI.Compatible.StakePool.Run
1716
import Cardano.CLI.Compatible.Transaction.Run
18-
import Cardano.CLI.Render
19-
import Cardano.CLI.Type.Error.CmdError
20-
21-
import RIO
22-
23-
data CompatibleCmdError
24-
= CompatibleTransactionError CompatibleTransactionError
25-
| CompatibleGovernanceError CmdError
26-
27-
renderCompatibleCmdError :: Text -> CompatibleCmdError -> Doc ann
28-
renderCompatibleCmdError cmdText = \case
29-
CompatibleTransactionError e -> renderAnyCmdError cmdText prettyError e
30-
CompatibleGovernanceError e -> renderCmdError cmdText e
3117

32-
runAnyCompatibleCommand :: AnyCompatibleCommand -> ExceptT CompatibleCmdError IO ()
18+
runAnyCompatibleCommand :: AnyCompatibleCommand -> CIO e ()
3319
runAnyCompatibleCommand (AnyCompatibleCommand cmd) = runCompatibleCommand cmd
3420

35-
runCompatibleCommand :: CompatibleCommand era -> ExceptT CompatibleCmdError IO ()
36-
runCompatibleCommand (CompatibleTransactionCmd txCmd) =
37-
runRIO () (runCompatibleTransactionCmd txCmd)
38-
runCompatibleCommand (CompatibleGovernanceCmds govCmd) =
39-
firstExceptT CompatibleGovernanceError $ runCompatibleGovernanceCmds govCmd
21+
runCompatibleCommand :: CompatibleCommand era -> CIO e ()
22+
runCompatibleCommand = \case
23+
CompatibleTransactionCmds txCmd ->
24+
runCompatibleTransactionCmd txCmd
25+
CompatibleGovernanceCmds govCmd ->
26+
runCompatibleGovernanceCmds govCmd
27+
CompatibleStakeAddressCmds stakeAddressCmd ->
28+
runCompatibleStakeAddressCmds stakeAddressCmd
29+
CompatibleStakePoolCmds stakePoolCmd ->
30+
runCompatibleStakePoolCmds stakePoolCmd
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE LambdaCase #-}
3+
4+
module Cardano.CLI.Compatible.StakeAddress.Command
5+
( CompatibleStakeAddressCmds (..)
6+
, renderCompatibleStakeAddressCmds
7+
)
8+
where
9+
10+
import Cardano.Api.Ledger (Coin)
11+
import Cardano.Api.Shelley
12+
13+
import Cardano.CLI.Type.Key
14+
15+
import Prelude
16+
17+
import Data.Text (Text)
18+
19+
data CompatibleStakeAddressCmds era
20+
= CompatibleStakeAddressRegistrationCertificateCmd
21+
(ShelleyBasedEra era)
22+
StakeIdentifier
23+
(Maybe (Featured ConwayEraOnwards era Coin))
24+
-- ^ Deposit required in conway era
25+
(File () Out)
26+
| CompatibleStakeAddressStakeDelegationCertificateCmd
27+
(ShelleyBasedEra era)
28+
StakeIdentifier
29+
(VerificationKeyOrHashOrFile StakePoolKey)
30+
(File () Out)
31+
deriving Show
32+
33+
renderCompatibleStakeAddressCmds :: CompatibleStakeAddressCmds era -> Text
34+
renderCompatibleStakeAddressCmds =
35+
(<>) "stake-address " . \case
36+
CompatibleStakeAddressRegistrationCertificateCmd{} -> "registration-certificate"
37+
CompatibleStakeAddressStakeDelegationCertificateCmd{} -> "stake-delegation-certificate"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE GADTs #-}
3+
4+
module Cardano.CLI.Compatible.StakeAddress.Option
5+
( pCompatibleStakeAddressCmds
6+
)
7+
where
8+
9+
import Cardano.Api
10+
11+
import Cardano.CLI.Compatible.StakeAddress.Command
12+
import Cardano.CLI.EraBased.Common.Option
13+
import Cardano.CLI.Parser
14+
15+
import Options.Applicative
16+
import Options.Applicative qualified as Opt
17+
18+
pCompatibleStakeAddressCmds
19+
:: ()
20+
=> ShelleyBasedEra era
21+
-> Maybe (Parser (CompatibleStakeAddressCmds era))
22+
pCompatibleStakeAddressCmds era =
23+
subInfoParser
24+
"stake-address"
25+
( Opt.progDesc $
26+
mconcat
27+
[ "Stake address commands."
28+
]
29+
)
30+
[ Just $ pStakeAddressRegistrationCertificateCmd era
31+
, Just $ pStakeAddressStakeDelegationCertificateCmd era
32+
]
33+
34+
pStakeAddressRegistrationCertificateCmd
35+
:: ()
36+
=> ShelleyBasedEra era
37+
-> Parser (CompatibleStakeAddressCmds era)
38+
pStakeAddressRegistrationCertificateCmd sbe = do
39+
subParser "registration-certificate" $
40+
Opt.info
41+
( CompatibleStakeAddressRegistrationCertificateCmd sbe
42+
<$> pStakeIdentifier Nothing
43+
<*> pFeatured (toCardanoEra sbe) pKeyRegistDeposit
44+
<*> pOutputFile
45+
)
46+
desc
47+
where
48+
desc = Opt.progDesc "Create a stake address registration certificate"
49+
50+
pStakeAddressStakeDelegationCertificateCmd
51+
:: ()
52+
=> ShelleyBasedEra era
53+
-> Parser (CompatibleStakeAddressCmds era)
54+
pStakeAddressStakeDelegationCertificateCmd sbe = do
55+
subParser "stake-delegation-certificate"
56+
$ Opt.info
57+
( CompatibleStakeAddressStakeDelegationCertificateCmd sbe
58+
<$> pStakeIdentifier Nothing
59+
<*> pStakePoolVerificationKeyOrHashOrFile Nothing
60+
<*> pOutputFile
61+
)
62+
$ Opt.progDesc
63+
$ mconcat
64+
[ "Create a stake address stake delegation certificate, which when submitted in a transaction "
65+
, "delegates stake to a stake pool."
66+
]

0 commit comments

Comments
 (0)