Skip to content

Commit

Permalink
Remove usage of stake pool keys as credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Nov 3, 2023
1 parent 38c9583 commit 6302a7e
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ module Cardano.CLI.EraBased.Commands.Governance.Actions
, UpdateProtocolParametersConwayOnwards(..)
, UpdateProtocolParametersPreConway(..)
, renderGovernanceActionCmds

, AnyStakeIdentifier(..)
) where

import Cardano.Api
Expand Down Expand Up @@ -47,7 +45,7 @@ data GoveranceActionUpdateCommitteeCmdArgs era
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, deposit :: !Lovelace
, returnAddress :: !AnyStakeIdentifier
, returnAddress :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
, oldCommitteeVkeySource :: ![VerificationKeyOrHashOrFile CommitteeColdKey]
Expand All @@ -62,7 +60,7 @@ data GovernanceActionCreateConstitutionCmdArgs era
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, deposit :: !Lovelace
, stakeCredential :: !AnyStakeIdentifier
, stakeCredential :: !(VerificationKeyOrHashOrFile StakeKey)
, mPrevGovernanceActionId :: !(Maybe (TxId, Word32))
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
Expand All @@ -77,7 +75,7 @@ data GovernanceActionInfoCmdArgs era
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, deposit :: !Lovelace
, returnStakeAddress :: !AnyStakeIdentifier
, returnStakeAddress :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
, outFile :: !(File () Out)
Expand All @@ -88,7 +86,7 @@ data GovernanceActionCreateNoConfidenceCmdArgs era
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, deposit :: !Lovelace
, returnStakeAddress :: !AnyStakeIdentifier
, returnStakeAddress :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
, governanceActionId :: !TxId
Expand All @@ -110,10 +108,10 @@ data GovernanceActionTreasuryWithdrawalCmdArgs era
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, deposit :: !Lovelace
, returnAddr :: !AnyStakeIdentifier
, returnAddr :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
, treasuryWithdrawal :: ![(AnyStakeIdentifier, Lovelace)]
, treasuryWithdrawal :: ![(VerificationKeyOrHashOrFile StakeKey, Lovelace)]
, outFile :: !(File () Out)
} deriving Show

Expand All @@ -130,7 +128,7 @@ data UpdateProtocolParametersConwayOnwards era
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, deposit :: !Lovelace
, returnAddr :: !AnyStakeIdentifier
, returnAddr :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
, governanceActionId :: !(Maybe (TxId, Word32))
Expand Down Expand Up @@ -170,8 +168,3 @@ renderGovernanceActionCmds = ("governance action " <>) . \case

GovernanceActionViewCmd {} ->
"view"

data AnyStakeIdentifier
= AnyStakeKey (VerificationKeyOrHashOrFile StakeKey)
| AnyStakePoolKey (VerificationKeyOrHashOrFile StakePoolKey)
deriving Show
22 changes: 7 additions & 15 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pGovernanceActionNewInfoCmd era = do
Cmd.GovernanceActionInfoCmdArgs eon
<$> pNetwork
<*> pGovActionDeposit
<*> pAnyStakeIdentifier Nothing
<*> pStakeVerificationKeyOrHashOrFile Nothing
<*> pProposalUrl
<*> pProposalHashSource
<*> pFileOutDirection "out-file" "Path to action file to be used later on with build or build-raw "
Expand All @@ -88,7 +88,7 @@ pGovernanceActionNewConstitutionCmd era = do
Cmd.GovernanceActionCreateConstitutionCmdArgs eon
<$> pNetwork
<*> pGovActionDeposit
<*> pAnyStakeIdentifier Nothing
<*> pStakeVerificationKeyOrHashOrFile Nothing
<*> pPreviousGovernanceAction
<*> pProposalUrl
<*> pProposalHashSource
Expand Down Expand Up @@ -118,7 +118,7 @@ pUpdateCommitteeCmd eon =
Cmd.GoveranceActionUpdateCommitteeCmdArgs eon
<$> pNetwork
<*> pGovActionDeposit
<*> pAnyStakeIdentifier Nothing
<*> pStakeVerificationKeyOrHashOrFile Nothing
<*> pProposalUrl
<*> pProposalHashSource
<*> many pRemoveCommitteeColdVerificationKeyOrHashOrFile
Expand All @@ -143,7 +143,7 @@ pGovernanceActionNoConfidenceCmd era = do
Cmd.GovernanceActionCreateNoConfidenceCmdArgs eon
<$> pNetwork
<*> pGovActionDeposit
<*> pAnyStakeIdentifier Nothing
<*> pStakeVerificationKeyOrHashOrFile Nothing
<*> pProposalUrl
<*> pProposalHashSource
<*> pTxId "governance-action-tx-id" "Previous txid of `NoConfidence` or `NewCommittee` governance action."
Expand All @@ -152,14 +152,6 @@ pGovernanceActionNoConfidenceCmd era = do
)
$ Opt.progDesc "Create a no confidence proposal."

