@@ -52,6 +52,7 @@ import Cardano.Binary qualified as CBOR
52
52
import Cardano.CLI.EraBased.Genesis.Internal.Common
53
53
import Cardano.CLI.EraBased.Query.Command qualified as Cmd
54
54
import Cardano.CLI.Helper
55
+ import Cardano.CLI.Json.Encode qualified as Json
55
56
import Cardano.CLI.Read
56
57
( getHashFromStakePoolKeyHashSource
57
58
)
@@ -69,7 +70,7 @@ import Cardano.Slotting.Time (RelativeTime (..), toRelativeTime)
69
70
import Control.Monad (forM , forM_ , join )
70
71
import Data.Aeson as Aeson
71
72
import Data.Aeson qualified as A
72
- import Data.Aeson.Encode.Pretty ( encodePretty )
73
+ import Data.Aeson.Encode.Pretty qualified as Aeson
73
74
import Data.Bifunctor (Bifunctor (.. ))
74
75
import Data.ByteString.Base16.Lazy qualified as Base16
75
76
import Data.ByteString.Char8 qualified as C8
@@ -92,7 +93,6 @@ import Data.Text.Encoding qualified as Text
92
93
import Data.Text.IO qualified as T
93
94
import Data.Text.Lazy.IO qualified as LT
94
95
import Data.Time.Clock
95
- import Data.Yaml qualified as Yaml
96
96
import GHC.Exts (IsList (.. ))
97
97
import GHC.Generics
98
98
import Lens.Micro ((^.) )
@@ -160,7 +160,7 @@ runQueryProtocolParametersCmd
160
160
firstExceptT QueryCmdWriteFileError . newExceptT $
161
161
writeLazyByteStringOutput mOutFile' $
162
162
shelleyBasedEraConstraints sbe $
163
- encodePretty pparams
163
+ Aeson. encodePretty pparams
164
164
165
165
-- | Calculate the percentage sync rendered as text: @min 1 (tipTime/nowTime)@
166
166
percentage
@@ -290,7 +290,7 @@ runQueryTipCmd
290
290
291
291
firstExceptT QueryCmdWriteFileError . newExceptT $
292
292
writeLazyByteStringOutput mOutFile $
293
- encodePretty localStateOutput
293
+ Aeson. encodePretty localStateOutput
294
294
295
295
-- | Query the UTxO, filtered by a given set of addresses, from a Shelley node
296
296
-- via the local state query protocol.
@@ -387,7 +387,7 @@ runQueryKesPeriodInfoCmd
387
387
renderOpCertNodeAndOnDiskCounterInformation (unFile nodeOpCertFp) counterInformation
388
388
389
389
let qKesInfoOutput = createQueryKesPeriodInfoOutput opCertIntervalInformation counterInformation eInfo gParams
390
- kesPeriodInfoJSON = encodePretty qKesInfoOutput
390
+ kesPeriodInfoJSON = Aeson. encodePretty qKesInfoOutput
391
391
392
392
liftIO $ LBS. putStrLn kesPeriodInfoJSON
393
393
forM_
@@ -681,7 +681,7 @@ runQueryTxMempoolCmd
681
681
result <- liftIO $ queryTxMonitoringLocal nodeConnInfo localQuery
682
682
firstExceptT QueryCmdWriteFileError . newExceptT $
683
683
writeLazyByteStringOutput mOutFile $
684
- encodePretty result
684
+ Aeson. encodePretty result
685
685
686
686
runQuerySlotNumberCmd
687
687
:: ()
@@ -883,13 +883,14 @@ runQueryLedgerPeerSnapshot
883
883
Left (bs :: LBS. ByteString ) -> do
884
884
firstExceptT QueryCmdHelpersError $ pPrintCBOR bs
885
885
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. encodeJsonPretty)
890
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
891
+ $ Vary. exhaustiveCase
892
+ )
893
+ $ snapshot
893
894
894
895
let writeOutputContents =
895
896
case mOutFile of
@@ -1047,7 +1048,7 @@ writeStakeAddressInfo
1047
1048
)
1048
1049
mOutFile =
1049
1050
firstExceptT QueryCmdWriteFileError . newExceptT $
1050
- writeLazyByteStringOutput mOutFile (encodePretty $ jsonInfo sbe)
1051
+ writeLazyByteStringOutput mOutFile (Aeson. encodePretty $ jsonInfo sbe)
1051
1052
where
1052
1053
jsonInfo :: ShelleyBasedEra era -> [Aeson. Value ]
1053
1054
jsonInfo =
@@ -1114,7 +1115,7 @@ writeStakeSnapshots mOutFile qState = do
1114
1115
& onLeft (left . QueryCmdStakeSnapshotDecodeError )
1115
1116
1116
1117
-- 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
1118
1119
1119
1120
-- | This function obtains the pool parameters, equivalent to the following jq query on the output of query ledger-state
1120
1121
-- .nesEs.esLState.lsDPState.dpsPState.psStakePoolParams.<pool_id>
@@ -1154,7 +1155,7 @@ writePoolState mOutFile serialisedCurrentEpochState = do
1154
1155
1155
1156
firstExceptT QueryCmdWriteFileError . newExceptT $
1156
1157
writeLazyByteStringOutput mOutFile $
1157
- encodePretty poolStates
1158
+ Aeson. encodePretty poolStates
1158
1159
1159
1160
writeProtocolState
1160
1161
:: ShelleyBasedEra era
@@ -1195,7 +1196,7 @@ writeProtocolState sbe mOutFile ps@(ProtocolState pstate) =
1195
1196
decodePState ps' =
1196
1197
case decodeProtocolState ps' of
1197
1198
Left (bs, _) -> firstExceptT QueryCmdHelpersError $ pPrintCBOR bs
1198
- Right chainDepstate -> liftIO . LBS. putStrLn $ encodePretty chainDepstate
1199
+ Right chainDepstate -> liftIO . LBS. putStrLn $ Aeson. encodePretty chainDepstate
1199
1200
1200
1201
writeFilteredUTxOs
1201
1202
:: Api. ShelleyBasedEra era
@@ -1211,7 +1212,7 @@ writeFilteredUTxOs sbe format mOutFile utxo =
1211
1212
$ format
1212
1213
& ( id
1213
1214
. Vary. on (\ FormatCbor -> Base16. encode . CBOR. serialize $ toLedgerUTxO sbe utxo)
1214
- . Vary. on (\ FormatJson -> encodePretty utxo)
1215
+ . Vary. on (\ FormatJson -> Aeson. encodePretty utxo)
1215
1216
. Vary. on (\ FormatText -> strictTextToLazyBytestring $ filteredUTxOsToText sbe utxo)
1216
1217
$ Vary. exhaustiveCase
1217
1218
)
@@ -1347,7 +1348,7 @@ writeStakePools format mOutFile stakePools =
1347
1348
$ Vary. exhaustiveCase
1348
1349
)
1349
1350
writeJson =
1350
- encodePretty stakePools
1351
+ Aeson. encodePretty stakePools
1351
1352
writeText =
1352
1353
LBS. unlines $
1353
1354
map (strictTextToLazyBytestring . serialiseToBech32) $
@@ -1368,7 +1369,7 @@ writeFormattedOutput format mOutFile value =
1368
1369
toWrite :: LBS. ByteString =
1369
1370
format
1370
1371
& ( id
1371
- . Vary. on (\ FormatJson -> encodePretty value)
1372
+ . Vary. on (\ FormatJson -> Aeson. encodePretty value)
1372
1373
. Vary. on (\ FormatText -> fromString . docToString $ pretty value)
1373
1374
$ Vary. exhaustiveCase
1374
1375
)
@@ -1416,7 +1417,7 @@ writeStakeDistribution format mOutFile stakeDistrib =
1416
1417
toWrite :: LBS. ByteString =
1417
1418
format
1418
1419
& ( id
1419
- . Vary. on (\ FormatJson -> encodePretty stakeDistrib)
1420
+ . Vary. on (\ FormatJson -> Aeson. encodePretty stakeDistrib)
1420
1421
. Vary. on (\ FormatText -> strictTextToLazyBytestring stakeDistributionText)
1421
1422
$ Vary. exhaustiveCase
1422
1423
)
@@ -1540,8 +1541,9 @@ runQueryLeadershipScheduleCmd
1540
1541
toWrite =
1541
1542
format
1542
1543
& ( id
1543
- . Vary. on (\ FormatJson -> encodePretty $ leadershipScheduleToJson schedule eInfo start)
1544
+ . Vary. on (\ FormatJson -> Json. encodeJsonPretty $ leadershipScheduleToJson schedule eInfo start)
1544
1545
. Vary. on (\ FormatText -> strictTextToLazyBytestring $ leadershipScheduleToText schedule eInfo start)
1546
+ . Vary. on (\ FormatYaml -> Json. encodeYaml $ leadershipScheduleToJson schedule eInfo start)
1545
1547
$ Vary. exhaustiveCase
1546
1548
)
1547
1549
@@ -1973,10 +1975,10 @@ writeOutput
1973
1975
-> b
1974
1976
-> ExceptT QueryCmdError IO ()
1975
1977
writeOutput mOutFile content = case mOutFile of
1976
- Nothing -> liftIO . LBS. putStrLn . encodePretty $ content
1978
+ Nothing -> liftIO . LBS. putStrLn . Aeson. encodePretty $ content
1977
1979
Just (File f) ->
1978
1980
handleIOExceptT (QueryCmdWriteFileError . FileIOError f) $
1979
- LBS. writeFile f (encodePretty content)
1981
+ LBS. writeFile f (Aeson. encodePretty content)
1980
1982
1981
1983
-- Helpers
1982
1984
0 commit comments