Skip to content

Commit

Permalink
conway governance hash -> conway hash
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Jun 13, 2024
1 parent fed71b3 commit 8a20217
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 195 deletions.
8 changes: 4 additions & 4 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ 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.Hash
Cardano.CLI.EraBased.Commands.Key
Cardano.CLI.EraBased.Commands.Node
Cardano.CLI.EraBased.Commands.Query
Expand All @@ -84,9 +84,9 @@ 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.Hash
Cardano.CLI.EraBased.Options.Key
Cardano.CLI.EraBased.Options.Node
Cardano.CLI.EraBased.Options.Query
Expand All @@ -103,10 +103,10 @@ 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
Cardano.CLI.EraBased.Run.Hash
Cardano.CLI.EraBased.Run.Key
Cardano.CLI.EraBased.Run.Node
Cardano.CLI.EraBased.Run.Query
Expand Down Expand Up @@ -167,9 +167,9 @@ 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.HashCmdError
Cardano.CLI.Types.Errors.ItnKeyConversionError
Cardano.CLI.Types.Errors.KeyCmdError
Cardano.CLI.Types.Errors.NodeCmdError
Expand Down
6 changes: 6 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Cardano.Api (ShelleyBasedEra (..), toCardanoEra)
import Cardano.CLI.Environment
import Cardano.CLI.EraBased.Commands.Address
import Cardano.CLI.EraBased.Commands.Genesis
import Cardano.CLI.EraBased.Commands.Hash
import Cardano.CLI.EraBased.Commands.Key
import Cardano.CLI.EraBased.Commands.Node
import Cardano.CLI.EraBased.Commands.Query
Expand All @@ -26,6 +27,7 @@ import Cardano.CLI.EraBased.Options.Address
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.EraBased.Options.Genesis
import Cardano.CLI.EraBased.Options.Governance
import Cardano.CLI.EraBased.Options.Hash (pHashCmds)
import Cardano.CLI.EraBased.Options.Key
import Cardano.CLI.EraBased.Options.Node
import Cardano.CLI.EraBased.Options.Query
Expand All @@ -52,6 +54,7 @@ data Cmds era
| KeyCmds (KeyCmds era)
| GenesisCmds (GenesisCmds era)
| GovernanceCmds (GovernanceCmds era)
| HashCmds (HashCmds era)
| NodeCmds (NodeCmds era)
| QueryCmds (QueryCmds era)
| StakeAddressCmds (StakeAddressCmds era)
Expand All @@ -69,6 +72,8 @@ renderCmds = \case
renderGenesisCmds cmd
GovernanceCmds cmd ->
renderGovernanceCmds cmd
HashCmds cmd ->
renderHashCmds cmd
NodeCmds cmd ->
renderNodeCmds cmd
QueryCmds cmd ->
Expand Down Expand Up @@ -118,6 +123,7 @@ pCmds era envCli =
, fmap KeyCmds <$> pKeyCmds
, fmap GenesisCmds <$> pGenesisCmds envCli
, fmap GovernanceCmds <$> pGovernanceCmds (toCardanoEra era)
, fmap HashCmds <$> pHashCmds (toCardanoEra era)
, fmap NodeCmds <$> pNodeCmds
, fmap QueryCmds <$> pQueryCmds (toCardanoEra era) envCli
, fmap StakeAddressCmds <$> pStakeAddressCmds (toCardanoEra era) envCli
Expand Down
5 changes: 0 additions & 5 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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 @@ -48,8 +47,6 @@ data GovernanceCmds era
(GovernanceCommitteeCmds era)
| GovernanceDRepCmds
(GovernanceDRepCmds era)
| GovernanceHashCmds
(GovernanceHashCmds era)
| GovernancePollCmds
(GovernancePollCmds era)
| GovernanceVoteCmds
Expand All @@ -71,8 +68,6 @@ renderGovernanceCmds = \case
renderGovernanceCommitteeCmds cmds
GovernanceDRepCmds cmds ->
renderGovernanceDRepCmds cmds
GovernanceHashCmds cmds ->
renderGovernanceHashCmds cmds
GovernancePollCmds cmds ->
renderGovernancePollCmds cmds
GovernanceVoteCmds cmds ->
Expand Down
47 changes: 0 additions & 47 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Hash.hs

