diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/StakeAddress.hs index f6559cb08d..ab558402c0 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/StakeAddress.hs @@ -40,6 +40,12 @@ data StakeAddressCmds era StakeIdentifier (VerificationKeyOrHashOrFile StakePoolKey) (File () Out) + | StakeAddressStakeAndVoteDelegationCertificateCmd + (ConwayEraOnwards era) + StakeIdentifier + (VerificationKeyOrHashOrFile StakePoolKey) + (VerificationKeyOrHashOrFile DRepKey) + (File () Out) | StakeAddressDeregistrationCertificateCmd (ShelleyBasedEra era) StakeIdentifier @@ -54,4 +60,5 @@ renderStakeAddressCmds = \case StakeAddressBuildCmd {} -> "stake-address build" StakeAddressRegistrationCertificateCmd {} -> "stake-address registration-certificate" StakeAddressStakeDelegationCertificateCmd {} -> "stake-address stake-delegation-certificate" + StakeAddressStakeAndVoteDelegationCertificateCmd {} -> "stake-address stake-and-vote-delegation-certificate" StakeAddressDeregistrationCertificateCmd {} -> "stake-address deregistration-certificate" diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs index e1a74f2967..f6142db78f 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs @@ -32,6 +32,7 @@ pStakeAddressCmds era envCli = , pStakeAddressRegistrationCertificateCmd era , pStakeAddressDeregistrationCertificateCmd era , pStakeAddressStakeDelegationCertificateCmd era + , pStakeAddressStakeAndVoteDelegationCertificateCmd era ] pStakeAddressKeyGenCmd :: () @@ -127,3 +128,23 @@ pStakeAddressStakeDelegationCertificateCmd era = do [ "Create a stake address stake delegation certificate, which when submitted in a transaction " , "delegates stake to a stake pool." ] + +pStakeAddressStakeAndVoteDelegationCertificateCmd :: () + => CardanoEra era + -> Maybe (Parser (StakeAddressCmds era)) +pStakeAddressStakeAndVoteDelegationCertificateCmd era = do + w <- maybeFeatureInEra era + pure + $ subParser "stake-and-vote-delegation-certificate" + $ Opt.info + ( StakeAddressStakeAndVoteDelegationCertificateCmd w + <$> pStakeIdentifier + <*> pStakePoolVerificationKeyOrHashOrFile + <*> pDRepVerificationKeyOrHashOrFile + <*> pOutputFile + ) + $ Opt.progDesc + $ mconcat + [ "Create a stake address stake and vote delegation certificate, which when submitted in a transaction " + , "delegates stake to a stake pool and a DRep." + ] diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs index 67108ebc33..269d98afb0 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs @@ -26,6 +26,7 @@ import Cardano.CLI.EraBased.Commands.StakeAddress import Cardano.CLI.Read import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError +import Cardano.CLI.Types.Errors.DelegationError import Cardano.CLI.Types.Errors.StakeAddressRegistrationError import Cardano.CLI.Types.Key @@ -52,6 +53,8 @@ runStakeAddressCmds = \case runStakeAddressRegistrationCertificateCmd sbe stakeIdentifier mDeposit outputFp StakeAddressStakeDelegationCertificateCmd sbe stakeIdentifier stkPoolVerKeyHashOrFp outputFp -> runStakeAddressStakeDelegationCertificateCmd sbe stakeIdentifier stkPoolVerKeyHashOrFp outputFp + StakeAddressStakeAndVoteDelegationCertificateCmd w stakeIdentifier stakePoolVerificationKeyHashSource drepVerificationKeyHashSource outputFp -> + runStakeAddressStakeAndVoteDelegationCertificateCmd w stakeIdentifier stakePoolVerificationKeyHashSource drepVerificationKeyHashSource outputFp StakeAddressDeregistrationCertificateCmd sbe stakeIdentifier mDeposit outputFp -> runStakeAddressDeregistrationCertificateCmd sbe stakeIdentifier mDeposit outputFp @@ -201,6 +204,46 @@ caseShelleyToBabbageAndConwayEraOnwards l r = \case ShelleyBasedEraBabbage -> l ShelleyToBabbageEraBabbage ShelleyBasedEraConway -> r ConwayEraOnwardsConway +runStakeAddressStakeAndVoteDelegationCertificateCmd :: () + => ConwayEraOnwards era + -> StakeIdentifier + -- ^ Delegator stake verification key, verification key file or script file. + -> VerificationKeyOrHashOrFile StakePoolKey + -- ^ Delegatee stake pool verification key or verification key file or + -> VerificationKeyOrHashOrFile DRepKey + -- verification key hash. + -> File () Out + -> ExceptT ShelleyStakeAddressCmdError IO () +runStakeAddressStakeAndVoteDelegationCertificateCmd w stakeVerifier poolVKeyOrHashOrFile drepVKeyOrHashOrFile outFp = + conwayEraOnwardsConstraints w $ do + StakePoolKeyHash poolStakeVKeyHash <- + lift (readVerificationKeyOrHashOrFile AsStakePoolKey poolVKeyOrHashOrFile) + & onLeft (left . ShelleyStakeAddressCmdReadKeyFileError) + + stakeCredential <- + getStakeCredentialFromIdentifier stakeVerifier + & firstExceptT ShelleyStakeAddressCmdStakeCredentialError + + DRepKeyHash drepKeyHash <- + lift (readVerificationKeyOrHashOrTextEnvFile AsDRepKey drepVKeyOrHashOrFile) + & onLeft (left . StakeAddressDelegationError . DelegationDRepReadError) + + let drepCred = Ledger.DRepCredential $ Ledger.KeyHashObj drepKeyHash + + let delegatee = + Ledger.DelegStakeVote + (conwayEraOnwardsConstraints w poolStakeVKeyHash) + (conwayEraOnwardsConstraints w drepCred) + + let certificate = + ConwayCertificate w + $ Ledger.mkDelegTxCert (toShelleyStakeCredential stakeCredential) delegatee + + firstExceptT ShelleyStakeAddressCmdWriteFileError + . newExceptT + $ writeLazyByteStringFile outFp + $ textEnvelopeToJSON (Just @TextEnvelopeDescr "Stake Address Delegation Certificate") certificate + createStakeDelegationCertificate :: forall era. () => StakeCredential -> Hash StakePoolKey diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/ShelleyStakeAddressCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/ShelleyStakeAddressCmdError.hs index 1668f0c4f4..1450448df3 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/ShelleyStakeAddressCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/ShelleyStakeAddressCmdError.hs @@ -9,12 +9,14 @@ import Cardano.Api import Cardano.CLI.Types.Errors.ScriptDecodeError import Cardano.CLI.Types.Errors.StakeAddressRegistrationError import Cardano.CLI.Types.Errors.StakeCredentialError +import Cardano.CLI.Types.Errors.DelegationError data ShelleyStakeAddressCmdError = ShelleyStakeAddressCmdReadKeyFileError !(FileError InputDecodeError) | ShelleyStakeAddressCmdReadScriptFileError !(FileError ScriptDecodeError) | ShelleyStakeAddressCmdStakeCredentialError !StakeCredentialError | ShelleyStakeAddressCmdWriteFileError !(FileError ()) + | StakeAddressDelegationError !DelegationError | StakeRegistrationError !StakeAddressRegistrationError deriving Show @@ -24,4 +26,5 @@ instance Error ShelleyStakeAddressCmdError where ShelleyStakeAddressCmdReadScriptFileError e -> displayError e ShelleyStakeAddressCmdStakeCredentialError e -> displayError e ShelleyStakeAddressCmdWriteFileError e -> displayError e + StakeAddressDelegationError e -> displayError e StakeRegistrationError e -> displayError e diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index 4ca6bcedf2..3ce23c1592 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -3627,6 +3627,7 @@ Usage: cardano-cli conway stake-address | registration-certificate | deregistration-certificate | stake-delegation-certificate + | stake-and-vote-delegation-certificate ) Stake address commands. @@ -3694,6 +3695,25 @@ Usage: cardano-cli conway stake-address stake-delegation-certificate Create a stake address stake delegation certificate, which when submitted in a transaction delegates stake to a stake pool. +Usage: cardano-cli conway stake-address stake-and-vote-delegation-certificate + ( --stake-verification-key STRING + | --stake-verification-key-file FILE + | --stake-script-file FILE + | --stake-address ADDRESS + ) + ( --stake-pool-verification-key STRING + | --cold-verification-key-file FILE + | --stake-pool-id STAKE_POOL_ID + ) + ( --drep-verification-key STRING + | --drep-verification-key-file FILE + | --drep-key-hash HASH + ) + --out-file FILE + + Create a stake address stake and vote delegation certificate, which when + submitted in a transaction delegates stake to a stake pool and a DRep. + Usage: cardano-cli conway transaction ( build-raw | build diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address.cli index be71afae46..2dfc30ca72 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address.cli @@ -5,6 +5,7 @@ Usage: cardano-cli conway stake-address | registration-certificate | deregistration-certificate | stake-delegation-certificate + | stake-and-vote-delegation-certificate ) Stake address commands. @@ -23,3 +24,7 @@ Available commands: Create a stake address stake delegation certificate, which when submitted in a transaction delegates stake to a stake pool. + stake-and-vote-delegation-certificate + Create a stake address stake and vote delegation + certificate, which when submitted in a transaction + delegates stake to a stake pool and a DRep. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_stake-and-vote-delegation-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_stake-and-vote-delegation-certificate.cli new file mode 100644 index 0000000000..685393d107 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_stake-and-vote-delegation-certificate.cli @@ -0,0 +1,43 @@ +Usage: cardano-cli conway stake-address stake-and-vote-delegation-certificate + ( --stake-verification-key STRING + | --stake-verification-key-file FILE + | --stake-script-file FILE + | --stake-address ADDRESS + ) + ( --stake-pool-verification-key STRING + | --cold-verification-key-file FILE + | --stake-pool-id STAKE_POOL_ID + ) + ( --drep-verification-key STRING + | --drep-verification-key-file FILE + | --drep-key-hash HASH + ) + --out-file FILE + + Create a stake address stake and vote delegation certificate, which when + submitted in a transaction delegates stake to a stake pool and a DRep. + +Available options: + --stake-verification-key STRING + Stake verification key (Bech32 or hex-encoded). + --stake-verification-key-file FILE + Filepath of the staking verification key. + --stake-script-file FILE Filepath of the staking script. + --stake-address ADDRESS Target stake address (bech32 format). + --stake-pool-verification-key STRING + Stake pool verification key (Bech32 or hex-encoded). + --cold-verification-key-file FILE + Filepath of the stake pool verification key. + --stake-pool-id STAKE_POOL_ID + Stake pool ID/verification key hash (either + Bech32-encoded or hex-encoded). Zero or more + occurences of this option is allowed. + --drep-verification-key STRING + DRep verification key (Bech32 or hex-encoded). + --drep-verification-key-file FILE + Filepath of the DRep verification key. + --drep-key-hash HASH DRep verification key hash (either Bech32-encoded or + hex-encoded). Zero or more occurences of this option + is allowed. + --out-file FILE The output file. + -h,--help Show this help text