Skip to content

Commit

Permalink
Merge pull request #919 from IntersectMBO/cl/stakereganddeleg
Browse files Browse the repository at this point in the history
Cl/stakereganddeleg
  • Loading branch information
CarlosLopezDeLara authored Oct 1, 2024
2 parents e4e1d1b + 3171dc2 commit 7ede09f
Show file tree
Hide file tree
Showing 13 changed files with 480 additions and 0 deletions.
14 changes: 14 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,18 @@ data StakeAddressCmds era
StakeIdentifier
(Maybe Coin)
(File () Out)
| StakeAddressRegistrationAndDelegationCertificateCmd
(ConwayEraOnwards era)
StakeIdentifier
(VerificationKeyOrHashOrFile StakePoolKey)
Coin
(File () Out)
| StakeAddressRegistrationAndVoteDelegationCertificateCmd
(ConwayEraOnwards era)
StakeIdentifier
VoteDelegationTarget
Coin
(File () Out)
deriving Show

renderStakeAddressCmds :: StakeAddressCmds era -> Text
Expand All @@ -71,3 +83,5 @@ 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"
StakeAddressRegistrationAndVoteDelegationCertificateCmd{} -> "stake-address registration-and-vote-delegation-certificate"
44 changes: 44 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,8 @@ pStakeAddressCmds era envCli =
, pStakeAddressStakeDelegationCertificateCmd era
, pStakeAddressStakeAndVoteDelegationCertificateCmd era
, pStakeAddressVoteDelegationCertificateCmd era
, pStakeAddressRegistrationAndDelegationCertificateCmd era
, pStakeAddressRegistrationAndVoteDelegationCertificateCmd era
]

pStakeAddressKeyGenCmd
Expand Down Expand Up @@ -206,3 +208,45 @@ 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."
]

pStakeAddressRegistrationAndVoteDelegationCertificateCmd
:: ()
=> CardanoEra era
-> Maybe (Parser (StakeAddressCmds era))
pStakeAddressRegistrationAndVoteDelegationCertificateCmd era = do
w <- forEraMaybeEon era
pure
$ subParser "registration-and-vote-delegation-certificate"
$ Opt.info
( StakeAddressRegistrationAndVoteDelegationCertificateCmd w
<$> pStakeIdentifier Nothing
<*> pVoteDelegationTarget
<*> pKeyRegistDeposit
<*> pOutputFile
)
$ Opt.progDesc
$ mconcat
[ "Create a stake address registration and vote delegation certificate, which when submitted in a transaction "
, "registers a stake address and delegates votes to a DRep or pre-defined voting option."
]
84 changes: 84 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,30 @@ 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
StakeAddressRegistrationAndVoteDelegationCertificateCmd
w
stakeIdentifier
voteDelegationTarget
keydeposit
outFp ->
runStakeAddressRegistrationAndVoteDelegationCertificateCmd
w
stakeIdentifier
voteDelegationTarget
keydeposit
outFp

runStakeAddressKeyGenCmd
:: ()
Expand Down Expand Up @@ -325,3 +350,62 @@ 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 id
-> 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 delegatee = L.DelegStake poolStakeVKeyHash

let certificate = makeStakeAddressAndDRepDelegationCertificate w stakeCred delegatee deposit

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

runStakeAddressRegistrationAndVoteDelegationCertificateCmd
:: ()
=> ConwayEraOnwards era
-> StakeIdentifier
-> VoteDelegationTarget
-> Lovelace
-> File () Out
-> ExceptT StakeAddressCmdError IO ()
runStakeAddressRegistrationAndVoteDelegationCertificateCmd w stakeVerifier voteDelegationTarget keydeposit outFp =
conwayEraOnwardsConstraints w $ do
stakeCred <-
getStakeCredentialFromIdentifier stakeVerifier
& firstExceptT StakeAddressCmdStakeCredentialError

drep <-
readVoteDelegationTarget voteDelegationTarget
& firstExceptT StakeAddressCmdDelegationError

let deleg = L.DelegVote drep

let certificate = makeStakeAddressAndDRepDelegationCertificate w stakeCred deleg keydeposit

firstExceptT StakeAddressCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile outFp
$ textEnvelopeToJSON
(Just @TextEnvelopeDescr "Stake address registration and vote delegation certificate")
certificate
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,61 @@ hprop_golden_conway_stakeaddress_delegate_pool_and_drep =
]

H.diffFileVsGoldenFile delegFile delegGold

-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden conway stakeaddress register and delegate pool/"'@
hprop_golden_conway_stakeaddress_register_and_delegate_pool :: Property
hprop_golden_conway_stakeaddress_register_and_delegate_pool =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
vkeyFile <- noteInputFile "test/cardano-cli-golden/files/input/conway/stake.vkey"
vkeyPool <- noteInputFile "test/cardano-cli-golden/files/input/conway/poolCold.vkey"
certFile <- H.noteTempFile tempDir "cert"
certGold <-
H.note
"test/cardano-cli-golden/files/golden/governance/stakeaddress/registerAddressDelegateToPool.cert"

void $
execCardanoCLI
[ "conway"
, "stake-address"
, "registration-and-delegation-certificate"
, "--stake-verification-key-file"
, vkeyFile
, "--cold-verification-key-file"
, vkeyPool
, "--key-reg-deposit-amt"
, "2000000"
, "--out-file"
, certFile
]

H.diffFileVsGoldenFile certFile certGold

