diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/StakeAddress.hs index a596fc6028..e98d32973a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/StakeAddress.hs @@ -50,7 +50,7 @@ data StakeAddressCmds era | StakeAddressVoteDelegationCertificateCmd (ConwayEraOnwards era) StakeIdentifier - (VerificationKeyOrHashOrFile DRepKey) + VoteDelegationTarget (File () Out) | StakeAddressDeregistrationCertificateCmd (ShelleyBasedEra era) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs index 27848d5a78..a6ba055980 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs @@ -160,7 +160,7 @@ pStakeAddressVoteDelegationCertificateCmd era = do $ Opt.info ( StakeAddressVoteDelegationCertificateCmd w <$> pStakeIdentifier - <*> pDRepVerificationKeyOrHashOrFile + <*> pVoteDelegationTarget <*> pOutputFile ) $ Opt.progDesc diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs index 532bbc43ea..2dc13d7df0 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs @@ -25,7 +25,6 @@ import Cardano.Api.Shelley import Cardano.CLI.EraBased.Commands.StakeAddress import Cardano.CLI.Read import Cardano.CLI.Types.Common -import Cardano.CLI.Types.Errors.DelegationError import Cardano.CLI.Types.Errors.StakeAddressCmdError import Cardano.CLI.Types.Errors.StakeAddressRegistrationError import Cardano.CLI.Types.Governance @@ -54,10 +53,10 @@ 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 - StakeAddressVoteDelegationCertificateCmd w stakeIdentifier drepVerificationKeyHashSource outputFp -> - runStakeAddressVoteDelegationCertificateCmd w stakeIdentifier drepVerificationKeyHashSource outputFp + StakeAddressStakeAndVoteDelegationCertificateCmd w stakeIdentifier stakePoolVerificationKeyHashSource voteDelegationTarget outputFp -> + runStakeAddressStakeAndVoteDelegationCertificateCmd w stakeIdentifier stakePoolVerificationKeyHashSource voteDelegationTarget outputFp + StakeAddressVoteDelegationCertificateCmd w stakeIdentifier voteDelegationTarget outputFp -> + runStakeAddressVoteDelegationCertificateCmd w stakeIdentifier voteDelegationTarget outputFp StakeAddressDeregistrationCertificateCmd sbe stakeIdentifier mDeposit outputFp -> runStakeAddressDeregistrationCertificateCmd sbe stakeIdentifier mDeposit outputFp @@ -227,21 +226,9 @@ runStakeAddressStakeAndVoteDelegationCertificateCmd w stakeVerifier poolVKeyOrHa getStakeCredentialFromIdentifier stakeVerifier & firstExceptT StakeAddressCmdStakeCredentialError - drep <- case voteDelegationTarget of - VoteDelegationTargetOfDRep drepHashSource -> do - drepHash <- case drepHashSource of - DRepHashSourceScript (ScriptHash scriptHash) -> - pure $ Ledger.ScriptHashObj scriptHash - DRepHashSourceVerificationKey drepVKeyOrHashOrFile -> do - DRepKeyHash drepKeyHash <- - lift (readVerificationKeyOrHashOrTextEnvFile AsDRepKey drepVKeyOrHashOrFile) - & onLeft (left . StakeAddressCmdDelegationError . DelegationDRepReadError) - pure $ Ledger.KeyHashObj drepKeyHash - pure $ Ledger.DRepCredential drepHash - VoteDelegationTargetOfAbstain -> - pure Ledger.DRepAlwaysAbstain - VoteDelegationTargetOfNoConfidence -> - pure Ledger.DRepAlwaysNoConfidence + drep <- + readVoteDelegationTarget voteDelegationTarget + & firstExceptT StakeAddressCmdDelegationError let delegatee = Ledger.DelegStakeVote poolStakeVKeyHash drep @@ -257,23 +244,22 @@ runStakeAddressStakeAndVoteDelegationCertificateCmd w stakeVerifier poolVKeyOrHa runStakeAddressVoteDelegationCertificateCmd :: () => ConwayEraOnwards era -> StakeIdentifier - -- ^ Delegator stake verification key, verification key file or script file. - -> VerificationKeyOrHashOrFile DRepKey + -- ^ Delegatee stake pool verification key or verification key file or + -> VoteDelegationTarget -- ^ Delegatee stake pool verification key or verification key file or verification key hash. -> File () Out -> ExceptT StakeAddressCmdError IO () -runStakeAddressVoteDelegationCertificateCmd w stakeVerifier drepVKeyOrHashOrFile outFp = +runStakeAddressVoteDelegationCertificateCmd w stakeVerifier voteDelegationTarget outFp = conwayEraOnwardsConstraints w $ do stakeCredential <- getStakeCredentialFromIdentifier stakeVerifier & firstExceptT StakeAddressCmdStakeCredentialError - DRepKeyHash drepKeyHash <- - lift (readVerificationKeyOrHashOrTextEnvFile AsDRepKey drepVKeyOrHashOrFile) - & onLeft (left . StakeAddressCmdDelegationError . DelegationDRepReadError) + drep <- + readVoteDelegationTarget voteDelegationTarget + & firstExceptT StakeAddressCmdDelegationError - let drepCred = Ledger.DRepCredential $ Ledger.KeyHashObj drepKeyHash - let delegatee = Ledger.DelegVote (conwayEraOnwardsConstraints w drepCred) + let delegatee = Ledger.DelegVote drep let certificate = ConwayCertificate w diff --git a/cardano-cli/src/Cardano/CLI/Read.hs b/cardano-cli/src/Cardano/CLI/Read.hs index ad783d1732..0ecbf8974d 100644 --- a/cardano-cli/src/Cardano/CLI/Read.hs +++ b/cardano-cli/src/Cardano/CLI/Read.hs @@ -83,13 +83,17 @@ module Cardano.CLI.Read , readSafeHash , scriptHashReader + + , readVoteDelegationTarget ) where import Cardano.Api as Api +import qualified Cardano.Api.Ledger as L import Cardano.Api.Shelley as Api import qualified Cardano.Binary as CBOR import Cardano.CLI.Types.Common +import Cardano.CLI.Types.Errors.DelegationError import Cardano.CLI.Types.Errors.ScriptDecodeError import Cardano.CLI.Types.Errors.StakeCredentialError import Cardano.CLI.Types.Governance @@ -110,6 +114,7 @@ import Prelude import Control.Exception (bracket) import Control.Monad (forM, unless) import Control.Monad.IO.Class +import Control.Monad.Trans (MonadTrans (..)) import Control.Monad.Trans.Except import Control.Monad.Trans.Except.Extra import qualified Data.Aeson as Aeson @@ -1034,3 +1039,23 @@ readSafeHash = scriptHashReader :: Opt.ReadM ScriptHash scriptHashReader = Opt.eitherReader $ Right . fromString + +readVoteDelegationTarget :: () + => VoteDelegationTarget + -> ExceptT DelegationError IO (L.DRep Ledger.StandardCrypto) +readVoteDelegationTarget voteDelegationTarget = + case voteDelegationTarget of + VoteDelegationTargetOfDRep drepHashSource -> do + drepHash <- case drepHashSource of + DRepHashSourceScript (ScriptHash scriptHash) -> + pure $ Ledger.ScriptHashObj scriptHash + DRepHashSourceVerificationKey drepVKeyOrHashOrFile -> do + DRepKeyHash drepKeyHash <- + lift (readVerificationKeyOrHashOrTextEnvFile AsDRepKey drepVKeyOrHashOrFile) + & onLeft (left . DelegationDRepReadError) + pure $ Ledger.KeyHashObj drepKeyHash + pure $ L.DRepCredential drepHash + VoteDelegationTargetOfAbstain -> + pure L.DRepAlwaysAbstain + VoteDelegationTargetOfNoConfidence -> + pure L.DRepAlwaysNoConfidence 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 c07b6a434d..329cbcd869 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -6847,9 +6847,12 @@ Usage: cardano-cli conway stake-address vote-delegation-certificate | --stake-script-file FILE | --stake-address ADDRESS ) - ( --drep-verification-key STRING + ( --drep-script-hash HASH + | --drep-verification-key STRING | --drep-verification-key-file FILE | --drep-key-hash HASH + | --always-abstain + | --always-no-confidence ) --out-file FILE diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli index 5490ba3938..af481af0d9 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli @@ -4,9 +4,12 @@ Usage: cardano-cli conway stake-address vote-delegation-certificate | --stake-script-file FILE | --stake-address ADDRESS ) - ( --drep-verification-key STRING + ( --drep-script-hash HASH + | --drep-verification-key STRING | --drep-verification-key-file FILE | --drep-key-hash HASH + | --always-abstain + | --always-no-confidence ) --out-file FILE @@ -20,6 +23,7 @@ Available options: Filepath of the staking verification key. --stake-script-file FILE Filepath of the staking script. --stake-address ADDRESS Target stake address (bech32 format). + --drep-script-hash HASH DRep script hash (hex-encoded). --drep-verification-key STRING DRep verification key (Bech32 or hex-encoded). --drep-verification-key-file FILE @@ -27,5 +31,7 @@ Available options: --drep-key-hash HASH DRep verification key hash (either Bech32-encoded or hex-encoded). Zero or more occurences of this option is allowed. + --always-abstain Abstain from voting on all proposals. + --always-no-confidence Always vote no confidence --out-file FILE The output file. -h,--help Show this help text