Skip to content

Commit

Permalink
Merge pull request #272 from input-output-hk/newhoggy/support-more-vo…
Browse files Browse the repository at this point in the history
…te-delegation-targets

Add support for `--drep-script-hash` `--always-abstain` `--always-no-confidence` to `vote-delegation-certificate` command
  • Loading branch information
newhoggy authored Sep 14, 2023
2 parents 095fc4a + 8bbf602 commit f02fe9c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data StakeAddressCmds era
| StakeAddressVoteDelegationCertificateCmd
(ConwayEraOnwards era)
StakeIdentifier
(VerificationKeyOrHashOrFile DRepKey)
VoteDelegationTarget
(File () Out)
| StakeAddressDeregistrationCertificateCmd
(ShelleyBasedEra era)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pStakeAddressVoteDelegationCertificateCmd era = do
$ Opt.info
( StakeAddressVoteDelegationCertificateCmd w
<$> pStakeIdentifier
<*> pDRepVerificationKeyOrHashOrFile
<*> pVoteDelegationTarget
<*> pOutputFile
)
$ Opt.progDesc
Expand Down
42 changes: 14 additions & 28 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions cardano-cli/src/Cardano/CLI/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -20,12 +23,15 @@ 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
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.
--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

0 comments on commit f02fe9c

Please sign in to comment.