Skip to content

Commit

Permalink
Add governance query commands
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Aug 25, 2023
1 parent 2e5538a commit ac961e4
Show file tree
Hide file tree
Showing 28 changed files with 1,057 additions and 27 deletions.
6 changes: 5 additions & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,21 @@ library
Cardano.CLI.EraBased.Commands.Governance.Actions
Cardano.CLI.EraBased.Commands.Governance.Committee
Cardano.CLI.EraBased.Commands.Governance.DRep
Cardano.CLI.EraBased.Commands.Governance.Query
Cardano.CLI.EraBased.Commands.Governance.Vote
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.Options.Governance.DRep
Cardano.CLI.EraBased.Options.Governance.Query
Cardano.CLI.EraBased.Options.Governance.Vote
Cardano.CLI.EraBased.Run
Cardano.CLI.EraBased.Run.Governance
Cardano.CLI.EraBased.Run.Governance.Actions
Cardano.CLI.EraBased.Run.Governance.Committee
Cardano.CLI.EraBased.Run.Governance.DRep
Cardano.CLI.EraBased.Run.Governance.Query
Cardano.CLI.EraBased.Run.Governance.Vote
Cardano.CLI.Helpers
Cardano.CLI.IO.Lazy
Expand Down Expand Up @@ -129,6 +132,7 @@ library
Cardano.CLI.Types.Errors.GovernanceActionsError
Cardano.CLI.Types.Errors.GovernanceCmdError
Cardano.CLI.Types.Errors.GovernanceCommitteeError
Cardano.CLI.Types.Errors.GovernanceQueryError
Cardano.CLI.Types.Errors.GovernanceVoteCmdError
Cardano.CLI.Types.Errors.ItnKeyConversionError
Cardano.CLI.Types.Errors.ProtocolParamsError
Expand Down Expand Up @@ -259,7 +263,7 @@ test-suite cardano-cli-test
, bech32 >= 1.1.0
, bytestring
, cardano-api:{cardano-api, internal} ^>= 8.16.1
, cardano-api-gen ^>= 8.1.1.0
, cardano-api-gen ^>= 8.2.0.0
, cardano-cli
, cardano-cli:cardano-cli-test-lib
, cardano-slotting ^>= 0.1
Expand Down
1 change: 0 additions & 1 deletion cardano-cli/src/Cardano/CLI/Commands/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Cardano.Api
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley

import Cardano.CLI.Read (singletonVotingProcedures)
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Errors.GovernanceCmdError
import Cardano.CLI.Types.Governance
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 @@ -12,6 +12,7 @@ import Cardano.Api
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.Query
import Cardano.CLI.EraBased.Commands.Governance.Vote
import Cardano.CLI.Types.Common

Expand All @@ -37,6 +38,8 @@ data EraBasedGovernanceCmds era
(GovernanceDRepCmds era)
| EraBasedGovernanceVoteCmds
(GovernanceVoteCmds era)
| EraBasedGovernanceQueryCmds
(GovernanceQueryCmds era)

renderEraBasedGovernanceCmds :: EraBasedGovernanceCmds era -> Text
renderEraBasedGovernanceCmds = \case
Expand All @@ -54,3 +57,5 @@ renderEraBasedGovernanceCmds = \case
renderGovernanceDRepCmds cmds
EraBasedGovernanceVoteCmds cmds ->
renderGovernanceVoteCmds cmds
EraBasedGovernanceQueryCmds cmds ->
renderGovernanceQueryCmds cmds
66 changes: 66 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Query.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.EraBased.Commands.Governance.Query
( GovernanceQueryCmds(..)
, EraBasedNoArgQuery(..)
, EraBasedDRepStateQuery(..)
, EraBasedDRepStakeDistributionQuery(..)
, renderGovernanceQueryCmds
) where

import Cardano.Api

import Cardano.CLI.Types.Key

import Data.Text (Text)

