Skip to content

Commit

Permalink
Merge pull request #257 from input-output-hk/newhoggy/new-stake-and-v…
Browse files Browse the repository at this point in the history
…ote-delegation-certificate-command

New `stake-address stake-and-vote-delegation-certificate` command
  • Loading branch information
newhoggy authored Sep 9, 2023
2 parents bad0fe8 + 8adeffd commit 8eb3fdb
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
21 changes: 21 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pStakeAddressCmds era envCli =
, pStakeAddressRegistrationCertificateCmd era
, pStakeAddressDeregistrationCertificateCmd era
, pStakeAddressStakeDelegationCertificateCmd era
, pStakeAddressStakeAndVoteDelegationCertificateCmd era
]

pStakeAddressKeyGenCmd :: ()
Expand Down Expand Up @@ -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."
]
43 changes: 43 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

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

Expand All @@ -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
20 changes: 20 additions & 0 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8eb3fdb

Please sign in to comment.