@@ -52,6 +52,7 @@ import Cardano.Binary qualified as CBOR
5252import Cardano.CLI.EraBased.Genesis.Internal.Common
5353import Cardano.CLI.EraBased.Query.Command qualified as Cmd
5454import Cardano.CLI.Helper
55+ import Cardano.CLI.Json.Encode qualified as Json
5556import Cardano.CLI.Read
5657 ( getHashFromStakePoolKeyHashSource
5758 )
@@ -69,7 +70,7 @@ import Cardano.Slotting.Time (RelativeTime (..), toRelativeTime)
6970import Control.Monad (forM , forM_ , join )
7071import Data.Aeson as Aeson
7172import Data.Aeson qualified as A
72- import Data.Aeson.Encode.Pretty ( encodePretty )
73+ import Data.Aeson.Encode.Pretty qualified as Aeson
7374import Data.Bifunctor (Bifunctor (.. ))
7475import Data.ByteString.Base16.Lazy qualified as Base16
7576import Data.ByteString.Char8 qualified as C8
@@ -92,7 +93,6 @@ import Data.Text.Encoding qualified as Text
9293import Data.Text.IO qualified as T
9394import Data.Text.Lazy.IO qualified as LT
9495import Data.Time.Clock
95- import Data.Yaml qualified as Yaml
9696import GHC.Exts (IsList (.. ))
9797import GHC.Generics
9898import Lens.Micro ((^.) )
@@ -160,7 +160,7 @@ runQueryProtocolParametersCmd
160160 firstExceptT QueryCmdWriteFileError . newExceptT $
161161 writeLazyByteStringOutput mOutFile' $
162162 shelleyBasedEraConstraints sbe $
163- encodePretty pparams
163+ Aeson. encodePretty pparams
164164
165165-- | Calculate the percentage sync rendered as text: @min 1 (tipTime/nowTime)@
166166percentage
@@ -290,7 +290,7 @@ runQueryTipCmd
290290
291291 firstExceptT QueryCmdWriteFileError . newExceptT $
292292 writeLazyByteStringOutput mOutFile $
293- encodePretty localStateOutput
293+ Aeson. encodePretty localStateOutput
294294
295295-- | Query the UTxO, filtered by a given set of addresses, from a Shelley node
296296-- via the local state query protocol.
@@ -387,7 +387,7 @@ runQueryKesPeriodInfoCmd
387387 renderOpCertNodeAndOnDiskCounterInformation (unFile nodeOpCertFp) counterInformation
388388
389389 let qKesInfoOutput = createQueryKesPeriodInfoOutput opCertIntervalInformation counterInformation eInfo gParams
390- kesPeriodInfoJSON = encodePretty qKesInfoOutput
390+ kesPeriodInfoJSON = Aeson. encodePretty qKesInfoOutput
391391
392392 liftIO $ LBS. putStrLn kesPeriodInfoJSON
393393 forM_
@@ -681,7 +681,7 @@ runQueryTxMempoolCmd
681681 result <- liftIO $ queryTxMonitoringLocal nodeConnInfo localQuery
682682 firstExceptT QueryCmdWriteFileError . newExceptT $
683683 writeLazyByteStringOutput mOutFile $
684- encodePretty result
684+ Aeson. encodePretty result
685685
686686runQuerySlotNumberCmd
687687 :: ()
@@ -883,13 +883,14 @@ runQueryLedgerPeerSnapshot
883883 Left (bs :: LBS. ByteString ) -> do
884884 firstExceptT QueryCmdHelpersError $ pPrintCBOR bs
885885 Right (snapshot :: LedgerPeerSnapshot ) -> do
886- outputContents <-
887- outputFormat
888- & ( id
889- . Vary. on (\ FormatJson -> pure $ encodePretty snapshot)
890- . Vary. on (\ FormatYaml -> pure $ LBS. fromStrict $ Yaml. encode snapshot)
891- $ Vary. exhaustiveCase
892- )
886+ let outputContents =
887+ outputFormat
888+ & ( id
889+ . Vary. on (\ FormatJson -> Json. encodeJson)
890+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
891+ $ Vary. exhaustiveCase
892+ )
893+ $ snapshot
893894
894895 let writeOutputContents =
895896 case mOutFile of
@@ -1047,7 +1048,7 @@ writeStakeAddressInfo
10471048 )
10481049 mOutFile =
10491050 firstExceptT QueryCmdWriteFileError . newExceptT $
1050- writeLazyByteStringOutput mOutFile (encodePretty $ jsonInfo sbe)
1051+ writeLazyByteStringOutput mOutFile (Aeson. encodePretty $ jsonInfo sbe)
10511052 where
10521053 jsonInfo :: ShelleyBasedEra era -> [Aeson. Value ]
10531054 jsonInfo =
@@ -1114,7 +1115,7 @@ writeStakeSnapshots mOutFile qState = do
11141115 & onLeft (left . QueryCmdStakeSnapshotDecodeError )
11151116
11161117 -- Calculate the three pool and active stake values for the given pool
1117- liftIO . maybe LBS. putStrLn (LBS. writeFile . unFile) mOutFile $ encodePretty snapshot
1118+ liftIO . maybe LBS. putStrLn (LBS. writeFile . unFile) mOutFile $ Aeson. encodePretty snapshot
11181119
11191120-- | This function obtains the pool parameters, equivalent to the following jq query on the output of query ledger-state
11201121-- .nesEs.esLState.lsDPState.dpsPState.psStakePoolParams.<pool_id>
@@ -1154,7 +1155,7 @@ writePoolState mOutFile serialisedCurrentEpochState = do
11541155
11551156 firstExceptT QueryCmdWriteFileError . newExceptT $
11561157 writeLazyByteStringOutput mOutFile $
1157- encodePretty poolStates
1158+ Aeson. encodePretty poolStates
11581159
11591160writeProtocolState
11601161 :: ShelleyBasedEra era
@@ -1195,7 +1196,7 @@ writeProtocolState sbe mOutFile ps@(ProtocolState pstate) =
11951196 decodePState ps' =
11961197 case decodeProtocolState ps' of
11971198 Left (bs, _) -> firstExceptT QueryCmdHelpersError $ pPrintCBOR bs
1198- Right chainDepstate -> liftIO . LBS. putStrLn $ encodePretty chainDepstate
1199+ Right chainDepstate -> liftIO . LBS. putStrLn $ Aeson. encodePretty chainDepstate
11991200
12001201writeFilteredUTxOs
12011202 :: Api. ShelleyBasedEra era
@@ -1211,7 +1212,7 @@ writeFilteredUTxOs sbe format mOutFile utxo =
12111212 $ format
12121213 & ( id
12131214 . Vary. on (\ FormatCbor -> Base16. encode . CBOR. serialize $ toLedgerUTxO sbe utxo)
1214- . Vary. on (\ FormatJson -> encodePretty utxo)
1215+ . Vary. on (\ FormatJson -> Json. encodeJson utxo)
12151216 . Vary. on (\ FormatText -> strictTextToLazyBytestring $ filteredUTxOsToText sbe utxo)
12161217 $ Vary. exhaustiveCase
12171218 )
@@ -1347,7 +1348,7 @@ writeStakePools format mOutFile stakePools =
13471348 $ Vary. exhaustiveCase
13481349 )
13491350 writeJson =
1350- encodePretty stakePools
1351+ Aeson. encodePretty stakePools
13511352 writeText =
13521353 LBS. unlines $
13531354 map (strictTextToLazyBytestring . serialiseToBech32) $
@@ -1368,7 +1369,7 @@ writeFormattedOutput format mOutFile value =
13681369 toWrite :: LBS. ByteString =
13691370 format
13701371 & ( id
1371- . Vary. on (\ FormatJson -> encodePretty value)
1372+ . Vary. on (\ FormatJson -> Json. encodeJson value)
13721373 . Vary. on (\ FormatText -> fromString . docToString $ pretty value)
13731374 $ Vary. exhaustiveCase
13741375 )
@@ -1416,7 +1417,7 @@ writeStakeDistribution format mOutFile stakeDistrib =
14161417 toWrite :: LBS. ByteString =
14171418 format
14181419 & ( id
1419- . Vary. on (\ FormatJson -> encodePretty stakeDistrib)
1420+ . Vary. on (\ FormatJson -> Json. encodeJson stakeDistrib)
14201421 . Vary. on (\ FormatText -> strictTextToLazyBytestring stakeDistributionText)
14211422 $ Vary. exhaustiveCase
14221423 )
@@ -1540,8 +1541,9 @@ runQueryLeadershipScheduleCmd
15401541 toWrite =
15411542 format
15421543 & ( id
1543- . Vary. on (\ FormatJson -> encodePretty $ leadershipScheduleToJson schedule eInfo start)
1544+ . Vary. on (\ FormatJson -> Json. encodeJson $ leadershipScheduleToJson schedule eInfo start)
15441545 . Vary. on (\ FormatText -> strictTextToLazyBytestring $ leadershipScheduleToText schedule eInfo start)
1546+ . Vary. on (\ FormatYaml -> Json. encodeYaml $ leadershipScheduleToJson schedule eInfo start)
15451547 $ Vary. exhaustiveCase
15461548 )
15471549
@@ -1973,10 +1975,10 @@ writeOutput
19731975 -> b
19741976 -> ExceptT QueryCmdError IO ()
19751977writeOutput mOutFile content = case mOutFile of
1976- Nothing -> liftIO . LBS. putStrLn . encodePretty $ content
1978+ Nothing -> liftIO . LBS. putStrLn . Aeson. encodePretty $ content
19771979 Just (File f) ->
19781980 handleIOExceptT (QueryCmdWriteFileError . FileIOError f) $
1979- LBS. writeFile f (encodePretty content)
1981+ LBS. writeFile f (Aeson. encodePretty content)
19801982
19811983-- Helpers
19821984
0 commit comments