diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 9b38b7e770..3889ec047e 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -244,6 +244,7 @@ library cardano-data >=1.1, cardano-git-rev ^>=0.2.2, cardano-ledger-api, + cardano-ledger-conway, cardano-ledger-core, cardano-ping ^>=0.8, cardano-prelude, diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Query/Command.hs b/cardano-cli/src/Cardano/CLI/EraBased/Query/Command.hs index c0afb37c4c..960c1b6439 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Query/Command.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Query/Command.hs @@ -29,6 +29,7 @@ module Cardano.CLI.EraBased.Query.Command , QuerySPOStakeDistributionCmdArgs (..) , QueryTreasuryValueCmdArgs (..) , QueryLedgerPeerSnapshotCmdArgs (..) + , QueryStakePoolDefaultVoteCmdArgs (..) , renderQueryCmds , IncludeStake (..) ) @@ -74,6 +75,7 @@ data QueryCmds era | QueryTreasuryValueCmd !(QueryTreasuryValueCmdArgs era) | QueryProposalsCmd !(QueryProposalsCmdArgs era) | QueryLedgerPeerSnapshotCmd !QueryLedgerPeerSnapshotCmdArgs + | QueryStakePoolDefaultVoteCmd !(QueryStakePoolDefaultVoteCmdArgs era) deriving (Generic, Show) -- | Fields that are common to most queries @@ -253,6 +255,14 @@ data QueryTreasuryValueCmdArgs era = QueryTreasuryValueCmdArgs } deriving Show +data QueryStakePoolDefaultVoteCmdArgs era = QueryStakePoolDefaultVoteCmdArgs + { eon :: !(ConwayEraOnwards era) + , commons :: !QueryCommons + , spoHashSources :: !SPOHashSource + , mOutFile :: !(Maybe (File () Out)) + } + deriving Show + renderQueryCmds :: QueryCmds era -> Text renderQueryCmds = \case QueryLeadershipScheduleCmd{} -> @@ -307,6 +317,8 @@ renderQueryCmds = \case "committee-state" QueryTreasuryValueCmd{} -> "treasury" + QueryStakePoolDefaultVoteCmd{} -> + "query stake-pool-default-vote" renderTxMempoolQuery :: TxMempoolQuery -> Text renderTxMempoolQuery = \case diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Query/Option.hs b/cardano-cli/src/Cardano/CLI/EraBased/Query/Option.hs index 022b624e27..e685fd4822 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Query/Option.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Query/Option.hs @@ -338,6 +338,7 @@ pQueryCmds era envCli = , pQueryGetCommitteeStateCmd era envCli , pQueryTreasuryValueCmd era envCli , pQueryProposalsCmd era envCli + , pQueryStakePoolDefaultVote era envCli ] pQueryProtocolParametersCmd :: EnvCli -> Parser (QueryCmds era) @@ -764,6 +765,27 @@ pQueryTreasuryValueCmd era envCli = do <$> pQueryCommons era envCli <*> pMaybeOutputFile +pQueryStakePoolDefaultVote + :: () + => ShelleyBasedEra era + -> EnvCli + -> Maybe (Parser (QueryCmds era)) +pQueryStakePoolDefaultVote era envCli = do + w <- forShelleyBasedEraMaybeEon era + pure $ + Opt.hsubparser $ + commandWithMetavar "stake-pool-default-vote" $ + Opt.info (QueryStakePoolDefaultVoteCmd <$> pQueryStakePoolDefaultVoteCmdArgs w) $ + Opt.progDesc "Get the stake pool default vote." + where + pQueryStakePoolDefaultVoteCmdArgs + :: ConwayEraOnwards era -> Parser (QueryStakePoolDefaultVoteCmdArgs era) + pQueryStakePoolDefaultVoteCmdArgs w = + QueryStakePoolDefaultVoteCmdArgs w + <$> pQueryCommons era envCli + <*> pSPOHashSource + <*> pMaybeOutputFile + pQueryNoArgCmdArgs :: forall era . () diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs b/cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs index 62ccb93f41..16c9db1f7b 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs @@ -58,6 +58,7 @@ import Cardano.CLI.Type.Key import Cardano.CLI.Type.Output (QueryDRepStateOutput (..)) import Cardano.CLI.Type.Output qualified as O import Cardano.Crypto.Hash (hashToBytesAsHex) +import Cardano.Ledger.Api.State.Query qualified as L import Cardano.Slotting.EpochInfo (EpochInfo (..), epochInfoSlotToUTCTime, hoistEpochInfo) import Cardano.Slotting.Time (RelativeTime (..), toRelativeTime) @@ -67,6 +68,7 @@ import Data.Aeson qualified as A import Data.Aeson.Encode.Pretty (encodePretty) import Data.Bifunctor (Bifunctor (..)) import Data.ByteString.Base16 qualified as Base16 +import Data.ByteString.Char8 qualified as C8 import Data.ByteString.Lazy qualified as BS import Data.ByteString.Lazy.Char8 qualified as LBS import Data.Coerce (coerce) @@ -123,6 +125,7 @@ runQueryCmds = \case Cmd.QueryCommitteeMembersStateCmd args -> runQueryCommitteeMembersState args Cmd.QueryTreasuryValueCmd args -> runQueryTreasuryValue args Cmd.QueryProposalsCmd args -> runQueryProposals args + Cmd.QueryStakePoolDefaultVoteCmd args -> runQueryStakePoolDefaultVote args runQueryProtocolParametersCmd :: () @@ -1848,6 +1851,34 @@ runQueryProposals writeOutput mOutFile govActionStates +runQueryStakePoolDefaultVote + :: Cmd.QueryStakePoolDefaultVoteCmdArgs era + -> ExceptT QueryCmdError IO () +runQueryStakePoolDefaultVote + Cmd.QueryStakePoolDefaultVoteCmdArgs + { Cmd.eon + , Cmd.commons = + Cmd.QueryCommons + { Cmd.nodeConnInfo + , Cmd.target + } + , Cmd.spoHashSources + , Cmd.mOutFile + } = conwayEraOnwardsConstraints eon $ do + let spoFromSource = firstExceptT QueryCmdSPOKeyError . readSPOCredential + spo <- spoFromSource spoHashSources + + defVote :: L.DefaultVote <- + runQuery nodeConnInfo target $ queryStakePoolDefaultVote eon spo + + let defVoteJson = Aeson.encode defVote + case mOutFile of + Nothing -> + liftIO . putStrLn . C8.unpack $ LBS.toStrict defVoteJson + Just outFile -> + firstExceptT QueryCmdWriteFileError . ExceptT $ + writeLazyByteStringFile outFile defVoteJson + runQuery :: LocalNodeConnectInfo -> Consensus.Target ChainPoint diff --git a/cardano-cli/src/Cardano/CLI/Orphan.hs b/cardano-cli/src/Cardano/CLI/Orphan.hs index e8f8fe81ba..7627ce1719 100644 --- a/cardano-cli/src/Cardano/CLI/Orphan.hs +++ b/cardano-cli/src/Cardano/CLI/Orphan.hs @@ -13,10 +13,18 @@ import Cardano.Api.Ledger qualified as L import Cardano.Api.Shelley (VotesMergingConflict, scriptDataToJsonDetailedSchema) import Cardano.Ledger.CertState qualified as L +import Cardano.Ledger.Conway.Governance qualified as L import Cardano.Ledger.State qualified as L import Data.Aeson +instance ToJSON L.DefaultVote where + toJSON defaultVote = + case defaultVote of + L.DefaultNo -> String "DefaultNo" + L.DefaultAbstain -> String "DefaultAbstain" + L.DefaultNoConfidence -> String "DefaultNoConfidence" + instance Error (VotesMergingConflict era) where prettyError = pretty . show diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index 5e600eb075..8a053c3e00 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -6545,6 +6545,7 @@ Usage: cardano-cli conway query | committee-state | treasury | proposals + | stake-pool-default-vote ) Node query commands. Will query the local node whose Unix domain socket is @@ -6988,6 +6989,24 @@ Usage: cardano-cli conway query proposals [--cardano-mode [--epoch-slots SLOTS]] submitted during the current epoch are excluded, as they cannot be ratified until the next epoch. +Usage: cardano-cli conway query stake-pool-default-vote + [--cardano-mode + [--epoch-slots SLOTS]] + ( --mainnet + | --testnet-magic NATURAL + ) + --socket-path SOCKET_PATH + [ --volatile-tip + | --immutable-tip + ] + ( --spo-verification-key STRING + | --spo-verification-key-file FILEPATH + | --spo-key-hash HASH + ) + [--out-file FILEPATH] + + Get the stake pool default vote. + Usage: cardano-cli conway stake-address ( key-gen | key-hash @@ -8670,6 +8689,7 @@ Usage: cardano-cli latest query | committee-state | treasury | proposals + | stake-pool-default-vote ) Node query commands. Will query the local node whose Unix domain socket is @@ -9113,6 +9133,24 @@ Usage: cardano-cli latest query proposals [--cardano-mode [--epoch-slots SLOTS]] submitted during the current epoch are excluded, as they cannot be ratified until the next epoch. +Usage: cardano-cli latest query stake-pool-default-vote + [--cardano-mode + [--epoch-slots SLOTS]] + ( --mainnet + | --testnet-magic NATURAL + ) + --socket-path SOCKET_PATH + [ --volatile-tip + | --immutable-tip + ] + ( --spo-verification-key STRING + | --spo-verification-key-file FILEPATH + | --spo-key-hash HASH + ) + [--out-file FILEPATH] + + Get the stake pool default vote. + Usage: cardano-cli latest stake-address ( key-gen | key-hash diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_query.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_query.cli index 5138a965f7..83e36aef28 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_query.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_query.cli @@ -25,6 +25,7 @@ Usage: cardano-cli conway query | committee-state | treasury | proposals + | stake-pool-default-vote ) Node query commands. Will query the local node whose Unix domain socket is @@ -78,3 +79,4 @@ Available commands: ratification. Proposals submitted during the current epoch are excluded, as they cannot be ratified until the next epoch. + stake-pool-default-vote Get the stake pool default vote. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_query_stake-pool-default-vote.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_query_stake-pool-default-vote.cli new file mode 100644 index 0000000000..2290bc7327 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_query_stake-pool-default-vote.cli @@ -0,0 +1,43 @@ +Usage: cardano-cli conway query stake-pool-default-vote + [--cardano-mode + [--epoch-slots SLOTS]] + ( --mainnet + | --testnet-magic NATURAL + ) + --socket-path SOCKET_PATH + [ --volatile-tip + | --immutable-tip + ] + ( --spo-verification-key STRING + | --spo-verification-key-file FILEPATH + | --spo-key-hash HASH + ) + [--out-file FILEPATH] + + Get the stake pool default vote. + +Available options: + --cardano-mode For talking to a node running in full Cardano mode + (default). + --epoch-slots SLOTS The number of slots per epoch for the Byron era. + (default: 21600) + --mainnet Use the mainnet magic id. This overrides the + CARDANO_NODE_NETWORK_ID environment variable + --testnet-magic NATURAL Specify a testnet magic id. This overrides the + CARDANO_NODE_NETWORK_ID environment variable + --socket-path SOCKET_PATH + Path to the node socket. This overrides the + CARDANO_NODE_SOCKET_PATH environment variable. The + argument is optional if CARDANO_NODE_SOCKET_PATH is + defined and mandatory otherwise. + --volatile-tip Use the volatile tip as a target. (This is the + default) + --immutable-tip Use the immutable tip as a target. + --spo-verification-key STRING + SPO verification key (Bech32 or hex-encoded). + --spo-verification-key-file FILEPATH + Filepath of the SPO verification key. + --spo-key-hash HASH SPO verification key hash (either Bech32-encoded or + hex-encoded). + --out-file FILEPATH Optional output file. Default is to write to stdout. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_query.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_query.cli index bc007e7fc6..372fcd369a 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_query.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_query.cli @@ -25,6 +25,7 @@ Usage: cardano-cli latest query | committee-state | treasury | proposals + | stake-pool-default-vote ) Node query commands. Will query the local node whose Unix domain socket is @@ -78,3 +79,4 @@ Available commands: ratification. Proposals submitted during the current epoch are excluded, as they cannot be ratified until the next epoch. + stake-pool-default-vote Get the stake pool default vote. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_query_stake-pool-default-vote.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_query_stake-pool-default-vote.cli new file mode 100644 index 0000000000..b17b87b45a --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_query_stake-pool-default-vote.cli @@ -0,0 +1,43 @@ +Usage: cardano-cli latest query stake-pool-default-vote + [--cardano-mode + [--epoch-slots SLOTS]] + ( --mainnet + | --testnet-magic NATURAL + ) + --socket-path SOCKET_PATH + [ --volatile-tip + | --immutable-tip + ] + ( --spo-verification-key STRING + | --spo-verification-key-file FILEPATH + | --spo-key-hash HASH + ) + [--out-file FILEPATH] + + Get the stake pool default vote. + +Available options: + --cardano-mode For talking to a node running in full Cardano mode + (default). + --epoch-slots SLOTS The number of slots per epoch for the Byron era. + (default: 21600) + --mainnet Use the mainnet magic id. This overrides the + CARDANO_NODE_NETWORK_ID environment variable + --testnet-magic NATURAL Specify a testnet magic id. This overrides the + CARDANO_NODE_NETWORK_ID environment variable + --socket-path SOCKET_PATH + Path to the node socket. This overrides the + CARDANO_NODE_SOCKET_PATH environment variable. The + argument is optional if CARDANO_NODE_SOCKET_PATH is + defined and mandatory otherwise. + --volatile-tip Use the volatile tip as a target. (This is the + default) + --immutable-tip Use the immutable tip as a target. + --spo-verification-key STRING + SPO verification key (Bech32 or hex-encoded). + --spo-verification-key-file FILEPATH + Filepath of the SPO verification key. + --spo-key-hash HASH SPO verification key hash (either Bech32-encoded or + hex-encoded). + --out-file FILEPATH Optional output file. Default is to write to stdout. + -h,--help Show this help text