This file was deleted.

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

module Cardano.CLI.EraBased.Commands.Hash
(
HashCmds (..),
HashAnchorDataCmdArgs (..),
HashScriptCmdArgs (..),
AnchorDataHashSource (..),
renderHashCmds
) where

import Cardano.Api

import Cardano.CLI.Types.Common

import Data.Text (Text)

data HashCmds era
= HashAnchorDataCmd !(HashAnchorDataCmdArgs era)
| HashScriptCmd !(HashScriptCmdArgs era)

data HashAnchorDataCmdArgs era
= HashAnchorDataCmdArgs {
eon :: !(ConwayEraOnwards era)
, toHash :: !AnchorDataHashSource
, moutFile :: !(Maybe (File () Out)) -- ^ The output file to which the hash is written
} deriving Show

data AnchorDataHashSource
= AnchorDataHashSourceBinaryFile (File ProposalBinary In)
| AnchorDataHashSourceTextFile (File ProposalText In)
| AnchorDataHashSourceText Text
deriving Show

data HashScriptCmdArgs era
= HashScriptCmdArgs {
eon :: !(ConwayEraOnwards era)
, toHash :: !ScriptFile
, moutFile :: !(Maybe (File () Out)) -- ^ The output file to which the hash is written
} deriving Show

renderHashCmds :: HashCmds era -> Text
renderHashCmds = \case
HashAnchorDataCmd {} -> "hash anchor-data"
HashScriptCmd {} -> "hash script"
2 changes: 0 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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 @@ -37,7 +36,6 @@ 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
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}

module Cardano.CLI.EraBased.Options.Governance.Hash
module Cardano.CLI.EraBased.Options.Hash
(
pGovernanceHashCmds,
pHashCmds,
) where

import Cardano.Api

import qualified Cardano.CLI.EraBased.Commands.Governance.Hash as Cmd
import qualified Cardano.CLI.EraBased.Commands.Hash as Cmd
import Cardano.CLI.EraBased.Options.Common

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

