Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update proposal governance action #152

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ library
Cardano.CLI.Environment
Cardano.CLI.EraBased.Commands
Cardano.CLI.EraBased.Commands.Governance
Cardano.CLI.EraBased.Commands.Governance.Actions
Cardano.CLI.EraBased.Commands.Governance.Committee
Cardano.CLI.EraBased.Governance
Cardano.CLI.EraBased.Legacy
Cardano.CLI.EraBased.Options.Common
Cardano.CLI.EraBased.Options.Governance
Cardano.CLI.EraBased.Options.Governance.Actions
Cardano.CLI.EraBased.Options.Governance.Committee
Cardano.CLI.EraBased.Run
Cardano.CLI.EraBased.Run.Certificate
Cardano.CLI.EraBased.Run.Governance
Cardano.CLI.EraBased.Run.Governance.Actions
Cardano.CLI.EraBased.Run.Governance.Committee
Cardano.CLI.EraBased.Vote
Cardano.CLI.Helpers
Expand Down
1 change: 1 addition & 0 deletions cardano-cli/src/Cardano/CLI/Commands/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Cardano.Api.Shelley
import Cardano.Binary (DecoderError)
import Cardano.CLI.Run.Legacy.Read (CddlError)
import Cardano.CLI.Run.Legacy.StakeAddress
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Governance
import Cardano.CLI.Types.Key
import Cardano.Prelude (intercalate, toS)
Expand Down
6 changes: 6 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module Cardano.CLI.EraBased.Commands.Governance

import Cardano.Api

import Cardano.CLI.EraBased.Commands.Governance.Actions (GovernanceActionCmds,
renderGovernanceActionCmds)
import Cardano.CLI.EraBased.Commands.Governance.Committee
import Cardano.CLI.EraBased.Vote
import Cardano.CLI.Types.Common
Expand Down Expand Up @@ -42,6 +44,8 @@ data EraBasedGovernanceCmds era
(File () Out)
| EraBasedGovernanceCommitteeCmds
(GovernanceCommitteeCmds era)
| EraBasedGovernanceActionCmds
(GovernanceActionCmds era)

renderEraBasedGovernanceCmds :: EraBasedGovernanceCmds era -> Text
renderEraBasedGovernanceCmds = \case
Expand All @@ -63,3 +67,5 @@ renderEraBasedGovernanceCmds = \case
"goverance vote"
EraBasedGovernanceCommitteeCmds cmds ->
renderGovernanceCommitteeCmds cmds
EraBasedGovernanceActionCmds cmds ->
renderGovernanceActionCmds cmds
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE StandaloneDeriving #-}

module Cardano.CLI.EraBased.Commands.Governance.Actions
( AnyStakeIdentifier(..)
, GovernanceActionCmds(..)
, EraBasedUpdateProposal(..)
, EraBasedNewConstitution(..)
, renderGovernanceActionCmds
) where

import Cardano.Api
import Cardano.Api.Shelley

import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key

import Data.Text (Text)

data GovernanceActionCmds era
= GovernanceActionCreateConstitution
(ConwayEraOnwards era)
EraBasedNewConstitution
| GovernanceActionCreateUpdateProposal
(ConwayEraOnwards era)
EraBasedUpdateProposal
deriving Show

data EraBasedNewConstitution
= EraBasedNewConstitution
{ encDeposit :: Lovelace
, encStakeCredential :: AnyStakeIdentifier
, encConstitution :: Constitution
, encFilePath :: File () Out
} deriving Show

renderGovernanceActionCmds :: GovernanceActionCmds era -> Text
renderGovernanceActionCmds = \case
GovernanceActionCreateConstitution {} ->
"governance action create-constitution"

GovernanceActionCreateUpdateProposal {} ->
"governance action create-update-proposal"

data AnyStakeIdentifier
= AnyStakeKey (VerificationKeyOrHashOrFile StakeKey)
| AnyStakePoolKey (VerificationKeyOrHashOrFile StakePoolKey)
deriving Show


data EraBasedUpdateProposal where
ConwayOnwardsUpdateProposal
:: ConwayEraOnwards era
-> ProtocolParametersUpdate
-> Lovelace -- ^ Deposit
-> AnyStakeIdentifier -- ^ Return address
-> Maybe (File () In) -- ^ Cost model file
-> File () Out
-> EraBasedUpdateProposal
-- TODO: Conway era - add constructor for pre-conway
-- update proposals. This will require genesis delegate keys
-- see UpdateProposal type in cardano-api.

deriving instance Show EraBasedUpdateProposal

20 changes: 0 additions & 20 deletions cardano-cli/src/Cardano/CLI/EraBased/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,3 @@ pCreateConstitution envCli =
<*> pVotingCredential
<*> pConstitution
<*> pFileOutDirection "out-file" "Output filepath of the governance action."

