Skip to content

Commit

Permalink
Merge pull request #243 from input-output-hk/newhoggy/tidy-up-stake-a…
Browse files Browse the repository at this point in the history
…ddress-command-related-names

Rename `delegation-certificate` to `stake-delegation-certificate` only in era-based command structure
  • Loading branch information
newhoggy authored Sep 6, 2023
2 parents 509004a + 785183c commit 0c682f8
Show file tree
Hide file tree
Showing 27 changed files with 423 additions and 387 deletions.
26 changes: 13 additions & 13 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ import Prelude
import Data.Text (Text)

data StakeAddressCmds era
= StakeAddressKeyGen
= StakeAddressKeyGenCmd
(ShelleyBasedEra era)
KeyOutputFormat
(VerificationKeyFile Out)
(SigningKeyFile Out)
| StakeAddressKeyHash
| StakeAddressKeyHashCmd
(ShelleyBasedEra era)
(VerificationKeyOrFile StakeKey)
(Maybe (File () Out))
| StakeAddressBuild
| StakeAddressBuildCmd
(ShelleyBasedEra era)
StakeVerifier
NetworkId
(Maybe (File () Out))
| StakeRegistrationCert
| StakeAddressRegistrationCertificateCmd
(ShelleyBasedEra era)
StakeIdentifier
(Maybe Lovelace)
(File () Out)
| StakeCredentialDelegationCert
| StakeAddressStakeDelegationCertificateCmd
(ShelleyBasedEra era)
StakeIdentifier
DelegationTarget
(VerificationKeyOrHashOrFile StakePoolKey)
(File () Out)
| StakeCredentialDeRegistrationCert
| StakeAddressDeregistrationCertificateCmd
(ShelleyBasedEra era)
StakeIdentifier
(Maybe Lovelace)
Expand All @@ -49,9 +49,9 @@ data StakeAddressCmds era

renderStakeAddressCmds :: StakeAddressCmds era -> Text
renderStakeAddressCmds = \case
StakeAddressKeyGen {} -> "stake-address key-gen"
StakeAddressKeyHash {} -> "stake-address key-hash"
StakeAddressBuild {} -> "stake-address build"
StakeRegistrationCert {} -> "stake-address registration-certificate"
StakeCredentialDelegationCert {} -> "stake-address delegation-certificate"
StakeCredentialDeRegistrationCert {} -> "stake-address deregistration-certificate"
StakeAddressKeyGenCmd {} -> "stake-address key-gen"
StakeAddressKeyHashCmd {} -> "stake-address key-hash"
StakeAddressBuildCmd {} -> "stake-address build"
StakeAddressRegistrationCertificateCmd {} -> "stake-address registration-certificate"
StakeAddressStakeDelegationCertificateCmd {} -> "stake-address stake-delegation-certificate"
StakeAddressDeregistrationCertificateCmd {} -> "stake-address deregistration-certificate"
4 changes: 0 additions & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2147,10 +2147,6 @@ pStakePoolVerificationKeyHash =
]
]

pDelegationTarget :: ()
=> Parser DelegationTarget
pDelegationTarget = StakePoolDelegationTarget <$> pStakePoolVerificationKeyOrHashOrFile

pVrfVerificationKeyFile :: Parser (VerificationKeyFile In)
pVrfVerificationKeyFile =
fmap File $ Opt.strOption $ mconcat
Expand Down
28 changes: 16 additions & 12 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pStakeAddressCmds era envCli =
, pStakeAddressBuildCmd era envCli
, pStakeAddressRegistrationCertificateCmd era
, pStakeAddressDeregistrationCertificateCmd era
, pStakeAddressDelegationCertificateCmd era
, pStakeAddressStakeDelegationCertificateCmd era
]