-- | The first argument is the optional prefix.
pAnyStakeIdentifier :: Maybe String -> Parser Cmd.AnyStakeIdentifier
pAnyStakeIdentifier prefix =
asum
[ Cmd.AnyStakePoolKey <$> pStakePoolVerificationKeyOrHashOrFile prefix
, Cmd.AnyStakeKey <$> pStakeVerificationKeyOrHashOrFile prefix
]

pUpdateProtocolParametersPreConway :: ShelleyToBabbageEra era -> Parser (Cmd.UpdateProtocolParametersPreConway era)
pUpdateProtocolParametersPreConway shelleyToBab =
Cmd.UpdateProtocolParametersPreConway shelleyToBab
Expand All @@ -171,7 +163,7 @@ pUpdateProtocolParametersPostConway conwayOnwards =
Cmd.UpdateProtocolParametersConwayOnwards conwayOnwards
<$> pNetwork
<*> pGovActionDeposit
<*> pAnyStakeIdentifier Nothing
<*> pStakeVerificationKeyOrHashOrFile Nothing
<*> pProposalUrl
<*> pProposalHashSource
<*> pPreviousGovernanceAction
Expand Down Expand Up @@ -340,10 +332,10 @@ pGovernanceActionTreasuryWithdrawalCmd era = do
Cmd.GovernanceActionTreasuryWithdrawalCmdArgs eon
<$> pNetwork
<*> pGovActionDeposit
<*> pAnyStakeIdentifier (Just "deposit-return")
<*> pStakeVerificationKeyOrHashOrFile (Just "deposit-return")
<*> pProposalUrl
<*> pProposalHashSource
<*> many ((,) <$> pAnyStakeIdentifier (Just "funds-receiving") <*> pTransferAmt)
<*> many ((,) <$> pStakeVerificationKeyOrHashOrFile (Just "funds-receiving") <*> pTransferAmt)
<*> pFileOutDirection "out-file" "Output filepath of the treasury withdrawal."
)
$ Opt.progDesc "Create a treasury withdrawal."
Expand Down
38 changes: 7 additions & 31 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}

module Cardano.CLI.EraBased.Run.Governance.Actions
Expand All @@ -12,7 +11,6 @@ module Cardano.CLI.EraBased.Run.Governance.Actions
) where

import Cardano.Api
import Cardano.Api.Ledger (coerceKeyRole)
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley

Expand Down Expand Up @@ -302,18 +300,10 @@ runGovernanceActionCreateProtocolParametersUpdateCmd eraBasedPParams' = do
)
sbe


readStakeKeyHash :: AnyStakeIdentifier -> ExceptT GovernanceActionsError IO (Hash StakeKey)
readStakeKeyHash anyStake =
case anyStake of
AnyStakeKey stake ->
firstExceptT GovernanceActionsCmdReadFileError
. newExceptT $ readVerificationKeyOrHashOrFile AsStakeKey stake

AnyStakePoolKey stake -> do
StakePoolKeyHash t <- firstExceptT GovernanceActionsCmdReadFileError
. newExceptT $ readVerificationKeyOrHashOrFile AsStakePoolKey stake
return $ StakeKeyHash $ coerceKeyRole t
readStakeKeyHash :: VerificationKeyOrHashOrFile StakeKey -> ExceptT GovernanceActionsError IO (Hash StakeKey)
readStakeKeyHash stake =
firstExceptT GovernanceActionsCmdReadFileError
. newExceptT $ readVerificationKeyOrHashOrFile AsStakeKey stake

