Skip to content

Commit

Permalink
Delete governance drep delegation-certificate command
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Sep 12, 2023
1 parent 3ba523c commit 371e306
Show file tree
Hide file tree
Showing 18 changed files with 7 additions and 629 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import Cardano.CLI.Types.Key
import Data.Text (Text)

data GovernanceDRepCmds era
= GovernanceDRepDelegationCertificateCmd
StakeIdentifier
AnyDelegationTarget
(File () Out)
| GovernanceDRepGenerateKeyCmd
= GovernanceDRepGenerateKeyCmd
(ConwayEraOnwards era)
(File (VerificationKey ()) Out)
(File (SigningKey ()) Out)
Expand All @@ -35,8 +31,6 @@ renderGovernanceDRepCmds :: ()
=> GovernanceDRepCmds era
-> Text
renderGovernanceDRepCmds = \case
GovernanceDRepDelegationCertificateCmd {} ->
"governance drep delegation-certificate"
GovernanceDRepGenerateKeyCmd{} ->
"governance drep key-gen"
GovernanceDRepIdCmd {} ->
Expand Down
64 changes: 0 additions & 64 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pGovernanceDRepCmds envCli era =
)
[ pGovernanceDRepKeyGenCmd era
, pGovernanceDRepKeyIdCmd era
, pDelegationCertificateCmd envCli era
, pRegistrationCertificateCmd envCli era
]

Expand Down Expand Up @@ -133,66 +132,3 @@ instance FeatureInEra AnyEraDecider where
AlonzoEra -> yes $ AnyEraDeciderShelleyToBabbage ShelleyToBabbageEraAlonzo
BabbageEra -> yes $ AnyEraDeciderShelleyToBabbage ShelleyToBabbageEraBabbage
ConwayEra -> yes $ AnyEraDeciderConwayOnwards ConwayEraOnwardsConway

-- Delegation Certificate related

pDelegationCertificateCmd :: ()
=> EnvCli
-> CardanoEra era
-> Maybe (Parser (GovernanceDRepCmds era))
pDelegationCertificateCmd _envCli era = do
w <- maybeFeatureInEra era
pure
$ subParser "delegation-certificate"
$ Opt.info (pCmd w)
$ Opt.progDesc "Delegation certificate creation."
where
pCmd :: AnyEraDecider era -> Parser (GovernanceDRepCmds era)
pCmd w =
GovernanceDRepDelegationCertificateCmd
<$> pStakeIdentifier
<*> pAnyDelegationCertificateTarget w
<*> pOutputFile

pAnyDelegationCertificateTarget :: ()
=> AnyEraDecider era
-> Parser AnyDelegationTarget
pAnyDelegationCertificateTarget e =
case e of
AnyEraDeciderShelleyToBabbage sbe ->
ShelleyToBabbageDelegTarget sbe
<$> pStakePoolVerificationKeyOrHashOrFile
AnyEraDeciderConwayOnwards cOnwards ->
ConwayOnwardDelegTarget cOnwards
<$> pStakeTarget cOnwards

-- TODO: Conway era AFTER sancho net. We probably want to
-- differentiate between delegating voting stake and reward stake
pStakeTarget :: ConwayEraOnwards era -> Parser (StakeTarget era)
pStakeTarget cOnwards =
asum
[ TargetVotingDrepAndStakePool cOnwards
<$> pCombinedDRepVerificationKeyOrHashOrFile
<*> pCombinedStakePoolVerificationKeyOrHashOrFile

, TargetStakePool cOnwards <$> pStakePoolVerificationKeyOrHashOrFile

, TargetVotingDrep cOnwards <$> pDRepVerificationKeyOrHashOrFile
, TargetVotingDRepScriptHash cOnwards <$> pDRepScriptHash
, TargetAlwaysAbstain cOnwards <$ pAlwaysAbstain

, TargetAlwaysNoConfidence cOnwards <$ pAlwaysNoConfidence
]

pDRepScriptHash :: Parser ScriptHash
pDRepScriptHash =
Opt.option scriptHashReader $ mconcat
[ Opt.long "drep-script-hash"
, Opt.metavar "HASH"
, Opt.help $ mconcat
[ "DRep script hash (hex-encoded). "
]
]

scriptHashReader :: Opt.ReadM ScriptHash
scriptHashReader = Opt.eitherReader $ Right . fromString
84 changes: 0 additions & 84 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Cardano.CLI.EraBased.Run.Governance
import Cardano.CLI.Read
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Errors.CmdError
import Cardano.CLI.Types.Errors.DelegationError
import Cardano.CLI.Types.Errors.GovernanceCmdError
import Cardano.CLI.Types.Errors.RegistrationError
import Cardano.CLI.Types.Key
Expand All @@ -35,10 +34,6 @@ runGovernanceDRepCmds :: ()
=> GovernanceDRepCmds era
-> ExceptT CmdError IO ()
runGovernanceDRepCmds = \case
GovernanceDRepDelegationCertificateCmd stakeIdentifier delegationTarget outFp ->
runGovernanceDelegationCertificateCmd stakeIdentifier delegationTarget outFp
& firstExceptT CmdEraDelegationError

