Skip to content

Commit

Permalink
Merge pull request #292 from input-output-hk/smelc/create-info-govern…
Browse files Browse the repository at this point in the history
…ance-action

cardano-cli: add governance create-info command
  • Loading branch information
smelc authored Sep 20, 2023
2 parents 5ad8d69 + 988c91b commit a0bbd49
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Cardano.CLI.EraBased.Commands.Governance.Actions
, GovernanceActionCmds(..)
, NewCommitteeCmd(..)
, NewConstitutionCmd(..)
, NewInfoCmd(..)
, NoConfidenceCmd(..)
, TreasuryWithdrawalCmd(..)
, renderGovernanceActionCmds
Expand Down Expand Up @@ -41,10 +42,9 @@ data GovernanceActionCmds era
| GovernanceActionTreasuryWithdrawalCmd
(ConwayEraOnwards era)
TreasuryWithdrawalCmd
| GoveranceActionInfoCmd -- TODO: Conway era - ledger currently provides a placeholder constructor
| GovernanceActionInfoCmd
(ConwayEraOnwards era)
(File () In)
(File () Out)
NewInfoCmd
deriving Show

data NewCommitteeCmd
Expand Down Expand Up @@ -74,6 +74,17 @@ data NewConstitutionCmd
, encFilePath :: File () Out
} deriving Show

-- | Datatype to carry data for the create-info governance action
data NewInfoCmd
= NewInfoCmd
{ niNetwork :: Ledger.Network
, niDeposit :: Lovelace
, niStakeCredential :: AnyStakeIdentifier
, niProposalUrl :: ProposalUrl
, niProposalHashSource :: ProposalHashSource
, niOutputFilePath :: File () Out
} deriving Show

data NoConfidenceCmd
= NoConfidenceCmd
{ ncNetwork :: Ledger.Network
Expand Down Expand Up @@ -114,7 +125,7 @@ renderGovernanceActionCmds = ("governance action " <>) . \case
GovernanceActionCreateNoConfidenceCmd {} ->
"create-no-confidence"

GoveranceActionInfoCmd {} ->
GovernanceActionInfoCmd {} ->
"create-info"

data AnyStakeIdentifier
Expand Down
20 changes: 20 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,31 @@ pGovernanceActionCmds era =
)
[ pGovernanceActionNewConstitutionCmd era
, pGovernanceActionNewCommitteeCmd era
, pGovernanceActionNewInfoCmd era
, pGovernanceActionNoConfidenceCmd era
, pGovernanceActionProtocolParametersUpdateCmd era
, pGovernanceActionTreasuryWithdrawalCmd era
]

pGovernanceActionNewInfoCmd
:: CardanoEra era
-> Maybe (Parser (GovernanceActionCmds era))
pGovernanceActionNewInfoCmd era = do
cOn <- maybeFeatureInEra era
pure
$ subParser "create-info"
$ Opt.info
( fmap (GovernanceActionInfoCmd cOn) $
NewInfoCmd
<$> pNetwork
<*> pGovActionDeposit
<*> pAnyStakeIdentifier
<*> pProposalUrl
<*> pProposalHashSource
<*> pFileOutDirection "out-file" "Path to action file to be used later on with build or build-raw "
)
$ Opt.progDesc "Create an info action."


pGovernanceActionNewConstitutionCmd
:: CardanoEra era
Expand Down
30 changes: 22 additions & 8 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

module Cardano.CLI.EraBased.Run.Governance.Actions
Expand All @@ -23,7 +22,6 @@ import Cardano.CLI.Types.Key
import qualified Cardano.Ledger.Conway.Governance as Ledger

import Control.Monad.Except (ExceptT)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Except.Extra
import Data.Function
import qualified Data.Map.Strict as Map
Expand All @@ -47,16 +45,32 @@ runGovernanceActionCmds = \case
GovernanceActionCreateNoConfidenceCmd cOn noConfidence ->
runGovernanceActionCreateNoConfidenceCmd cOn noConfidence

GoveranceActionInfoCmd cOn iFp oFp ->
runGovernanceActionInfoCmd cOn iFp oFp
GovernanceActionInfoCmd cOn newInfo ->
runGovernanceActionInfoCmd cOn newInfo

