Skip to content

Commit

Permalink
Implement "query proposals"
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Nov 28, 2024
1 parent 8216024 commit bf6f494
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Cardano.CLI.EraBased.Commands.Query
, QueryProtocolParametersCmdArgs (..)
, QueryTipCmdArgs (..)
, QueryStakePoolsCmdArgs (..)
, QueryProposalsCmdArgs (..)
, QueryStakeDistributionCmdArgs (..)
, QueryStakeAddressInfoCmdArgs (..)
, QueryUTxOCmdArgs (..)
Expand All @@ -31,6 +32,7 @@ module Cardano.CLI.EraBased.Commands.Query
)
where

import qualified Cardano.Api.Ledger as L
import qualified Cardano.Api.Network as Consensus
import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..))

Expand Down Expand Up @@ -65,6 +67,7 @@ data QueryCmds era
| QuerySPOStakeDistributionCmd !(QuerySPOStakeDistributionCmdArgs era)
| QueryCommitteeMembersStateCmd !(QueryCommitteeMembersStateCmdArgs era)
| QueryTreasuryValueCmd !(QueryTreasuryValueCmdArgs era)
| QueryProposalsCmd !(QueryProposalsCmdArgs era)
deriving (Generic, Show)

data QueryLeadershipScheduleCmdArgs = QueryLeadershipScheduleCmdArgs
Expand Down Expand Up @@ -239,6 +242,19 @@ data QueryDRepStateCmdArgs era = QueryDRepStateCmdArgs
}
deriving Show

-- TODO @smelc Add a record sharing the common fields of all these requests

data QueryProposalsCmdArgs era = QueryProposalsCmdArgs
{ eon :: !(ConwayEraOnwards era)
, nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
, govActionIds :: !(AllOrOnly (L.GovActionId L.StandardCrypto))
, target :: !(Consensus.Target ChainPoint)
, mOutFile :: !(Maybe (File () Out))
}
deriving Show

data QueryDRepStakeDistributionCmdArgs era = QueryDRepStakeDistributionCmdArgs
{ eon :: !(ConwayEraOnwards era)
, nodeSocketPath :: !SocketPath
Expand Down Expand Up @@ -316,6 +332,8 @@ renderQueryCmds = \case
"query slot-number"
QueryRefScriptSizeCmd{} ->
"query ref-script-size"
QueryProposalsCmd{} ->
"query proposals"
QueryConstitutionCmd{} ->
"constitution"
QueryGovStateCmd{} ->
Expand Down
27 changes: 27 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3483,6 +3483,33 @@ pAllOrOnlySPOHashSource = pAll <|> pOnly
, Opt.help "Query for all DReps."
]

pAllOrOnlyGovActionIds
:: ()
=> ConwayEraOnwards era
-> Parser (AllOrOnly (L.GovActionId (L.StandardCrypto)))

Check warning

Code scanning / HLint

Redundant bracket Warning

cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs:3489:39-56: Warning: Redundant bracket
  
Found:
  (L.StandardCrypto)
  
Perhaps:
  L.StandardCrypto
pAllOrOnlyGovActionIds era = pAll <|> pOnly
where
pOnly = Only <$> (pGovActionIds era)

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs:3492:20-38: Suggestion: Redundant bracket
  
Found:
  Only <$> (pGovActionIds era)
  
Perhaps:
  Only <$> pGovActionIds era
pAll =
Opt.flag' All $
mconcat
[ Opt.long "all-proposals"
, Opt.help "Query for all governance proposals."
]

pGovActionIds
:: forall era
. ()
=> ConwayEraOnwards era
-> Parser [L.GovActionId (L.StandardCrypto)]

Check warning

Code scanning / HLint

Redundant bracket Warning

cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs:3504:28-45: Warning: Redundant bracket
  
Found:
  (L.StandardCrypto)
  
Perhaps:
  L.StandardCrypto
pGovActionIds era = conwayEraOnwardsConstraints era (some pLedgerGovernanceAction)
where
pLedgerGovernanceAction :: Parser (L.GovActionId L.StandardCrypto)
pLedgerGovernanceAction = uncurry L.GovActionId <$> pairParser

