Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Query/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Cardano.CLI.EraBased.Query.Command
, QuerySPOStakeDistributionCmdArgs (..)
, QueryTreasuryValueCmdArgs (..)
, QueryLedgerPeerSnapshotCmdArgs (..)
, QueryStakePoolDefaultVoteCmdArgs (..)
, renderQueryCmds
, IncludeStake (..)
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{} ->
Expand Down Expand Up @@ -307,6 +317,8 @@ renderQueryCmds = \case
"committee-state"
QueryTreasuryValueCmd{} ->
"treasury"
QueryStakePoolDefaultVoteCmd{} ->
"query stake-pool-default-vote"

renderTxMempoolQuery :: TxMempoolQuery -> Text
renderTxMempoolQuery = \case
Expand Down
22 changes: 22 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Query/Option.hs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ pQueryCmds era envCli =
, pQueryGetCommitteeStateCmd era envCli
, pQueryTreasuryValueCmd era envCli
, pQueryProposalsCmd era envCli
, pQueryStakePoolDefaultVote era envCli
]

pQueryProtocolParametersCmd :: EnvCli -> Parser (QueryCmds era)
Expand Down Expand Up @@ -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
. ()
Expand Down
31 changes: 31 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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
:: ()
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions cardano-cli/src/Cardano/CLI/Orphan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 38 additions & 0 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -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
Loading