-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e5538a
commit ac961e4
Showing
28 changed files
with
1,057 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Query.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Query.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.