Skip to content

Commit

Permalink
Merge pull request #442 from input-output-hk/smelc/governance-rework-…
Browse files Browse the repository at this point in the history
…hash-arguments

governance: add hash command and remove text/file hash arguments of existing commands
  • Loading branch information
smelc authored Nov 15, 2023
2 parents 931ad3f + 5238d77 commit 0a7af1c
Show file tree
Hide file tree
Showing 42 changed files with 390 additions and 285 deletions.
4 changes: 4 additions & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ library
Cardano.CLI.EraBased.Commands.Governance.Actions
Cardano.CLI.EraBased.Commands.Governance.Committee
Cardano.CLI.EraBased.Commands.Governance.DRep
Cardano.CLI.EraBased.Commands.Governance.Hash
Cardano.CLI.EraBased.Commands.Governance.Poll
Cardano.CLI.EraBased.Commands.Governance.Vote
Cardano.CLI.EraBased.Commands.Key
Expand All @@ -90,6 +91,7 @@ library
Cardano.CLI.EraBased.Options.Governance.Actions
Cardano.CLI.EraBased.Options.Governance.Committee
Cardano.CLI.EraBased.Options.Governance.DRep
Cardano.CLI.EraBased.Options.Governance.Hash
Cardano.CLI.EraBased.Options.Governance.Poll
Cardano.CLI.EraBased.Options.Governance.Vote
Cardano.CLI.EraBased.Options.Key
Expand All @@ -107,6 +109,7 @@ library
Cardano.CLI.EraBased.Run.Governance.Actions
Cardano.CLI.EraBased.Run.Governance.Committee
Cardano.CLI.EraBased.Run.Governance.DRep
Cardano.CLI.EraBased.Run.Governance.Hash
Cardano.CLI.EraBased.Run.Governance.GenesisKeyDelegationCertificate
Cardano.CLI.EraBased.Run.Governance.Poll
Cardano.CLI.EraBased.Run.Governance.Vote
Expand Down Expand Up @@ -165,6 +168,7 @@ library
Cardano.CLI.Types.Errors.GovernanceActionsError
Cardano.CLI.Types.Errors.GovernanceCmdError
Cardano.CLI.Types.Errors.GovernanceCommitteeError
Cardano.CLI.Types.Errors.GovernanceHashError
Cardano.CLI.Types.Errors.GovernanceQueryError
Cardano.CLI.Types.Errors.GovernanceVoteCmdError
Cardano.CLI.Types.Errors.ItnKeyConversionError
Expand Down
5 changes: 5 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Cardano.Api.Shelley (VrfKey)
import Cardano.CLI.EraBased.Commands.Governance.Actions
import Cardano.CLI.EraBased.Commands.Governance.Committee
import Cardano.CLI.EraBased.Commands.Governance.DRep
import Cardano.CLI.EraBased.Commands.Governance.Hash
import Cardano.CLI.EraBased.Commands.Governance.Poll
import Cardano.CLI.EraBased.Commands.Governance.Vote
import Cardano.CLI.Types.Key (VerificationKeyOrHashOrFile)
Expand Down Expand Up @@ -46,6 +47,8 @@ data GovernanceCmds era
(GovernanceCommitteeCmds era)
| GovernanceDRepCmds
(GovernanceDRepCmds era)
| GovernanceHashCmds
(GovernanceHashCmds era)
| GovernancePollCmds
(GovernancePollCmds era)
| GovernanceVoteCmds
Expand All @@ -67,6 +70,8 @@ renderGovernanceCmds = \case
renderGovernanceCommitteeCmds cmds
GovernanceDRepCmds cmds ->
renderGovernanceDRepCmds cmds
GovernanceHashCmds cmds ->
renderGovernanceHashCmds cmds
GovernancePollCmds cmds ->
renderGovernancePollCmds cmds
GovernanceVoteCmds cmds ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import Cardano.Api.Shelley

