Skip to content

Commit

Permalink
Use ToJSON instance for getting era in query tip command
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Mar 31, 2021
1 parent 6732b28 commit 1340955
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
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

0 comments on commit 1340955

Please sign in to comment.