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

Use ToJSON instance for getting era in query tip command #2562

Merged
merged 1 commit into from
Mar 31, 2021
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
3 changes: 3 additions & 0 deletions cardano-api/src/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ instance Bounded AnyCardanoEra where
minBound = AnyCardanoEra ByronEra
maxBound = AnyCardanoEra MaryEra

instance ToJSON AnyCardanoEra where
toJSON (AnyCardanoEra era) = toJSON era

-- | Like the 'AnyCardanoEra' constructor but does not demand a 'IsCardanoEra'
-- class constraint.
--
Expand Down
13 changes: 1 addition & 12 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,13 @@ runQueryTip (AnyConsensusModeParams cModeParams) network mOutFile = do
mEpoch <- mEpochQuery anyEra consensusMode localNodeConnInfo
tip <- liftIO $ getLocalChainTip localNodeConnInfo
let output = encodePretty
. toObject "era" (Just (eraString anyEra))
. toObject "era" (Just (toJSON anyEra))
. toObject "epoch" mEpoch
$ toJSON tip
case mOutFile of
Just (OutputFile fpath) -> liftIO $ LBS.writeFile fpath output
Nothing -> liftIO $ LBS.putStrLn output
where
eraString
:: AnyCardanoEra
-> String
eraString (AnyCardanoEra era) =
case cardanoEraStyle era of
LegacyByronEra -> "byron"
ShelleyBasedEra sbe -> case sbe of
ShelleyBasedEraShelley -> "shelley"
ShelleyBasedEraAllegra -> "allegra"
ShelleyBasedEraMary -> "mary"

mEpochQuery
:: AnyCardanoEra
-> ConsensusMode mode
Expand Down