pairParser :: Parser (L.TxId L.StandardCrypto, L.GovActionIx)
pairParser = (bimap toShelleyTxId L.GovActionIx) <$> pGovernanceActionId

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs:3511:16-50: Suggestion: Redundant bracket
  
Found:
  (bimap toShelleyTxId L.GovActionIx) <$> pGovernanceActionId
  
Perhaps:
  bimap toShelleyTxId L.GovActionIx <$> pGovernanceActionId

pDRepVerificationKeyHash :: Parser (Hash DRepKey)
pDRepVerificationKeyHash =
Opt.option (rBech32KeyHash AsDRepKey <|> rHexHash AsDRepKey Nothing) $
Expand Down
23 changes: 23 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ pQueryCmds era envCli =
, pQuerySPOStakeDistributionCmd era envCli
, pQueryGetCommitteeStateCmd era envCli
, pQueryTreasuryValueCmd era envCli
, pQueryProposalsCmd era envCli
]

pQueryProtocolParametersCmd :: EnvCli -> Parser (QueryCmds era)
Expand Down Expand Up @@ -565,6 +566,28 @@ pQueryDRepStakeDistributionCmd era envCli = do
<*> pTarget era
<*> optional pOutputFile

pQueryProposalsCmd
:: ()
=> ShelleyBasedEra era
-> EnvCli
-> Maybe (Parser (QueryCmds era))
pQueryProposalsCmd era envCli = do
w <- forShelleyBasedEraMaybeEon era
pure $
subParser "proposals" $
Opt.info (QueryProposalsCmd <$> pQueryProposalsCmdArgs w) $
Opt.progDesc "Get the governance proposals."
where
pQueryProposalsCmdArgs :: ConwayEraOnwards era -> Parser (QueryProposalsCmdArgs era)
pQueryProposalsCmdArgs w =
QueryProposalsCmdArgs w
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> (pAllOrOnlyGovActionIds w)

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs:542:11-36: Suggestion: Redundant bracket
  
Found:
  QueryProposalsCmdArgs w <$> pSocketPath envCli
    <> pConsensusModeParams
    <> pNetworkId envCli
    <> (pAllOrOnlyGovActionIds w)
  
Perhaps:
  QueryProposalsCmdArgs w <$> pSocketPath envCli
    <> pConsensusModeParams
    <> pNetworkId envCli
    <> pAllOrOnlyGovActionIds w
<*> pTarget era
<*> optional pOutputFile

pQuerySPOStakeDistributionCmd
:: ()
=> ShelleyBasedEra era
Expand Down
26 changes: 26 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import qualified Data.List as List
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Proxy (Proxy (..))
import qualified Data.Sequence as Seq
import Data.Set (Set)
import qualified Data.Set as Set
import Data.String
Expand Down Expand Up @@ -117,6 +118,7 @@ runQueryCmds = \case
Cmd.QuerySPOStakeDistributionCmd args -> runQuerySPOStakeDistribution args
Cmd.QueryCommitteeMembersStateCmd args -> runQueryCommitteeMembersState args
Cmd.QueryTreasuryValueCmd args -> runQueryTreasuryValue args
Cmd.QueryProposalsCmd args -> runQueryProposals args

runQueryProtocolParametersCmd
:: ()
Expand Down Expand Up @@ -1738,6 +1740,30 @@ runQueryTreasuryValue
writeLazyByteStringFile outFile $
LBS.pack treasuryString

runQueryProposals
:: Cmd.QueryProposalsCmdArgs era
-> ExceptT QueryCmdError IO ()
runQueryProposals
Cmd.QueryProposalsCmdArgs
{ Cmd.eon
, Cmd.nodeSocketPath
, Cmd.consensusModeParams
, Cmd.networkId
, Cmd.govActionIds = govActionIds'
, Cmd.target
, Cmd.mOutFile
} = conwayEraOnwardsConstraints eon $ do
let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath

let govActionIds = case govActionIds' of
All -> []
Only l -> l

govActionStates :: (Seq.Seq (L.GovActionState (ShelleyLedgerEra era))) <-
runQuery localNodeConnInfo target $ queryProposals eon $ Set.fromList govActionIds

writeOutput mOutFile govActionStates

runQuery
:: LocalNodeConnectInfo
-> Consensus.Target ChainPoint
Expand Down

0 comments on commit bf6f494

Please sign in to comment.