Skip to content

Commit

Permalink
Add create-no-confidence command to era based cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Aug 17, 2023
1 parent f604139 commit eb24cf9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Cardano.CLI.EraBased.Commands.Governance.Actions
, GovernanceActionCmds(..)
, EraBasedNewCommittee(..)
, EraBasedNewConstitution(..)
, EraBasedNoConfidence(..)
, EraBasedTreasuryWithdrawal(..)
, renderGovernanceActionCmds
) where
Expand All @@ -19,6 +20,7 @@ import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key

import Data.Text (Text)
import Data.Word

data GovernanceActionCmds era
= GovernanceActionCreateConstitution
Expand All @@ -27,6 +29,9 @@ data GovernanceActionCmds era
| GoveranceActionCreateNewCommittee
(ConwayEraOnwards era)
EraBasedNewCommittee
| GovernanceActionCreateNoConfidence
(ConwayEraOnwards era)
EraBasedNoConfidence
| GovernanceActionProtocolParametersUpdate
(ShelleyBasedEra era)
EpochNo
Expand Down Expand Up @@ -57,6 +62,15 @@ data EraBasedNewConstitution
, encFilePath :: File () Out
} deriving Show

data EraBasedNoConfidence
= EraBasedNoConfidence
{ ncDeposit :: Lovelace
, ncStakeCredential :: AnyStakeIdentifier
, ncGovAct :: TxId
, ncGovActIndex :: Word32
, ncFilePath :: File () Out
} deriving Show

data EraBasedTreasuryWithdrawal where
EraBasedTreasuryWithdrawal
:: Lovelace -- ^ Deposit
Expand All @@ -81,6 +95,9 @@ renderGovernanceActionCmds = \case
GoveranceActionCreateNewCommittee {} ->
"governance action create-new-committee"

GovernanceActionCreateNoConfidence {} ->
"governance action create-no-confidence"

data AnyStakeIdentifier
= AnyStakeKey (VerificationKeyOrHashOrFile StakeKey)
| AnyStakePoolKey (VerificationKeyOrHashOrFile StakePoolKey)
Expand Down
40 changes: 40 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 @@ -18,6 +18,7 @@ import qualified Cardano.Ledger.BaseTypes as Ledger

import Data.Foldable
import GHC.Natural (Natural)
import GHC.Word
import Options.Applicative
import qualified Options.Applicative as Opt

Expand All @@ -33,6 +34,7 @@ pGovernanceActionCmds era =
)
[ pGovernanceActionNewConstitution era
, pGovernanceActionNewCommittee era
, pGovernanceActionNoConfidence era
, pGovernanceActionProtocolParametersUpdate era
, pGovernanceActionTreasuryWithdrawal era
]
Expand Down Expand Up @@ -78,6 +80,44 @@ pEraBasedNewCommittee =
<*> pGoveranceActionIdentifier "Previous governance action id of `NewCommittee` or `NoConfidence` type"
<*> pOutputFile


pGovernanceActionNoConfidence
:: CardanoEra era -> Maybe (Parser (GovernanceActionCmds era))
pGovernanceActionNoConfidence =
featureInEra Nothing (\cOn -> Just $
subParser "create-no-confidence"
$ Opt.info (pCmd cOn)
$ Opt.progDesc "Create a no confidence proposal.")
where
pCmd :: ConwayEraOnwards era -> Parser (GovernanceActionCmds era)
pCmd cOn =
fmap (GovernanceActionCreateNoConfidence cOn) $
EraBasedNoConfidence
<$> pGovActionDeposit
<*> pAnyStakeIdentifier
<*> pTxId "governance-action-tx-id" "Previous txid of `NoConfidence` or `NewCommittee` governance action."
<*> pWord32 "goverenance-action-index" "Previous tx's governance action index of `NoConfidence` or `NewCommittee` governance action."
<*> pFileOutDirection "out-file" "Output filepath of the no confidence proposal."


pWord32 :: String -> String -> Parser Word32
pWord32 l h =
Opt.option auto $ mconcat
[ Opt.long l
, Opt.metavar "WORD32"
, Opt.help h
]


pTxId :: String -> String -> Parser TxId
pTxId l h =
Opt.option (readerFromParsecParser parseTxId) $ mconcat
[ Opt.long l
, Opt.metavar "TXID"
, Opt.help h
]


pAnyStakeIdentifier :: Parser AnyStakeIdentifier
pAnyStakeIdentifier =
asum [ AnyStakePoolKey <$> pStakePoolVerificationKeyOrHashOrFile
Expand Down
17 changes: 17 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ runGovernanceActionCmds = \case
GoveranceActionCreateNewCommittee con newCommittee ->
runGovernanceActionCreateNewCommittee con newCommittee

GovernanceActionCreateNoConfidence cOn noConfidence ->
runGovernanceActionCreateNoConfidence cOn noConfidence

-- TODO: Conway era - update with new ledger types from cardano-ledger-conway-1.7.0.0
runGovernanceActionCreateNoConfidence
:: ConwayEraOnwards era
-> EraBasedNoConfidence
-> ExceptT GovernanceActionsError IO ()
runGovernanceActionCreateNoConfidence cOn (EraBasedNoConfidence deposit returnAddr _txid _ind outFp) = do
returnKeyHash <- readStakeKeyHash returnAddr
let sbe = conwayEraOnwardsToShelleyBasedEra cOn
proposal = createProposalProcedure sbe deposit returnKeyHash MotionOfNoConfidence

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

runGovernanceActionCreateConstitution :: ()
=> ConwayEraOnwards era
-> EraBasedNewConstitution
Expand Down

0 comments on commit eb24cf9

Please sign in to comment.