data GovernanceQueryCmds era
= GovernanceQueryConstitution
(ConwayEraOnwards era)
EraBasedNoArgQuery
| GovernanceQueryGovState
(ConwayEraOnwards era)
EraBasedNoArgQuery
| GovernanceQueryDRepState
(ConwayEraOnwards era)
EraBasedDRepStateQuery
| GovernanceQueryDRepStakeDistribution
(ConwayEraOnwards era)
EraBasedDRepStakeDistributionQuery
| GovernanceQueryCommitteeState
(ConwayEraOnwards era)
EraBasedNoArgQuery
deriving Show

data EraBasedNoArgQuery = EraBasedNoArgQuery
{ naSocketPath :: !SocketPath
, naConsensusModeParams :: !AnyConsensusModeParams
, naNetworkId :: !NetworkId
, naOutputFile :: !(Maybe (File () Out))
} deriving Show

data EraBasedDRepStateQuery = EraBasedDRepStateQuery
{ dsSocketPath :: !SocketPath
, dsConsensusModeParams :: !AnyConsensusModeParams
, dsNetworkId :: !NetworkId
, dsDRepKeys :: ![VerificationKeyOrHashOrFile DRepKey]
, dsOutputFile :: !(Maybe (File () Out))
} deriving Show

data EraBasedDRepStakeDistributionQuery = EraBasedDRepStakeDistributionQuery
{ dsdSocketPath :: !SocketPath
, dsdConsensusModeParams :: !AnyConsensusModeParams
, dsdNetworkId :: !NetworkId
, dsdDRepKeys :: ![VerificationKeyOrHashOrFile DRepKey]
, dsdOutputFile :: !(Maybe (File () Out))
} deriving Show

renderGovernanceQueryCmds :: GovernanceQueryCmds era -> Text
renderGovernanceQueryCmds = ("governance query " <>) . \case
GovernanceQueryConstitution{} -> "constitution"
GovernanceQueryGovState{} -> "gov-state"
GovernanceQueryDRepState{} -> "drep-state"
GovernanceQueryDRepStakeDistribution{} -> "drep-stake-distribution"
GovernanceQueryCommitteeState{} -> "committee-state"
5 changes: 2 additions & 3 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.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.Query
import Cardano.CLI.EraBased.Options.Governance.Vote
import Cardano.CLI.Types.Common