pConstitution :: Parser Constitution
pConstitution =
asum
[ fmap ConstitutionFromText $ Opt.strOption $ mconcat
[ Opt.long "constitution"
, Opt.metavar "TEXT"
, Opt.help "Input constitution as UTF-8 encoded text."
]
, ConstitutionFromFile
<$> pFileInDirection "constitution-file" "Input constitution as a text file."
]

pGovActionDeposit :: Parser Lovelace
pGovActionDeposit =
Opt.option (readerFromParsecParser parseLovelace) $ mconcat
[ Opt.long "governance-action-deposit"
, Opt.metavar "NATURAL"
, Opt.help "Deposit required to submit a governance action."
]
22 changes: 1 addition & 21 deletions cardano-cli/src/Cardano/CLI/EraBased/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Cardano.CLI.EraBased.Legacy

-- * Field parser and renderers
, parseTxIn

, pProtocolParametersUpdate
, pKeyRegistDeposit
, pStakePoolRegistrationParserRequirements
, pStakePoolVerificationKeyOrHashOrFile
Expand Down Expand Up @@ -2639,30 +2639,10 @@ pAddress =
, Opt.help "A Cardano address"
]


pStakePoolVerificationKeyHash :: Parser (Hash StakePoolKey)
pStakePoolVerificationKeyHash =
Opt.option (pBech32KeyHash AsStakePoolKey <|> pHexHash AsStakePoolKey) $ mconcat
[ Opt.long "stake-pool-id"
, Opt.metavar "STAKE_POOL_ID"
, Opt.help $ mconcat
[ "Stake pool ID/verification key hash (either Bech32-encoded or hex-encoded). "
, "Zero or more occurences of this option is allowed."
]
]

pDelegationTarget
:: Parser DelegationTarget
pDelegationTarget = StakePoolDelegationTarget <$> pStakePoolVerificationKeyOrHashOrFile

pStakePoolVerificationKeyOrHashOrFile
:: Parser (VerificationKeyOrHashOrFile StakePoolKey)
pStakePoolVerificationKeyOrHashOrFile =
asum
[ VerificationKeyOrFile <$> pStakePoolVerificationKeyOrFile
, VerificationKeyHash <$> pStakePoolVerificationKeyHash
]

pVrfVerificationKeyFile :: Parser (VerificationKeyFile In)
pVrfVerificationKeyFile =
fmap File $ Opt.strOption $ mconcat
Expand Down
59 changes: 59 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -685,3 +685,62 @@ catCommands :: [Parser a] -> Maybe (Parser a)
catCommands = \case
[] -> Nothing
ps -> Just $ asum ps



pConstitution :: Parser Constitution
pConstitution =
asum
[ fmap ConstitutionFromText $ Opt.strOption $ mconcat
[ Opt.long "constitution"
, Opt.metavar "TEXT"
, Opt.help "Input constitution as UTF-8 encoded text."
]
, ConstitutionFromFile
<$> pFileInDirection "constitution-file" "Input constitution as a text file."
]

pGovActionDeposit :: Parser Lovelace
pGovActionDeposit =
Opt.option (readerFromParsecParser parseLovelace) $ mconcat
[ Opt.long "governance-action-deposit"
, Opt.metavar "NATURAL"
, Opt.help "Deposit required to submit a governance action."
]


pStakeVerificationKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFile StakeKey)
pStakeVerificationKeyOrHashOrFile = asum
[ VerificationKeyOrFile <$> pStakeVerificationKeyOrFile
, VerificationKeyHash <$> pStakeVerificationKeyHash
]

pStakeVerificationKeyHash :: Parser (Hash StakeKey)
pStakeVerificationKeyHash =
Opt.option (pHexHash AsStakeKey) $ mconcat
[ Opt.long "stake-key-hash"
, Opt.metavar "HASH"
, Opt.help $ mconcat
[ "Stake verification key hash (hex-encoded)."
]
]


pStakePoolVerificationKeyOrHashOrFile
:: Parser (VerificationKeyOrHashOrFile StakePoolKey)
pStakePoolVerificationKeyOrHashOrFile =
asum
[ VerificationKeyOrFile <$> pStakePoolVerificationKeyOrFile
, VerificationKeyHash <$> pStakePoolVerificationKeyHash
]