runGovernanceActionTreasuryWithdrawalCmd :: ()
=> GovernanceActionTreasuryWithdrawalCmdArgs era
Expand Down Expand Up @@ -341,10 +331,9 @@ runGovernanceActionTreasuryWithdrawalCmd

returnKeyHash <- readStakeKeyHash returnAddr

withdrawals <- sequence
[ (networkId, , ll) <$> stakeIdentifiertoCredential stakeIdentifier
| (stakeIdentifier,ll) <- treasuryWithdrawal
]
withdrawals <- forM treasuryWithdrawal $ \(verificationKeyOrHashOrFile, lovelace) -> do
stakeKeyHash <- readStakeKeyHash verificationKeyOrHashOrFile
pure (networkId, StakeCredentialByKey stakeKeyHash, lovelace)

let sbe = conwayEraOnwardsToShelleyBasedEra eon
treasuryWithdrawals = TreasuryWithdrawal withdrawals
Expand All @@ -353,16 +342,3 @@ runGovernanceActionTreasuryWithdrawalCmd
firstExceptT GovernanceActionsCmdWriteFileError . newExceptT
$ conwayEraOnwardsConstraints eon
$ writeFileTextEnvelope outFile Nothing proposal

stakeIdentifiertoCredential :: AnyStakeIdentifier -> ExceptT GovernanceActionsError IO StakeCredential
stakeIdentifiertoCredential anyStake =
case anyStake of
AnyStakeKey stake -> do
hash <- firstExceptT GovernanceActionsCmdReadFileError
. newExceptT $ readVerificationKeyOrHashOrFile AsStakeKey stake
return $ StakeCredentialByKey hash
AnyStakePoolKey stake -> do
StakePoolKeyHash t <- firstExceptT GovernanceActionsCmdReadFileError
. newExceptT $ readVerificationKeyOrHashOrFile AsStakePoolKey stake
-- TODO: Conway era - don't use coerceKeyRole
return . StakeCredentialByKey $ StakeKeyHash $ coerceKeyRole t
5 changes: 2 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ runGovernanceDRepRegistrationCertificateCmd
. newExceptT
$ readVerificationKeyOrHashOrFile AsDRepKey drepVkeyHashSource
let drepCred = Ledger.KeyHashObj $ conwayEraOnwardsConstraints w drepKeyHash
votingCredential = VotingCredential drepCred
req = DRepRegistrationRequirements w votingCredential deposit
req = DRepRegistrationRequirements w drepCred deposit
registrationCert = makeDrepRegistrationCertificate req mAnchor
description = Just @TextEnvelopeDescr "DRep Key Registration Certificate"

Expand All @@ -138,7 +137,7 @@ runGovernanceDRepRetirementCertificateCmd
DRepKeyHash drepKeyHash <- firstExceptT GovernanceCmdKeyReadError
. newExceptT
$ readVerificationKeyOrHashOrFile AsDRepKey vkeyHashSource
makeDrepUnregistrationCertificate (DRepUnregistrationRequirements w (VotingCredential $ KeyHashObj drepKeyHash) deposit)
makeDrepUnregistrationCertificate (DRepUnregistrationRequirements w (KeyHashObj drepKeyHash) deposit)
& writeFileTextEnvelope outFile (Just genKeyDelegCertDesc)
& firstExceptT GovernanceCmdTextEnvWriteError . newExceptT

Expand Down
40 changes: 12 additions & 28 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Vote.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import Cardano.CLI.Types.Errors.CmdError
import Cardano.CLI.Types.Errors.GovernanceVoteCmdError
import Cardano.CLI.Types.Governance
import Cardano.CLI.Types.Key
import Cardano.Ledger.Keys (coerceKeyRole)

import Control.Monad.Trans.Except
import Control.Monad.Trans.Except.Extra
import Data.Aeson.Encode.Pretty
import Data.Bifunctor
import Data.Function
import qualified Data.Yaml.Pretty as Yaml