GovernanceDRepGenerateKeyCmd w vrf sgn ->
runGovernanceDRepKeyGen w vrf sgn
& firstExceptT CmdGovernanceCmdError
Expand All @@ -51,85 +46,6 @@ runGovernanceDRepCmds = \case
runGovernanceRegistrationCertificateCmd regTarget outFp
& firstExceptT CmdRegistrationError

runGovernanceDelegationCertificateCmd
:: StakeIdentifier
-> AnyDelegationTarget
-> File () Out
-> ExceptT DelegationError IO ()
runGovernanceDelegationCertificateCmd stakeIdentifier delegationTarget outFp = do
stakeCred <-
getStakeCredentialFromIdentifier stakeIdentifier
& firstExceptT DelegationStakeCredentialError

case delegationTarget of
ShelleyToBabbageDelegTarget sTob stakePool -> do
poolId <- lift (readVerificationKeyOrHashOrFile AsStakePoolKey stakePool)
& onLeft (left . DelegationReadError)
let req = StakeDelegationRequirementsPreConway sTob stakeCred poolId
delegCert = makeStakeAddressDelegationCertificate req
description = Just @TextEnvelopeDescr "Stake Address Delegation Certificate"
firstExceptT DelegationCertificateWriteFileError
. newExceptT
$ writeLazyByteStringFile outFp
$ shelleyToBabbageEraConstraints sTob
$ textEnvelopeToJSON description delegCert

ConwayOnwardDelegTarget cOnwards target -> do
delegatee <- toLedgerDelegatee target
let req = StakeDelegationRequirementsConwayOnwards cOnwards stakeCred delegatee
delegCert = makeStakeAddressDelegationCertificate req
description = Just $ toDelegateeEnvelope delegatee
firstExceptT DelegationCertificateWriteFileError
. newExceptT
$ writeLazyByteStringFile outFp
$ conwayEraOnwardsConstraints cOnwards
$ textEnvelopeToJSON description delegCert

toLedgerDelegatee
:: StakeTarget era
-> ExceptT DelegationError IO (Ledger.Delegatee (Ledger.EraCrypto (ShelleyLedgerEra era)))
toLedgerDelegatee t =
case t of
TargetStakePool cOnwards keyOrHashOrFile -> do
StakePoolKeyHash kHash
<- lift (readVerificationKeyOrHashOrFile AsStakePoolKey keyOrHashOrFile)
& onLeft (left . DelegationReadError)
right $ Ledger.DelegStake $ conwayEraOnwardsConstraints cOnwards kHash

TargetVotingDrep cOnwards keyOrHashOrFile -> do
DRepKeyHash drepKeyHash <- firstExceptT DelegationDRepReadError
. newExceptT
$ readVerificationKeyOrHashOrTextEnvFile AsDRepKey keyOrHashOrFile
let drepCred = Ledger.DRepCredential $ Ledger.KeyHashObj drepKeyHash
right $ Ledger.DelegVote $ conwayEraOnwardsConstraints cOnwards drepCred

TargetVotingDrepAndStakePool cOnwards drepKeyOrHashOrFile poolKeyOrHashOrFile -> do
StakePoolKeyHash kHash
<- lift (readVerificationKeyOrHashOrFile AsStakePoolKey poolKeyOrHashOrFile)
& onLeft (left . DelegationReadError)
DRepKeyHash drepKeyHash
<- firstExceptT DelegationDRepReadError
. newExceptT
$ readVerificationKeyOrHashOrTextEnvFile AsDRepKey drepKeyOrHashOrFile
let drepCred = Ledger.DRepCredential $ Ledger.KeyHashObj drepKeyHash
right $ Ledger.DelegStakeVote
(conwayEraOnwardsConstraints cOnwards kHash)
(conwayEraOnwardsConstraints cOnwards drepCred)

TargetAlwaysAbstain{}-> right $ Ledger.DelegVote Ledger.DRepAlwaysAbstain

TargetAlwaysNoConfidence{} -> right $ Ledger.DelegVote Ledger.DRepAlwaysNoConfidence

TargetVotingDRepScriptHash cOn (ScriptHash scriptHash) ->
conwayEraOnwardsConstraints cOn $
right $ Ledger.DelegVote $ Ledger.DRepCredential $ Ledger.ScriptHashObj scriptHash

toDelegateeEnvelope :: Ledger.Delegatee ledgerera -> TextEnvelopeDescr
toDelegateeEnvelope = \case
Ledger.DelegStake{} -> "Stake Delegation Certificate"
Ledger.DelegVote{} -> "Vote Delegation Certificate"
Ledger.DelegStakeVote{} -> "Stake and Vote Delegation Certificate"

runGovernanceDRepIdCmd :: ()
=> ConwayEraOnwards era
-> VerificationKeyOrFile DRepKey
Expand Down
Loading

0 comments on commit 371e306

Please sign in to comment.