pStakePoolVerificationKeyHash :: Parser (Hash StakePoolKey)
pStakePoolVerificationKeyHash =
Opt.option (pBech32KeyHash AsStakePoolKey <|> pHexHash AsStakePoolKey) $ mconcat
[ Opt.long "stake-pool-id"
, Opt.metavar "STAKE_POOL_ID"
, Opt.help $ mconcat
[ "Stake pool ID/verification key hash (either Bech32-encoded or hex-encoded). "
, "Zero or more occurences of this option is allowed."
]
]
3 changes: 3 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Cardano.CLI.EraBased.Commands.Governance
import Cardano.CLI.EraBased.Governance
import Cardano.CLI.EraBased.Legacy
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.EraBased.Options.Governance.Actions
import Cardano.CLI.EraBased.Options.Governance.Committee
import Cardano.CLI.EraBased.Vote
import Cardano.CLI.Types.Common
Expand All @@ -37,8 +38,10 @@ pEraBasedGovernanceCmds envCli era =
, pEraBasedVoteCmd envCli era
, pCreateMirCertificatesCmds era
, pGovernanceCommitteeCmds era <&> fmap EraBasedGovernanceCommitteeCmds
, fmap EraBasedGovernanceActionCmds <$> pGovernanceActionCmds era
]


-- Registration Certificate related

pEraBasedRegistrationCertificateCmd
Expand Down
68 changes: 68 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module Cardano.CLI.EraBased.Options.Governance.Actions
( pGovernanceActionCmds
) where

import Cardano.Api

import Cardano.CLI.EraBased.Commands.Governance.Actions
import qualified Cardano.CLI.EraBased.Legacy as Legacy
import Cardano.CLI.EraBased.Options.Common

import Data.Foldable
import Options.Applicative
import qualified Options.Applicative as Opt

pGovernanceActionCmds :: ()
=> CardanoEra era
-> Maybe (Parser (GovernanceActionCmds era))
pGovernanceActionCmds era =
subInfoParser "action"
( Opt.progDesc
$ mconcat
[ "Governance action commands."
]
)
[ pGovernanceActionNewConstitution era
, pGovernanceActionCreateUpdateProposal era
]


pGovernanceActionNewConstitution
:: CardanoEra era -> Maybe (Parser (GovernanceActionCmds era))
pGovernanceActionNewConstitution =
featureInEra Nothing (\cOn -> Just $
subParser "create-constitution"
$ Opt.info (pCmd cOn)
$ Opt.progDesc "Create a constitution.")
where
pCmd :: ConwayEraOnwards era -> Parser (GovernanceActionCmds era)
pCmd cOn =
fmap (GovernanceActionCreateConstitution cOn) $
EraBasedNewConstitution
<$> pGovActionDeposit
<*> pAnyStakeIdentifier
<*> pConstitution
<*> pFileOutDirection "out-file" "Output filepath of the constitution."

pAnyStakeIdentifier :: Parser AnyStakeIdentifier
pAnyStakeIdentifier =
asum [ AnyStakePoolKey <$> pStakePoolVerificationKeyOrHashOrFile
, AnyStakeKey <$> pStakeVerificationKeyOrHashOrFile
]

pGovernanceActionCreateUpdateProposal :: CardanoEra era -> Maybe (Parser (GovernanceActionCmds era))
pGovernanceActionCreateUpdateProposal =
featureInEra Nothing (\cOn -> Just $
subParser "create-update-proposal"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be create-param-proposal., or something to similar to distinguish that it's an update to parameters.

$ Opt.info (pCmd cOn)
$ Opt.progDesc "Create an update proposal.")
where
pCmd :: ConwayEraOnwards era -> Parser (GovernanceActionCmds era)
pCmd cOn =
fmap (GovernanceActionCreateUpdateProposal cOn) $
ConwayOnwardsUpdateProposal cOn
<$> Legacy.pProtocolParametersUpdate
<*> pGovActionDeposit
<*> pAnyStakeIdentifier
<*> optional (pFileInDirection "cost-model" "Cost model filepath.")
<*> pFileOutDirection "out-file" "Output filepath of the update proposal."
5 changes: 5 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Cardano.CLI.EraBased.Commands
import Cardano.CLI.EraBased.Options.Governance
import Cardano.CLI.EraBased.Run.Certificate
import Cardano.CLI.EraBased.Run.Governance
import Cardano.CLI.EraBased.Run.Governance.Actions
import Cardano.CLI.EraBased.Run.Governance.Committee
import Cardano.CLI.EraBased.Vote

Expand Down Expand Up @@ -73,6 +74,10 @@ runEraBasedGovernanceCmds = \case
firstExceptT (const ()) -- TODO: Conway era - fix error handling
$ runGovernanceCommitteeCmds cmds

EraBasedGovernanceActionCmds cmds ->
firstExceptT (const ()) -- TODO: Conway era - fix error handling
$ runGovernanceActionCmds cmds

runEraBasedGovernancePreConwayCmd
:: ShelleyToBabbageEra era
-> ExceptT () IO ()
Expand Down
Loading