runGovernanceActionInfoCmd
:: ConwayEraOnwards era
-> File () In
-> File () Out
-> NewInfoCmd
-> ExceptT GovernanceActionsError IO ()
runGovernanceActionInfoCmd _cOn _iFp _oFp =
liftIO $ print @String "TODO: Conway era - implement runGovernanceActionInfoCmd - ledger currently provides a placeholder constructor"
runGovernanceActionInfoCmd cOn (NewInfoCmd network deposit returnAddr proposalUrl proposalHashSource outFp) = do
returnKeyHash <- readStakeKeyHash returnAddr

proposalHash <-
proposalHashSourceToHash proposalHashSource
& firstExceptT GovernanceActionsCmdProposalError

let proposalAnchor = Ledger.Anchor
{ Ledger.anchorUrl = unProposalUrl proposalUrl
, Ledger.anchorDataHash = proposalHash
}

let sbe = conwayEraOnwardsToShelleyBasedEra cOn
govAction = InfoAct
proposalProcedure = createProposalProcedure sbe network deposit returnKeyHash govAction proposalAnchor

firstExceptT GovernanceActionsCmdWriteFileError . newExceptT
$ conwayEraOnwardsConstraints cOn
$ writeFileTextEnvelope outFp Nothing proposalProcedure

-- TODO: Conway era - update with new ledger types from cardano-ledger-conway-1.7.0.0
runGovernanceActionCreateNoConfidenceCmd
Expand Down
19 changes: 19 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 @@ -6449,6 +6449,7 @@ Usage: cardano-cli conway governance query committee-state
Usage: cardano-cli conway governance action
( create-constitution
| create-new-committee
| create-info
| create-no-confidence
| create-protocol-parameters-update
| create-treasury-withdrawal
Expand Down Expand Up @@ -6524,6 +6525,24 @@ Usage: cardano-cli conway governance action create-new-committee

Create a new committee proposal.

Usage: cardano-cli conway governance action create-info (--mainnet | --testnet)
--governance-action-deposit NATURAL
( --stake-pool-verification-key STRING
| --cold-verification-key-file FILE
| --stake-pool-id STAKE_POOL_ID
| --stake-verification-key STRING
| --stake-verification-key-file FILE
| --stake-key-hash HASH
)
--proposal-url TEXT
( --proposal-text TEXT
| --proposal-file FILE
| --proposal-hash HASH
)
--out-file FILE

Create an info action.

Usage: cardano-cli conway governance action create-no-confidence
( --mainnet
| --testnet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Usage: cardano-cli conway governance action
( create-constitution
| create-new-committee
| create-info
| create-no-confidence
| create-protocol-parameters-update
| create-treasury-withdrawal
Expand All @@ -14,6 +15,7 @@ Available options:
Available commands:
create-constitution Create a constitution.
create-new-committee Create a new committee proposal.
create-info Create an info action.
create-no-confidence Create a no confidence proposal.
create-protocol-parameters-update
Create a protocol parameters update.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Usage: cardano-cli conway governance action create-info (--mainnet | --testnet)
--governance-action-deposit NATURAL
( --stake-pool-verification-key STRING
| --cold-verification-key-file FILE
| --stake-pool-id STAKE_POOL_ID
| --stake-verification-key STRING
| --stake-verification-key-file FILE
| --stake-key-hash HASH
)
--proposal-url TEXT
( --proposal-text TEXT
| --proposal-file FILE
| --proposal-hash HASH
)
--out-file FILE

Create an info action.

Available options:
--mainnet Use the mainnet magic id.
--testnet Use the testnet magic id.
--governance-action-deposit NATURAL
Deposit required to submit a governance action.
--stake-pool-verification-key STRING
Stake pool verification key (Bech32 or hex-encoded).
--cold-verification-key-file FILE
Filepath of the stake pool verification key.
--stake-pool-id STAKE_POOL_ID
Stake pool ID/verification key hash (either
Bech32-encoded or hex-encoded). Zero or more
occurences of this option is allowed.
--stake-verification-key STRING
Stake verification key (Bech32 or hex-encoded).
--stake-verification-key-file FILE
Filepath of the staking verification key.
--stake-key-hash HASH Stake verification key hash (hex-encoded).
--proposal-url TEXT Proposal anchor URL
--proposal-text TEXT Input proposal as UTF-8 encoded text.
--proposal-file FILE Input proposal as a text file.
--proposal-hash HASH Proposal anchor data hash.
--out-file FILE Path to action file to be used later on with build or
build-raw
-h,--help Show this help text

0 comments on commit a0bbd49

Please sign in to comment.