pGovernanceHashCmds
pHashCmds
:: CardanoEra era
-> Maybe (Parser (Cmd.GovernanceHashCmds era))
pGovernanceHashCmds era =
-> Maybe (Parser (Cmd.HashCmds era))
pHashCmds era =
subInfoParser "hash"
( Opt.progDesc
$ mconcat
[ "Compute the hash to pass to the various --*-hash arguments of governance commands."
[ "Compute the hash to pass to the various --*-hash arguments of commands."
]
)
[ pGovernanceHashAnchorDataCmd era
, pGovernanceHashScriptCmd era
[ pHashAnchorDataCmd era
, pHashScriptCmd era
]

pGovernanceHashAnchorDataCmd :: ()
pHashAnchorDataCmd :: ()
=> CardanoEra era
-> Maybe (Parser (Cmd.GovernanceHashCmds era))
pGovernanceHashAnchorDataCmd era = do
-> Maybe (Parser (Cmd.HashCmds era))
pHashAnchorDataCmd era = do
eon <- forEraMaybeEon era
return
$ subParser "anchor-data"
$ Opt.info
( fmap Cmd.GovernanceHashAnchorDataCmd
(Cmd.GovernanceHashAnchorDataCmdArgs eon
<$> pGovernanceAnchorDataHashSource
( fmap Cmd.HashAnchorDataCmd
(Cmd.HashAnchorDataCmdArgs eon
<$> pAnchorDataHashSource
<*> optional pOutputFile))
$ Opt.progDesc "Compute the hash of some anchor data (to then pass it to other governance commands)."
$ Opt.progDesc "Compute the hash of some anchor data (to then pass it to other commands)."

pGovernanceAnchorDataHashSource :: Parser Cmd.GovernanceAnchorDataHashSource
pGovernanceAnchorDataHashSource =
pAnchorDataHashSource :: Parser Cmd.AnchorDataHashSource
pAnchorDataHashSource =
asum
[
Cmd.GovernanceAnchorDataHashSourceText
Cmd.AnchorDataHashSourceText
<$> Opt.strOption
( mconcat
[ Opt.long "text"
, Opt.metavar "TEXT"
, Opt.help "Text to hash as UTF-8"
]
)
, Cmd.GovernanceAnchorDataHashSourceBinaryFile
, Cmd.AnchorDataHashSourceBinaryFile
<$> pFileInDirection "file-binary" "Binary file to hash"
, Cmd.GovernanceAnchorDataHashSourceTextFile
, Cmd.AnchorDataHashSourceTextFile
<$> pFileInDirection "file-text" "Text file to hash"
]

pGovernanceHashScriptCmd :: ()
pHashScriptCmd :: ()
=> CardanoEra era
-> Maybe (Parser (Cmd.GovernanceHashCmds era))
pGovernanceHashScriptCmd era = do
-> Maybe (Parser (Cmd.HashCmds era))
pHashScriptCmd era = do
eon <- forEraMaybeEon era
return
$ subParser "script"
$ Opt.info
( fmap Cmd.GovernanceHashScriptCmd
(Cmd.GovernanceHashScriptCmdArgs eon
( fmap Cmd.HashScriptCmd
(Cmd.HashScriptCmdArgs eon
<$> pScript
<*> optional pOutputFile))
$ Opt.progDesc "Compute the hash of a script (to then pass it to other governance commands)."
$ Opt.progDesc "Compute the hash of a script (to then pass it to other commands)."
4 changes: 4 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Cardano.CLI.EraBased.Commands
import Cardano.CLI.EraBased.Run.Address
import Cardano.CLI.EraBased.Run.Genesis
import Cardano.CLI.EraBased.Run.Governance
import Cardano.CLI.EraBased.Run.Hash
import Cardano.CLI.EraBased.Run.Key
import Cardano.CLI.EraBased.Run.Node
import Cardano.CLI.EraBased.Run.Query
Expand Down Expand Up @@ -45,6 +46,9 @@ runCmds = \case
GenesisCmds cmd ->
runGenesisCmds cmd
& firstExceptT CmdGenesisError
HashCmds cmd ->
runHashCmds cmd
& firstExceptT CmdHashError
NodeCmds cmd ->
runNodeCmds cmd
& firstExceptT CmdNodeError
Expand Down
4 changes: 0 additions & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Cardano.CLI.EraBased.Run.Governance.Actions
import Cardano.CLI.EraBased.Run.Governance.Committee
import Cardano.CLI.EraBased.Run.Governance.DRep
import Cardano.CLI.EraBased.Run.Governance.GenesisKeyDelegationCertificate
import Cardano.CLI.EraBased.Run.Governance.Hash
import Cardano.CLI.EraBased.Run.Governance.Poll
import Cardano.CLI.EraBased.Run.Governance.Vote
import Cardano.CLI.Types.Errors.CmdError
Expand Down Expand Up @@ -65,9 +64,6 @@ runGovernanceCmds = \case
Cmd.GovernanceDRepCmds cmds ->
runGovernanceDRepCmds cmds

Cmd.GovernanceHashCmds cmds ->
runGovernanceHashCmds cmds

Cmd.GovernancePollCmds cmds ->
runGovernancePollCmds cmds
& firstExceptT CmdGovernanceCmdError
Expand Down
Loading

0 comments on commit 8a20217

Please sign in to comment.