pStakeAddressKeyGenCmd :: ()
Expand All @@ -42,7 +42,7 @@ pStakeAddressKeyGenCmd era = do
pure
$ subParser "key-gen"
$ Opt.info
( StakeAddressKeyGen w
( StakeAddressKeyGenCmd w
<$> pKeyOutputFormat
<*> pVerificationKeyFileOut
<*> pSigningKeyFileOut
Expand All @@ -57,7 +57,7 @@ pStakeAddressKeyHashCmd era = do
pure
$ subParser "key-hash"
$ Opt.info
( StakeAddressKeyHash w
( StakeAddressKeyHashCmd w
<$> pStakeVerificationKeyOrFile
<*> pMaybeOutputFile
)
Expand All @@ -72,7 +72,7 @@ pStakeAddressBuildCmd era envCli = do
pure
$ subParser "build"
$ Opt.info
( StakeAddressBuild w
( StakeAddressBuildCmd w
<$> pStakeVerifier
<*> pNetworkId envCli
<*> pMaybeOutputFile
Expand All @@ -87,7 +87,7 @@ pStakeAddressRegistrationCertificateCmd era = do
pure
$ subParser "registration-certificate"
$ Opt.info
( StakeRegistrationCert w
( StakeAddressRegistrationCertificateCmd w
<$> pStakeIdentifier
<*> optional pKeyRegistDeposit
<*> pOutputFile
Expand All @@ -102,24 +102,28 @@ pStakeAddressDeregistrationCertificateCmd era = do
pure
$ subParser "deregistration-certificate"
$ Opt.info
( StakeCredentialDeRegistrationCert w
( StakeAddressDeregistrationCertificateCmd w
<$> pStakeIdentifier
<*> optional pKeyRegistDeposit
<*> pOutputFile
)
$ Opt.progDesc "Create a stake address deregistration certificate"

pStakeAddressDelegationCertificateCmd :: ()
pStakeAddressStakeDelegationCertificateCmd :: ()
=> CardanoEra era
-> Maybe (Parser (StakeAddressCmds era))
pStakeAddressDelegationCertificateCmd era = do
pStakeAddressStakeDelegationCertificateCmd era = do
w <- maybeFeatureInEra era
pure
$ subParser "delegation-certificate"
$ subParser "stake-delegation-certificate"
$ Opt.info
( StakeCredentialDelegationCert w
( StakeAddressStakeDelegationCertificateCmd w
<$> pStakeIdentifier
<*> pDelegationTarget
<*> pStakePoolVerificationKeyOrHashOrFile
<*> pOutputFile
)
$ Opt.progDesc "Create a stake address pool delegation certificate"
$ Opt.progDesc
$ mconcat
[ "Create a stake address stake delegation certificate, which when submitted in a transaction "
, "delegates stake to a stake pool."
]
88 changes: 45 additions & 43 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ module Cardano.CLI.EraBased.Run.StakeAddress
( runStakeAddressCmds

, runStakeAddressBuildCmd
, runStakeAddressKeyGenToFileCmd
, runStakeAddressKeyGenCmd
, runStakeAddressKeyHashCmd
, runStakeCredentialDelegationCertCmd
, runStakeCredentialDeRegistrationCertCmd
, runStakeCredentialRegistrationCertCmd
, runStakeAddressStakeDelegationCertificateCmd
, runStakeAddressDeregistrationCertificateCmd
, runStakeAddressRegistrationCertificateCmd
) where

import Cardano.Api
Expand All @@ -27,9 +27,7 @@ import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError
import Cardano.CLI.Types.Errors.StakeAddressDelegationError
import Cardano.CLI.Types.Errors.StakeAddressRegistrationError
import Cardano.CLI.Types.Key (DelegationTarget (..), StakeIdentifier (..),
StakeVerifier (..), VerificationKeyOrFile, readVerificationKeyOrFile,
readVerificationKeyOrHashOrFile)
import Cardano.CLI.Types.Key

import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans (lift)
Expand All @@ -44,25 +42,25 @@ runStakeAddressCmds :: ()
=> StakeAddressCmds era
-> ExceptT ShelleyStakeAddressCmdError IO ()
runStakeAddressCmds = \case
StakeAddressKeyGen _ fmt vk sk ->
runStakeAddressKeyGenToFileCmd fmt vk sk
StakeAddressKeyHash _ vk mOutputFp ->
StakeAddressKeyGenCmd _ fmt vk sk ->
runStakeAddressKeyGenCmd fmt vk sk
StakeAddressKeyHashCmd _ vk mOutputFp ->
runStakeAddressKeyHashCmd vk mOutputFp
StakeAddressBuild _ stakeVerifier nw mOutputFp ->
StakeAddressBuildCmd _ 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 :: ()
StakeAddressRegistrationCertificateCmd sbe stakeIdentifier mDeposit outputFp ->
runStakeAddressRegistrationCertificateCmd sbe stakeIdentifier mDeposit outputFp
StakeAddressStakeDelegationCertificateCmd sbe stakeIdentifier stkPoolVerKeyHashOrFp outputFp ->
runStakeAddressStakeDelegationCertificateCmd sbe stakeIdentifier stkPoolVerKeyHashOrFp outputFp
StakeAddressDeregistrationCertificateCmd sbe stakeIdentifier mDeposit outputFp ->
runStakeAddressDeregistrationCertificateCmd sbe stakeIdentifier mDeposit outputFp

runStakeAddressKeyGenCmd :: ()
=> KeyOutputFormat
-> VerificationKeyFile Out
-> SigningKeyFile Out
-> ExceptT ShelleyStakeAddressCmdError IO ()
runStakeAddressKeyGenToFileCmd fmt vkFp skFp = do
runStakeAddressKeyGenCmd fmt vkFp skFp = do
let skeyDesc = "Stake Signing Key"
let vkeyDesc = "Stake Verification Key"

Expand Down Expand Up @@ -114,13 +112,13 @@ runStakeAddressBuildCmd stakeVerifier network mOutputFp = do
Nothing -> Text.putStrLn stakeAddrText


runStakeCredentialRegistrationCertCmd :: ()
runStakeAddressRegistrationCertificateCmd :: ()
=> ShelleyBasedEra era
-> StakeIdentifier
-> Maybe Lovelace -- ^ Deposit required in conway era
-> File () Out
-> ExceptT ShelleyStakeAddressCmdError IO ()
runStakeCredentialRegistrationCertCmd sbe stakeIdentifier mDeposit oFp = do
runStakeAddressRegistrationCertificateCmd sbe stakeIdentifier mDeposit oFp = do
stakeCred <-
getStakeCredentialFromIdentifier stakeIdentifier
& firstExceptT ShelleyStakeAddressCmdStakeCredentialError
Expand Down Expand Up @@ -163,32 +161,36 @@ createRegistrationCertRequirements sbe stakeCred mdeposit =
Just dep ->
return $ StakeAddrRegistrationConway ConwayEraOnwardsConway dep stakeCred

runStakeCredentialDelegationCertCmd :: ()
runStakeAddressStakeDelegationCertificateCmd :: ()
=> ShelleyBasedEra era
-> StakeIdentifier
-- ^ Delegator stake verification key, verification key file or script file.
-> DelegationTarget
-> VerificationKeyOrHashOrFile StakePoolKey
-- ^ Delegatee stake pool verification key or verification key file or
-- verification key hash.
-> File () Out
-> ExceptT ShelleyStakeAddressCmdError IO ()
runStakeCredentialDelegationCertCmd sbe stakeVerifier delegationTarget outFp =
shelleyBasedEraConstraints sbe $
case delegationTarget of
StakePoolDelegationTarget poolVKeyOrHashOrFile -> do
StakePoolKeyHash poolStakeVKeyHash <- lift (readVerificationKeyOrHashOrFile AsStakePoolKey poolVKeyOrHashOrFile)
& onLeft (left . ShelleyStakeAddressCmdReadKeyFileError)
let delegatee = Ledger.DelegStake poolStakeVKeyHash
stakeCred <-
getStakeCredentialFromIdentifier stakeVerifier
& firstExceptT ShelleyStakeAddressCmdStakeCredentialError
req <- firstExceptT StakeDelegationError . hoistEither
$ createDelegationCertRequirements sbe stakeCred delegatee
let delegCert = makeStakeAddressDelegationCertificate req
firstExceptT ShelleyStakeAddressCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile outFp
$ textEnvelopeToJSON (Just @TextEnvelopeDescr "Stake Address Delegation Certificate") delegCert
runStakeAddressStakeDelegationCertificateCmd sbe stakeVerifier poolVKeyOrHashOrFile outFp =
shelleyBasedEraConstraints sbe $ do
StakePoolKeyHash poolStakeVKeyHash <-
lift (readVerificationKeyOrHashOrFile AsStakePoolKey poolVKeyOrHashOrFile)
& onLeft (left . ShelleyStakeAddressCmdReadKeyFileError)

let delegatee = Ledger.DelegStake poolStakeVKeyHash

stakeCred <-
getStakeCredentialFromIdentifier stakeVerifier
& firstExceptT ShelleyStakeAddressCmdStakeCredentialError

req <- firstExceptT StakeDelegationError . hoistEither
$ createDelegationCertRequirements sbe stakeCred delegatee

let delegCert = makeStakeAddressDelegationCertificate req

firstExceptT ShelleyStakeAddressCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile outFp
$ textEnvelopeToJSON (Just @TextEnvelopeDescr "Stake Address Delegation Certificate") delegCert

createDelegationCertRequirements :: ()
=> ShelleyBasedEra era
Expand Down Expand Up @@ -227,13 +229,13 @@ onlySpoDelegatee w = \case
Ledger.DelegStakeVote{} ->
Left . VoteDelegationNotSupported $ AnyShelleyToBabbageEra w

runStakeCredentialDeRegistrationCertCmd :: ()
runStakeAddressDeregistrationCertificateCmd :: ()
=> ShelleyBasedEra era
-> StakeIdentifier
-> Maybe Lovelace -- ^ Deposit required in conway era
-> File () Out
-> ExceptT ShelleyStakeAddressCmdError IO ()
runStakeCredentialDeRegistrationCertCmd sbe stakeVerifier mDeposit oFp = do
runStakeAddressDeregistrationCertificateCmd sbe stakeVerifier mDeposit oFp = do
stakeCred <-
getStakeCredentialFromIdentifier stakeVerifier
& firstExceptT ShelleyStakeAddressCmdStakeCredentialError
Expand Down
26 changes: 13 additions & 13 deletions cardano-cli/src/Cardano/CLI/Legacy/Commands/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ import Prelude
import Data.Text (Text)

data LegacyStakeAddressCmds
= StakeAddressKeyGen
= StakeAddressKeyGenCmd
KeyOutputFormat
(VerificationKeyFile Out)
(SigningKeyFile Out)
| StakeAddressKeyHash
| StakeAddressKeyHashCmd
(VerificationKeyOrFile StakeKey)
(Maybe (File () Out))
| StakeAddressBuild
| StakeAddressBuildCmd
StakeVerifier
NetworkId
(Maybe (File () Out))
| StakeRegistrationCert
| StakeAddressRegistrationCertificateCmd
AnyShelleyBasedEra
StakeIdentifier
(Maybe Lovelace)
(File () Out)
| StakeCredentialDelegationCert
| StakeAddressDelegationCertificateCmd
AnyShelleyBasedEra
StakeIdentifier
DelegationTarget
(VerificationKeyOrHashOrFile StakePoolKey)
(File () Out)
| StakeCredentialDeRegistrationCert
| StakeAddressDeregistrationCertificateCmd
AnyShelleyBasedEra
StakeIdentifier
(Maybe Lovelace)
Expand All @@ -47,9 +47,9 @@ data LegacyStakeAddressCmds

renderLegacyStakeAddressCmds :: LegacyStakeAddressCmds -> Text
renderLegacyStakeAddressCmds = \case
StakeAddressKeyGen {} -> "stake-address key-gen"
StakeAddressKeyHash {} -> "stake-address key-hash"
StakeAddressBuild {} -> "stake-address build"
StakeRegistrationCert {} -> "stake-address registration-certificate"
StakeCredentialDelegationCert {} -> "stake-address delegation-certificate"
StakeCredentialDeRegistrationCert {} -> "stake-address deregistration-certificate"
StakeAddressKeyGenCmd {} -> "stake-address key-gen"
StakeAddressKeyHashCmd {} -> "stake-address key-hash"
StakeAddressBuildCmd {} -> "stake-address build"
StakeAddressRegistrationCertificateCmd {} -> "stake-address registration-certificate"
StakeAddressDelegationCertificateCmd {} -> "stake-address delegation-certificate"
StakeAddressDeregistrationCertificateCmd {} -> "stake-address deregistration-certificate"
Loading

0 comments on commit 0c682f8

Please sign in to comment.