From 13409559ae75d19ca39425d43aef163fefae9c43 Mon Sep 17 00:00:00 2001 From: John Ky Date: Wed, 31 Mar 2021 19:33:10 +1100 Subject: [PATCH] Use ToJSON instance for getting era in query tip command --- cardano-api/src/Cardano/Api/Eras.hs | 3 +++ cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs | 13 +------------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/cardano-api/src/Cardano/Api/Eras.hs b/cardano-api/src/Cardano/Api/Eras.hs index 0c28fc2d46d..e5a9036a712 100644 --- a/cardano-api/src/Cardano/Api/Eras.hs +++ b/cardano-api/src/Cardano/Api/Eras.hs @@ -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. -- diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs index 53da0726e39..212d402e3ec 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs @@ -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