import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key
import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.Crypto as Crypto
import qualified Cardano.Ledger.SafeHash as Ledger

import Data.Text (Text)
import Data.Word
Expand All @@ -47,7 +50,7 @@ data GoveranceActionUpdateCommitteeCmdArgs era
, deposit :: !Lovelace
, returnAddress :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, oldCommitteeVkeySource :: ![VerificationKeyOrHashOrFile CommitteeColdKey]
, newCommitteeVkeySource :: ![(VerificationKeyOrHashOrFile CommitteeColdKey, EpochNo)]
, requiredQuorum :: !Rational
Expand All @@ -63,7 +66,7 @@ data GovernanceActionCreateConstitutionCmdArgs era
, stakeCredential :: !(VerificationKeyOrHashOrFile StakeKey)
, mPrevGovernanceActionId :: !(Maybe (TxId, Word32))
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, constitutionUrl :: !ConstitutionUrl
, constitutionHashSource :: !ConstitutionHashSource
, outFile :: !(File () Out)
Expand All @@ -77,7 +80,7 @@ data GovernanceActionInfoCmdArgs era
, deposit :: !Lovelace
, returnStakeAddress :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, outFile :: !(File () Out)
} deriving Show

Expand All @@ -88,7 +91,7 @@ data GovernanceActionCreateNoConfidenceCmdArgs era
, deposit :: !Lovelace
, returnStakeAddress :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, governanceActionId :: !TxId
, governanceActionIndex :: !Word32
, outFile :: !(File () Out)
Expand All @@ -110,7 +113,7 @@ data GovernanceActionTreasuryWithdrawalCmdArgs era
, deposit :: !Lovelace
, returnAddr :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, treasuryWithdrawal :: ![(VerificationKeyOrHashOrFile StakeKey, Lovelace)]
, outFile :: !(File () Out)
} deriving Show
Expand All @@ -130,7 +133,7 @@ data UpdateProtocolParametersConwayOnwards era
, deposit :: !Lovelace
, returnAddr :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHashSource :: !ProposalHashSource
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, governanceActionId :: !(Maybe (TxId, Word32))
}

Expand Down
35 changes: 35 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Hash.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}


module Cardano.CLI.EraBased.Commands.Governance.Hash
(
GovernanceHashCmds (..),
GovernanceHashCmdArgs (..),
GovernanceHashSource (..),
renderGovernanceHashCmds
) where

import Cardano.Api

import Cardano.CLI.Types.Common

import Data.Text (Text)

newtype GovernanceHashCmds era = GovernanceHashCmd (GovernanceHashCmdArgs era)

data GovernanceHashCmdArgs era
= GovernanceHashCmdArgs {
eon :: !(ConwayEraOnwards era),
toHash :: !GovernanceHashSource
} deriving Show

data GovernanceHashSource
= GovernanceHashSourceBinaryFile (File ProposalText In)
| GovernanceHashSourceTextFile (File ProposalText In)
| GovernanceHashSourceText Text
deriving Show

renderGovernanceHashCmds :: GovernanceHashCmds era -> Text
renderGovernanceHashCmds =
\case GovernanceHashCmd {} -> "governance hash"
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ module Cardano.CLI.EraBased.Commands.Governance.Vote
, GovernanceVoteCreateCmdArgs(..)
, renderGovernanceVoteCmds
) where

import Cardano.Api.Shelley

import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Governance
import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.Crypto as Crypto
import qualified Cardano.Ledger.SafeHash as Ledger

import Data.Text (Text)
import Data.Word
Expand All @@ -30,7 +32,7 @@ data GovernanceVoteCreateCmdArgs era
, voteChoice :: Vote
, governanceAction :: (TxId, Word32)
, votingStakeCredentialSource :: AnyVotingStakeVerificationKeyOrHashOrFile
, mAnchor :: Maybe (VoteUrl, VoteHashSource)
, mAnchor :: Maybe (VoteUrl, Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, outFile :: VoteFile Out
}

