Skip to content

Commit

Permalink
implement stake_reg_deleg_cert certificate generation
Browse files Browse the repository at this point in the history
This certificate registers a stake address and delegates to a pool simultaneously:
From CDDL: stake_reg_deleg_cert = (11, stake_credential, pool_keyhash, coin)
  • Loading branch information
CarlosLopezDeLara committed Sep 30, 2024
1 parent e4e1d1b commit 004a37d
Show file tree
Hide file tree
Showing 3 changed files with 60 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 @@ -59,6 +59,12 @@ data StakeAddressCmds era
StakeIdentifier
(Maybe Coin)
(File () Out)
| StakeAddressRegistrationAndDelegationCertificateCmd
(ConwayEraOnwards era)
StakeIdentifier
(VerificationKeyOrHashOrFile StakePoolKey)
Coin
(File () Out)
deriving Show

renderStakeAddressCmds :: StakeAddressCmds era -> Text
Expand All @@ -71,3 +77,4 @@ renderStakeAddressCmds = \case
StakeAddressStakeAndVoteDelegationCertificateCmd{} -> "stake-address stake-and-vote-delegation-certificate"
StakeAddressStakeDelegationCertificateCmd{} -> "stake-address stake-delegation-certificate"
StakeAddressVoteDelegationCertificateCmd{} -> "stake-address vote-delegation-certificate"
StakeAddressRegistrationAndDelegationCertificateCmd{} -> "stake-address registration-and-stake-delegation-certificate"
22 changes: 22 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pStakeAddressCmds era envCli =
, pStakeAddressStakeDelegationCertificateCmd era
, pStakeAddressStakeAndVoteDelegationCertificateCmd era
, pStakeAddressVoteDelegationCertificateCmd era
, pStakeAddressRegistrationAndDelegationCertificateCmd era
]

pStakeAddressKeyGenCmd
Expand Down Expand Up @@ -206,3 +207,24 @@ pStakeAddressVoteDelegationCertificateCmd era = do
[ "Create a stake address vote delegation certificate, which when submitted in a transaction "
, "delegates stake to a DRep."
]

pStakeAddressRegistrationAndDelegationCertificateCmd
:: ()
=> CardanoEra era
-> Maybe (Parser (StakeAddressCmds era))
pStakeAddressRegistrationAndDelegationCertificateCmd era = do
w <- forEraMaybeEon era
pure
$ subParser "registration-and-delegation-certificate"
$ Opt.info
( StakeAddressRegistrationAndDelegationCertificateCmd w
<$> pStakeIdentifier Nothing
<*> pStakePoolVerificationKeyOrHashOrFile Nothing
<*> pKeyRegistDeposit
<*> pOutputFile
)
$ Opt.progDesc
$ mconcat
[ "Create a stake address registration and delegation certificate, which when submitted in a transaction "
, "registers a stake address and delegates stake to a stake pool."
]
31 changes: 31 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Cardano.CLI.EraBased.Run.StakeAddress
, runStakeAddressStakeDelegationCertificateCmd
, runStakeAddressDeregistrationCertificateCmd
, runStakeAddressRegistrationCertificateCmd
, runStakeAddressRegistrationAndDelegationCertificateCmd
)
where

Expand Down Expand Up @@ -67,6 +68,8 @@ runStakeAddressCmds = \case
runStakeAddressVoteDelegationCertificateCmd w stakeIdentifier voteDelegationTarget outputFp
StakeAddressDeregistrationCertificateCmd sbe stakeIdentifier mDeposit outputFp ->
runStakeAddressDeregistrationCertificateCmd sbe stakeIdentifier mDeposit outputFp
StakeAddressRegistrationAndDelegationCertificateCmd w stakeIdentifier poolVKeyOrHashOrFile deposit outFp ->
runStakeAddressRegistrationAndDelegationCertificateCmd w stakeIdentifier poolVKeyOrHashOrFile deposit outFp

runStakeAddressKeyGenCmd
:: ()
Expand Down Expand Up @@ -325,3 +328,31 @@ runStakeAddressDeregistrationCertificateCmd sbe stakeVerifier mDeposit oFp = do
where
deregCertDesc :: TextEnvelopeDescr
deregCertDesc = "Stake Address Deregistration Certificate"

runStakeAddressRegistrationAndDelegationCertificateCmd
:: ()
=> ConwayEraOnwards era
-> StakeIdentifier
-> VerificationKeyOrHashOrFile StakePoolKey
-- ^ Delegatee stake pool verification key or verification key file or
-> Lovelace
-> File () Out
-> ExceptT StakeAddressCmdError IO ()
runStakeAddressRegistrationAndDelegationCertificateCmd w stakeVerifier poolVKeyOrHashOrFile deposit outFp =
conwayEraOnwardsConstraints w $ do
StakePoolKeyHash poolStakeVKeyHash <-
modifyError StakeAddressCmdReadKeyFileError $
readVerificationKeyOrHashOrFile AsStakePoolKey poolVKeyOrHashOrFile

stakeCred <-
getStakeCredentialFromIdentifier stakeVerifier
& firstExceptT StakeAddressCmdStakeCredentialError

let deleg = L.DelegStake poolStakeVKeyHash

let certificate = makeStakeAddressAndDRepDelegationCertificate w stakeCred deleg deposit

firstExceptT StakeAddressCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile outFp
$ textEnvelopeToJSON (Just @TextEnvelopeDescr "Stake address registration and stake delegation certificate") certificate

0 comments on commit 004a37d

Please sign in to comment.