Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix era mismatch error in stake-address-info #490

Merged
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
10 changes: 4 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ module Cardano.CLI.EraBased.Run.Query

, DelegationsAndRewards(..)
, renderQueryCmdError
, renderLocalStateQueryError
, renderOpCertIntervalInformation
, percentage
) where
Expand Down Expand Up @@ -821,11 +820,10 @@ runQueryStakeAddressInfoCmd
& onLeft (left . QueryCmdUnsupportedNtcVersion)
& onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError)

ceo <- requireEon ConwayEra era

stakeVoteDelegatees <- lift (queryStakeVoteDelegatees ceo stakeAddr)
& onLeft (left . QueryCmdUnsupportedNtcVersion)
& onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError)
stakeVoteDelegatees <- monoidForEraInEonA era $ \ceo ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I didn't know about monoidForEraInEonA.

lift (queryStakeVoteDelegatees ceo stakeAddr)
& onLeft (left . QueryCmdUnsupportedNtcVersion)
& onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError)

return $ do
writeStakeAddressInfo
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ data QueryCmdError
renderQueryCmdError :: QueryCmdError -> Doc ann
renderQueryCmdError = \case
QueryCmdLocalStateQueryError lsqErr ->
renderLocalStateQueryError lsqErr
prettyError lsqErr
QueryCmdWriteFileError fileErr ->
prettyError fileErr
QueryCmdHelpersError helpersErr ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@
module Cardano.CLI.Types.Errors.QueryCmdLocalStateQueryError
( QueryCmdLocalStateQueryError(..)
, mkEraMismatchError
, renderLocalStateQueryError
) where

import Cardano.Api (Error (..))
import Cardano.Api.Pretty

import Cardano.CLI.Types.Errors.NodeEraMismatchError
import Ouroboros.Consensus.Cardano.Block (EraMismatch (..))

import Prettyprinter ((<+>))

-- | An error that can occur while querying a node's local state.
newtype QueryCmdLocalStateQueryError
= EraMismatchError EraMismatch
-- ^ A query from a certain era was applied to a ledger from a different
-- era.
-- ^ A query from a certain era was applied to a ledger from a different era.
deriving (Eq, Show)

mkEraMismatchError :: NodeEraMismatchError -> QueryCmdLocalStateQueryError
mkEraMismatchError NodeEraMismatchError{nodeEra, era} =
EraMismatchError EraMismatch{ ledgerEraName = docToText $ pretty nodeEra
, otherEraName = docToText $ pretty era}

renderLocalStateQueryError :: QueryCmdLocalStateQueryError -> Doc ann
renderLocalStateQueryError = \case
EraMismatchError err ->
"A query from a certain era was applied to a ledger from a different era: " <> pshow err
instance Error QueryCmdLocalStateQueryError where
prettyError = \case
EraMismatchError EraMismatch{ledgerEraName, otherEraName} ->
"A query from" <+> pretty otherEraName <+> "era was applied to a ledger from a different era:" <+> pretty ledgerEraName