Expand All @@ -27,17 +28,15 @@ pEraBasedGovernanceCmds :: EnvCli -> CardanoEra era -> Parser (EraBasedGovernanc
pEraBasedGovernanceCmds envCli era =
asum $ catMaybes
[ pCreateMirCertificatesCmds era
, fmap EraBasedGovernanceQueryCmds <$> pGovernanceQueryCmds envCli era
, fmap EraBasedGovernanceActionCmds <$> pGovernanceActionCmds era
, fmap EraBasedGovernanceCommitteeCmds <$> pGovernanceCommitteeCmds era
, fmap EraBasedGovernanceDRepCmds <$> pGovernanceDRepCmds envCli era
, fmap EraBasedGovernanceVoteCmds <$> pGovernanceVoteCmds era
]

--------------------------------------------------------------------------------

-- Vote related


--------------------------------------------------------------------------------


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

module Cardano.CLI.EraBased.Options.Governance.Query
( pGovernanceQueryCmds
) where

import Cardano.Api

import Cardano.CLI.Environment
import Cardano.CLI.EraBased.Commands.Governance.Query
import Cardano.CLI.EraBased.Options.Common

import Options.Applicative
import qualified Options.Applicative as Opt

pGovernanceQueryCmds
:: ()
=> EnvCli
-> CardanoEra era
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryCmds env era =
subInfoParser "query"
( Opt.progDesc "Query governance-related information" )
[ pGovernanceQueryGetConstitution env era
, pGovernanceQueryGetGovState env era
, pGovernanceQueryDRepState env era
, pGovernanceQueryDRepStakeDistribution env era
, pGovernanceQueryGetCommitteeState env era
]

pGovernanceQueryGetConstitution
:: EnvCli
-> CardanoEra era
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryGetConstitution env era = do
cOn <- maybeFeatureInEra era
pure
$ subParser "constitution"
$ Opt.info (GovernanceQueryConstitution cOn <$> pEraBasedNoArgQuery env)
$ Opt.progDesc "Get the constitution"

pGovernanceQueryGetGovState
:: EnvCli
-> CardanoEra era
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryGetGovState env era = do
cOn <- maybeFeatureInEra era
pure
$ subParser "gov-state"
$ Opt.info (GovernanceQueryGovState cOn <$> pEraBasedNoArgQuery env)
$ Opt.progDesc "Get the governance state"

-- TODO DRep State and DRep Stake Distribution parsers use DRep keys to obtain DRep credentials. This only
-- makes use of 'KeyHashObj' constructor of 'Credential kr c'. Should we also support here 'ScriptHashObj'?
-- What about 'DRep c' - this means that only 'KeyHash' constructor is in use here: should also
-- 'DRepAlwaysAbstain' and 'DRepAlwaysNoConfidence' be supported here?

pGovernanceQueryDRepState
:: EnvCli
-> CardanoEra era
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryDRepState env era = do
cOn <- maybeFeatureInEra era
pure
$ subParser "drep-state"
$ Opt.info (GovernanceQueryDRepState cOn <$> pEraBasedDRepStateQuery)
$ Opt.progDesc "Get the DRep state"
where
pEraBasedDRepStateQuery :: Parser EraBasedDRepStateQuery
pEraBasedDRepStateQuery = EraBasedDRepStateQuery
<$> pSocketPath env
<*> pConsensusModeParams
<*> pNetworkId env
<*> some pDRepVerificationKeyOrHashOrFile
<*> optional pOutputFile

pGovernanceQueryDRepStakeDistribution
:: EnvCli
-> CardanoEra era
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryDRepStakeDistribution env era = do
cOn <- maybeFeatureInEra era
pure
$ subParser "drep-stake-distribution"
$ Opt.info (GovernanceQueryDRepStakeDistribution cOn <$> pEraBasedDRepStakeDistributionQuery)
$ Opt.progDesc "Get the DRep stake distribution"
where
pEraBasedDRepStakeDistributionQuery :: Parser EraBasedDRepStakeDistributionQuery
pEraBasedDRepStakeDistributionQuery = EraBasedDRepStakeDistributionQuery
<$> pSocketPath env
<*> pConsensusModeParams
<*> pNetworkId env
<*> some pDRepVerificationKeyOrHashOrFile
<*> optional pOutputFile

pGovernanceQueryGetCommitteeState
:: EnvCli
-> CardanoEra era
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryGetCommitteeState env era = do
cOn <- maybeFeatureInEra era
pure
$ subParser "committee-state"
$ Opt.info (GovernanceQueryCommitteeState cOn <$> pEraBasedNoArgQuery env)
$ Opt.progDesc "Get the committee state"

pEraBasedNoArgQuery :: EnvCli -> Parser EraBasedNoArgQuery
pEraBasedNoArgQuery env =
EraBasedNoArgQuery
<$> pSocketPath env
<*> pConsensusModeParams
<*> pNetworkId env
<*> optional pOutputFile

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 @@ -15,6 +15,7 @@ import Cardano.CLI.EraBased.Run.Governance
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.Query
import Cardano.CLI.EraBased.Run.Governance.Vote
import Cardano.CLI.Types.Errors.CmdError

Expand Down Expand Up @@ -59,3 +60,6 @@ runEraBasedGovernanceCmds = \case

EraBasedGovernanceVoteCmds cmds ->
runGovernanceVoteCmds cmds

EraBasedGovernanceQueryCmds cmds ->
runGovernanceQueryCmds cmds
7 changes: 7 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.CLI.EraBased.Run.Governance
( runGovernanceMIRCertificatePayStakeAddrs
Expand Down Expand Up @@ -90,3 +96,4 @@ runGovernanceDRepKeyGen _w vkeyPath skeyPath = firstExceptT GovernanceCmdWriteFi
skeyDesc = "Delegate Representative Signing Key"
vkeyDesc :: TextEnvelopeDescr
vkeyDesc = "Delegate Representative Verification Key"

Loading

0 comments on commit ac961e4

Please sign in to comment.