Skip to content

Commit

Permalink
No-args queries
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Aug 25, 2023
1 parent 5e98c87 commit 3a8e53b
Show file tree
Hide file tree
Showing 24 changed files with 859 additions and 101 deletions.
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
55 changes: 48 additions & 7 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Query.hs
Original file line number Diff line number Diff line change
@@ -1,27 +1,68 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE StandaloneDeriving #-}

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

import Cardano.Api
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley

import Cardano.CLI.Types.Common (Constitution, VerificationKeyFile)
import Cardano.CLI.Types.Key

import Data.Set
import Data.Text (Text)
import Data.Word

data GovernanceQueryCmds era
= GovernanceQueryGetConstitution
= 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] -- TODO
, dsdOutputFile :: !(Maybe (File () Out))
} deriving Show

renderGovernanceQueryCmds :: GovernanceQueryCmds era -> Text
renderGovernanceQueryCmds = \case
GovernanceQueryGetConstitution{} -> "get-constitution"
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 (pGovernanceQueryCmds)
import Cardano.CLI.EraBased.Options.Governance.Vote
import Cardano.CLI.Types.Common

Expand All @@ -31,13 +32,11 @@ pEraBasedGovernanceCmds envCli era =
, fmap EraBasedGovernanceCommitteeCmds <$> pGovernanceCommitteeCmds era
, fmap EraBasedGovernanceDRepCmds <$> pGovernanceDRepCmds envCli era
, fmap EraBasedGovernanceVoteCmds <$> pGovernanceVoteCmds era
, fmap EraBasedGovernanceQueryCmds <$> pGovernanceQueryCmds envCli era
]

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

-- Vote related


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


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

module Cardano.CLI.EraBased.Options.Governance.Query
( pGovernanceQueryCmds
Expand All @@ -10,6 +9,7 @@ import Cardano.Api
import Cardano.Api.Ledger
import Cardano.Api.Shelley

import Cardano.CLI.Environment
import Cardano.CLI.EraBased.Commands.Governance.Actions
import Cardano.CLI.EraBased.Commands.Governance.Query
import Cardano.CLI.EraBased.Options.Common
Expand All @@ -25,6 +25,95 @@ import qualified Options.Applicative as Opt

pGovernanceQueryCmds
:: ()
=> CardanoEra era
=> EnvCli
-> CardanoEra era
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryCmds era = undefined
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"

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
Loading

0 comments on commit 3a8e53b

Please sign in to comment.