Expand Down
62 changes: 14 additions & 48 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3046,34 +3046,17 @@ pAlwaysAbstain =
, Opt.help "Abstain from voting on all proposals."
]

pVoteAnchor :: Parser (VoteUrl, VoteHashSource)
pVoteAnchor :: Parser (VoteUrl, L.SafeHash Crypto.StandardCrypto L.AnchorData)
pVoteAnchor = (,)
<$> (VoteUrl <$> pUrl "vote-anchor-url" "Vote anchor URL")
<*> pVoteHashSource
<$> (VoteUrl <$> pUrl "anchor-url" "Vote anchor URL")
<*> pVoteAnchorDataHash

pVoteHashSource :: Parser VoteHashSource
pVoteHashSource =
asum
[ VoteHashSourceText
<$> Opt.strOption
( mconcat
[ Opt.long "vote-anchor-metadata"
, Opt.metavar "TEXT"
, Opt.help "Vote anchor contents as UTF-8 encoded text."
]
)
, VoteHashSourceFile
<$> pFileInDirection "vote-anchor-metadata-file" "Vote anchor contents as a text file."
, VoteHashSourceHash
<$> pVoteHash
]

pVoteHash :: Parser (L.SafeHash Crypto.StandardCrypto L.AnchorData)
pVoteHash =
pVoteAnchorDataHash :: Parser (L.SafeHash Crypto.StandardCrypto L.AnchorData)
pVoteAnchorDataHash =
Opt.option readSafeHash $ mconcat
[ Opt.long "vote-anchor-metadata-hash"
[ Opt.long "anchor-data-hash"
, Opt.metavar "HASH"
, Opt.help "Hash of the vote anchor data."
, Opt.help "Hash of the vote anchor data (obtain it with \"cardano-cli conway governance hash ...\")."
]

pAlwaysNoConfidence :: Parser ()
Expand Down Expand Up @@ -3186,34 +3169,17 @@ pDRepVerificationKeyFile =
, Opt.completer (Opt.bashCompleter "file")
]

pProposalUrl :: Parser ProposalUrl
pProposalUrl =
pAnchorUrl :: Parser ProposalUrl
pAnchorUrl =
ProposalUrl
<$> pUrl "proposal-anchor-url" "Proposal anchor URL"

pProposalHashSource :: Parser ProposalHashSource
pProposalHashSource =
asum
[ ProposalHashSourceText
<$> Opt.strOption
( mconcat
[ Opt.long "proposal-anchor-metadata"
, Opt.metavar "TEXT"
, Opt.help "Proposal anchor contents as UTF-8 encoded text."
]
)
, ProposalHashSourceFile
<$> pFileInDirection "proposal-anchor-metadata-file" "Proposal anchor contents as a text file."
, ProposalHashSourceHash
<$> pProposalHash
]
<$> pUrl "anchor-url" "Anchor URL"