Expand Down Expand Up @@ -62,39 +60,25 @@ runGovernanceVoteCreateCmd
let voteAnchor = Ledger.Anchor { Ledger.anchorUrl = url, Ledger.anchorDataHash = voteHash }
VotingProcedure votingProcedureWithoutAnchor = createVotingProcedure eon voteChoice Nothing
votingProcedureWithAnchor = VotingProcedure $ votingProcedureWithoutAnchor { Ledger.vProcAnchor = Ledger.SJust voteAnchor }
return votingProcedureWithAnchor
pure votingProcedureWithAnchor

shelleyBasedEraConstraints sbe $ do
case votingStakeCredentialSource of
voter <- firstExceptT GovernanceVoteCmdReadVerificationKeyError $ case votingStakeCredentialSource of
AnyDRepVerificationKeyOrHashOrFile stake -> do
DRepKeyHash h <- firstExceptT GovernanceVoteCmdReadVerificationKeyError
. newExceptT $ readVerificationKeyOrHashOrTextEnvFile AsDRepKey stake
let vStakeCred = StakeCredentialByKey . StakeKeyHash $ coerceKeyRole h

votingCred <- hoistEither $ first GovernanceVoteCmdCredentialDecodeError $ toVotingCredential eon vStakeCred
let voter = Ledger.DRepVoter (unVotingCredential votingCred)
govActIdentifier = createGovernanceActionId govActionTxId govActionIndex
votingProcedures = singletonVotingProcedures eon voter govActIdentifier (unVotingProcedure voteProcedure)
firstExceptT GovernanceVoteCmdWriteError . newExceptT $ writeFileTextEnvelope outFile Nothing votingProcedures
DRepKeyHash h <- newExceptT $ readVerificationKeyOrHashOrTextEnvFile AsDRepKey stake
pure $ Ledger.DRepVoter $ Ledger.KeyHashObj h

AnyStakePoolVerificationKeyOrHashOrFile stake -> do
h <- firstExceptT GovernanceVoteCmdReadVerificationKeyError
. newExceptT $ readVerificationKeyOrHashOrTextEnvFile AsStakePoolKey stake

let voter = Ledger.StakePoolVoter (unStakePoolKeyHash h)
govActIdentifier = createGovernanceActionId govActionTxId govActionIndex
votingProcedures = singletonVotingProcedures eon voter govActIdentifier (unVotingProcedure voteProcedure)
firstExceptT GovernanceVoteCmdWriteError . newExceptT $ writeFileTextEnvelope outFile Nothing votingProcedures
StakePoolKeyHash h <- newExceptT $ readVerificationKeyOrHashOrTextEnvFile AsStakePoolKey stake
pure $ Ledger.StakePoolVoter h

AnyCommitteeHotVerificationKeyOrHashOrFile stake -> do
CommitteeHotKeyHash h <- firstExceptT GovernanceVoteCmdReadVerificationKeyError
. newExceptT $ readVerificationKeyOrHashOrTextEnvFile AsCommitteeHotKey stake
let vStakeCred = StakeCredentialByKey . StakeKeyHash $ coerceKeyRole h
votingCred <- hoistEither $ first GovernanceVoteCmdCredentialDecodeError $ toVotingCredential eon vStakeCred
let voter = Ledger.CommitteeVoter (Ledger.coerceKeyRole (unVotingCredential votingCred)) -- TODO Conway - remove coerceKeyRole
govActIdentifier = createGovernanceActionId govActionTxId govActionIndex
votingProcedures = singletonVotingProcedures eon voter govActIdentifier (unVotingProcedure voteProcedure)
firstExceptT GovernanceVoteCmdWriteError . newExceptT $ writeFileTextEnvelope outFile Nothing votingProcedures
CommitteeHotKeyHash h <- newExceptT $ readVerificationKeyOrHashOrTextEnvFile AsCommitteeHotKey stake
pure $ Ledger.CommitteeVoter $ Ledger.KeyHashObj h

let govActIdentifier = createGovernanceActionId govActionTxId govActionIndex
votingProcedures = singletonVotingProcedures eon voter govActIdentifier (unVotingProcedure voteProcedure)
firstExceptT GovernanceVoteCmdWriteError . newExceptT $ writeFileTextEnvelope outFile Nothing votingProcedures

runGovernanceVoteViewCmd :: ()
=> Cmd.GovernanceVoteViewCmdArgs era
Expand Down
Loading

0 comments on commit 6302a7e

Please sign in to comment.