-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden conway stakeaddress register and delegate vote/"'@
hprop_golden_conway_stakeaddress_register_and_delegate_vote :: Property
hprop_golden_conway_stakeaddress_register_and_delegate_vote =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
vkeyFile <- noteInputFile "test/cardano-cli-golden/files/input/conway/stake.vkey"
vkeyDrepFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/drep/drep.vkey"
certFile <- H.noteTempFile tempDir "cert"
certGold <-
H.note
"test/cardano-cli-golden/files/golden/governance/stakeaddress/registerAddressDelegateToDrep.cert"

void $
execCardanoCLI
[ "conway"
, "stake-address"
, "registration-and-vote-delegation-certificate"
, "--stake-verification-key-file"
, vkeyFile
, "--drep-verification-key-file"
, vkeyDrepFile
, "--key-reg-deposit-amt"
, "2000000"
, "--out-file"
, certFile
]

H.diffFileVsGoldenFile certFile certGold
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "CertificateConway",
"description": "Stake address registration and vote delegation certificate",
"cborHex": "840c8200581cef1785cf18928f8353c90e76b7a8fc60855472d31a0ea1c1c774ab018200581ce68f9ee70599cb93d9f60678f9c6463c01938c27d9820c7bf93887a51a001e8480"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "CertificateConway",
"description": "Stake address registration and stake delegation certificate",
"cborHex": "840b8200581cef1785cf18928f8353c90e76b7a8fc60855472d31a0ea1c1c774ab01581cc27cf021914a2b3bcb286d3d741979083422378c577fe757702b69881a001e8480"
}
82 changes: 82 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 @@ -7307,6 +7307,8 @@ Usage: cardano-cli conway stake-address
| stake-delegation-certificate
| stake-and-vote-delegation-certificate
| vote-delegation-certificate
| registration-and-delegation-certificate
| registration-and-vote-delegation-certificate
)

Stake address commands.
Expand Down Expand Up @@ -7420,6 +7422,45 @@ Usage: cardano-cli conway stake-address vote-delegation-certificate
Create a stake address vote delegation certificate, which when submitted in a
transaction delegates stake to a DRep.

Usage: cardano-cli conway stake-address registration-and-delegation-certificate
( --stake-verification-key STRING
| --stake-verification-key-file FILEPATH
| --stake-key-hash HASH
| --stake-script-file FILEPATH
| --stake-address ADDRESS
)
( --stake-pool-verification-key STRING
| --cold-verification-key-file FILEPATH
| --stake-pool-id STAKE_POOL_ID
)
--key-reg-deposit-amt NATURAL
--out-file FILEPATH

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.

Usage: cardano-cli conway stake-address registration-and-vote-delegation-certificate
( --stake-verification-key STRING
| --stake-verification-key-file FILEPATH
| --stake-key-hash HASH
| --stake-script-file FILEPATH
| --stake-address ADDRESS
)
( --drep-script-hash HASH
| --drep-verification-key STRING
| --drep-verification-key-file FILEPATH
| --drep-key-hash HASH
| --always-abstain
| --always-no-confidence
)
--key-reg-deposit-amt NATURAL
--out-file FILEPATH

Create a stake address registration and vote delegation certificate, which
when submitted in a transaction registers a stake address and delegates votes
to a DRep or pre-defined voting option.

Usage: cardano-cli conway stake-pool
( registration-certificate
| deregistration-certificate
Expand Down Expand Up @@ -9239,6 +9280,8 @@ Usage: cardano-cli latest stake-address
| stake-delegation-certificate
| stake-and-vote-delegation-certificate
| vote-delegation-certificate
| registration-and-delegation-certificate
| registration-and-vote-delegation-certificate
)

Stake address commands.
Expand Down Expand Up @@ -9352,6 +9395,45 @@ Usage: cardano-cli latest stake-address vote-delegation-certificate
Create a stake address vote delegation certificate, which when submitted in a
transaction delegates stake to a DRep.

Usage: cardano-cli latest stake-address registration-and-delegation-certificate
( --stake-verification-key STRING
| --stake-verification-key-file FILEPATH
| --stake-key-hash HASH
| --stake-script-file FILEPATH
| --stake-address ADDRESS
)
( --stake-pool-verification-key STRING
| --cold-verification-key-file FILEPATH
| --stake-pool-id STAKE_POOL_ID
)
--key-reg-deposit-amt NATURAL
--out-file FILEPATH

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.

Usage: cardano-cli latest stake-address registration-and-vote-delegation-certificate
( --stake-verification-key STRING
| --stake-verification-key-file FILEPATH
| --stake-key-hash HASH
| --stake-script-file FILEPATH
| --stake-address ADDRESS
)
( --drep-script-hash HASH
| --drep-verification-key STRING
| --drep-verification-key-file FILEPATH
| --drep-key-hash HASH
| --always-abstain
| --always-no-confidence
)
--key-reg-deposit-amt NATURAL
--out-file FILEPATH

Create a stake address registration and vote delegation certificate, which
when submitted in a transaction registers a stake address and delegates votes
to a DRep or pre-defined voting option.

Usage: cardano-cli latest stake-pool
( registration-certificate
| deregistration-certificate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Usage: cardano-cli conway stake-address
| stake-delegation-certificate
| stake-and-vote-delegation-certificate
| vote-delegation-certificate
| registration-and-delegation-certificate
| registration-and-vote-delegation-certificate
)

Stake address commands.
Expand All @@ -33,3 +35,13 @@ Available commands:
Create a stake address vote delegation certificate,
which when submitted in a transaction delegates stake
to a DRep.
registration-and-delegation-certificate
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.
registration-and-vote-delegation-certificate
Create a stake address registration and vote
delegation certificate, which when submitted in a
transaction registers a stake address and delegates
votes to a DRep or pre-defined voting option.
Loading

0 comments on commit 7ede09f

Please sign in to comment.