pProposalHash :: Parser (L.SafeHash Crypto.StandardCrypto L.AnchorData)
pProposalHash =
pAnchorDataHash :: Parser (L.SafeHash Crypto.StandardCrypto L.AnchorData)
pAnchorDataHash =
Opt.option readSafeHash $ mconcat
[ Opt.long "proposal-anchor-metadata-hash"
[ Opt.long "anchor-data-hash"
, Opt.metavar "HASH"
, Opt.help "Proposal anchor data hash."
, Opt.help "Proposal anchor data hash (obtain it with \"cardano-cli conway governance hash ...\")"
]

pPreviousGovernanceAction :: Parser (Maybe (TxId, Word32))
Expand Down
2 changes: 2 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.EraBased.Options.Governance.Actions
import Cardano.CLI.EraBased.Options.Governance.Committee
import Cardano.CLI.EraBased.Options.Governance.DRep
import Cardano.CLI.EraBased.Options.Governance.Hash
import Cardano.CLI.EraBased.Options.Governance.Poll
import Cardano.CLI.EraBased.Options.Governance.Vote

Expand All @@ -36,6 +37,7 @@ pGovernanceCmds era =
, fmap GovernanceActionCmds <$> pGovernanceActionCmds era
, fmap GovernanceCommitteeCmds <$> pGovernanceCommitteeCmds era
, fmap GovernanceDRepCmds <$> pGovernanceDRepCmds era
, fmap GovernanceHashCmds <$> pGovernanceHashCmds era
, fmap GovernancePollCmds <$> pGovernancePollCmds era
, fmap GovernanceVoteCmds <$> pGovernanceVoteCmds era
]
Expand Down
24 changes: 12 additions & 12 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ pGovernanceActionNewInfoCmd era = do
<$> pNetwork
<*> pGovActionDeposit
<*> pStakeVerificationKeyOrHashOrFile Nothing
<*> pProposalUrl
<*> pProposalHashSource
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pFileOutDirection "out-file" "Path to action file to be used later on with build or build-raw "
)
$ Opt.progDesc "Create an info action."
Expand All @@ -90,8 +90,8 @@ pGovernanceActionNewConstitutionCmd era = do
<*> pGovActionDeposit
<*> pStakeVerificationKeyOrHashOrFile Nothing
<*> pPreviousGovernanceAction
<*> pProposalUrl
<*> pProposalHashSource
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pConstitutionUrl
<*> pConstitutionHashSource
<*> pFileOutDirection "out-file" "Output filepath of the constitution."
Expand Down Expand Up @@ -119,8 +119,8 @@ pUpdateCommitteeCmd eon =
<$> pNetwork
<*> pGovActionDeposit
<*> pStakeVerificationKeyOrHashOrFile Nothing
<*> pProposalUrl
<*> pProposalHashSource
<*> pAnchorUrl
<*> pAnchorDataHash
<*> many pRemoveCommitteeColdVerificationKeyOrHashOrFile
<*> many
( (,)
Expand All @@ -144,8 +144,8 @@ pGovernanceActionNoConfidenceCmd era = do
<$> pNetwork
<*> pGovActionDeposit
<*> pStakeVerificationKeyOrHashOrFile Nothing
<*> pProposalUrl
<*> pProposalHashSource
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pTxId "governance-action-tx-id" "Previous txid of `NoConfidence` or `NewCommittee` governance action."
<*> pWord32 "governance-action-index" "Previous tx's governance action index of `NoConfidence` or `NewCommittee` governance action."
<*> pFileOutDirection "out-file" "Output filepath of the no confidence proposal."
Expand All @@ -164,8 +164,8 @@ pUpdateProtocolParametersPostConway conwayOnwards =
<$> pNetwork
<*> pGovActionDeposit
<*> pStakeVerificationKeyOrHashOrFile Nothing
<*> pProposalUrl
<*> pProposalHashSource
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pPreviousGovernanceAction


Expand Down Expand Up @@ -342,8 +342,8 @@ pGovernanceActionTreasuryWithdrawalCmd era = do
<$> pNetwork
<*> pGovActionDeposit
<*> pStakeVerificationKeyOrHashOrFile (Just "deposit-return")
<*> pProposalUrl
<*> pProposalHashSource
<*> pAnchorUrl
<*> pAnchorDataHash
<*> many ((,) <$> pStakeVerificationKeyOrHashOrFile (Just "funds-receiving") <*> pTransferAmt)
<*> pFileOutDirection "out-file" "Output filepath of the treasury withdrawal."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Cardano.CLI.EraBased.Options.Governance.Committee
import Cardano.Api

import Cardano.CLI.EraBased.Commands.Governance.Committee
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.EraBased.Options.Common hiding (pAnchorUrl)
import Cardano.CLI.Read
import qualified Cardano.Ledger.BaseTypes as L
import qualified Cardano.Ledger.Crypto as Crypto
Expand Down
Loading

0 comments on commit 0a7af1c

Please sign in to comment.