@@ -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,14 +883,15 @@ 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 $ Aeson. encode snapshot)
890
- . Vary. on (\ FormatJsonPretty -> pure $ encodePretty snapshot)
891
- . Vary. on (\ FormatYaml -> pure $ LBS. fromStrict $ Yaml. encode snapshot)
892
- $ Vary. exhaustiveCase
893
- )
886
+ let outputContents =
887
+ outputFormat
888
+ & ( id
889
+ . Vary. on (\ FormatJson -> Json. encodeJson)
890
+ . Vary. on (\ FormatJsonPretty -> Json. encodeJsonPretty)
891
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
892
+ $ Vary. exhaustiveCase
893
+ )
894
+ $ snapshot
894
895
895
896
let writeOutputContents =
896
897
case mOutFile of
@@ -1048,7 +1049,7 @@ writeStakeAddressInfo
1048
1049
)
1049
1050
mOutFile =
1050
1051
firstExceptT QueryCmdWriteFileError . newExceptT $
1051
- writeLazyByteStringOutput mOutFile (encodePretty $ jsonInfo sbe)
1052
+ writeLazyByteStringOutput mOutFile (Aeson. encodePretty $ jsonInfo sbe)
1052
1053
where
1053
1054
jsonInfo :: ShelleyBasedEra era -> [Aeson. Value ]
1054
1055
jsonInfo =
@@ -1115,7 +1116,7 @@ writeStakeSnapshots mOutFile qState = do
1115
1116
& onLeft (left . QueryCmdStakeSnapshotDecodeError )
1116
1117
1117
1118
-- Calculate the three pool and active stake values for the given pool
1118
- liftIO . maybe LBS. putStrLn (LBS. writeFile . unFile) mOutFile $ encodePretty snapshot
1119
+ liftIO . maybe LBS. putStrLn (LBS. writeFile . unFile) mOutFile $ Aeson. encodePretty snapshot
1119
1120
1120
1121
-- | This function obtains the pool parameters, equivalent to the following jq query on the output of query ledger-state
1121
1122
-- .nesEs.esLState.lsDPState.dpsPState.psStakePoolParams.<pool_id>
@@ -1155,7 +1156,7 @@ writePoolState mOutFile serialisedCurrentEpochState = do
1155
1156
1156
1157
firstExceptT QueryCmdWriteFileError . newExceptT $
1157
1158
writeLazyByteStringOutput mOutFile $
1158
- encodePretty poolStates
1159
+ Aeson. encodePretty poolStates
1159
1160
1160
1161
writeProtocolState
1161
1162
:: ShelleyBasedEra era
@@ -1196,7 +1197,7 @@ writeProtocolState sbe mOutFile ps@(ProtocolState pstate) =
1196
1197
decodePState ps' =
1197
1198
case decodeProtocolState ps' of
1198
1199
Left (bs, _) -> firstExceptT QueryCmdHelpersError $ pPrintCBOR bs
1199
- Right chainDepstate -> liftIO . LBS. putStrLn $ encodePretty chainDepstate
1200
+ Right chainDepstate -> liftIO . LBS. putStrLn $ Aeson. encodePretty chainDepstate
1200
1201
1201
1202
writeFilteredUTxOs
1202
1203
:: Api. ShelleyBasedEra era
@@ -1212,7 +1213,7 @@ writeFilteredUTxOs sbe format mOutFile utxo =
1212
1213
$ format
1213
1214
& ( id
1214
1215
. Vary. on (\ FormatCbor -> Base16. encode . CBOR. serialize $ toLedgerUTxO sbe utxo)
1215
- . Vary. on (\ FormatJson -> encodePretty utxo)
1216
+ . Vary. on (\ FormatJson -> Aeson. encodePretty utxo)
1216
1217
. Vary. on (\ FormatText -> strictTextToLazyBytestring $ filteredUTxOsToText sbe utxo)
1217
1218
$ Vary. exhaustiveCase
1218
1219
)
@@ -1348,7 +1349,7 @@ writeStakePools format mOutFile stakePools =
1348
1349
$ Vary. exhaustiveCase
1349
1350
)
1350
1351
writeJson =
1351
- encodePretty stakePools
1352
+ Aeson. encodePretty stakePools
1352
1353
writeText =
1353
1354
LBS. unlines $
1354
1355
map (strictTextToLazyBytestring . serialiseToBech32) $
@@ -1369,7 +1370,7 @@ writeFormattedOutput format mOutFile value =
1369
1370
toWrite :: LBS. ByteString =
1370
1371
format
1371
1372
& ( id
1372
- . Vary. on (\ FormatJson -> encodePretty value)
1373
+ . Vary. on (\ FormatJson -> Aeson. encodePretty value)
1373
1374
. Vary. on (\ FormatText -> fromString . docToString $ pretty value)
1374
1375
$ Vary. exhaustiveCase
1375
1376
)
@@ -1417,7 +1418,7 @@ writeStakeDistribution format mOutFile stakeDistrib =
1417
1418
toWrite :: LBS. ByteString =
1418
1419
format
1419
1420
& ( id
1420
- . Vary. on (\ FormatJson -> encodePretty stakeDistrib)
1421
+ . Vary. on (\ FormatJson -> Aeson. encodePretty stakeDistrib)
1421
1422
. Vary. on (\ FormatText -> strictTextToLazyBytestring stakeDistributionText)
1422
1423
$ Vary. exhaustiveCase
1423
1424
)
@@ -1541,8 +1542,10 @@ runQueryLeadershipScheduleCmd
1541
1542
toWrite =
1542
1543
format
1543
1544
& ( id
1544
- . Vary. on (\ FormatJson -> encodePretty $ leadershipScheduleToJson schedule eInfo start)
1545
+ . Vary. on (\ FormatJson -> Json. encodeJson $ leadershipScheduleToJson schedule eInfo start)
1546
+ . Vary. on (\ FormatJsonPretty -> Json. encodeJsonPretty $ leadershipScheduleToJson schedule eInfo start)
1545
1547
. Vary. on (\ FormatText -> strictTextToLazyBytestring $ leadershipScheduleToText schedule eInfo start)
1548
+ . Vary. on (\ FormatYaml -> Json. encodeYaml $ leadershipScheduleToJson schedule eInfo start)
1546
1549
$ Vary. exhaustiveCase
1547
1550
)
1548
1551
@@ -1974,10 +1977,10 @@ writeOutput
1974
1977
-> b
1975
1978
-> ExceptT QueryCmdError IO ()
1976
1979
writeOutput mOutFile content = case mOutFile of
1977
- Nothing -> liftIO . LBS. putStrLn . encodePretty $ content
1980
+ Nothing -> liftIO . LBS. putStrLn . Aeson. encodePretty $ content
1978
1981
Just (File f) ->
1979
1982
handleIOExceptT (QueryCmdWriteFileError . FileIOError f) $
1980
- LBS. writeFile f (encodePretty content)
1983
+ LBS. writeFile f (Aeson. encodePretty content)
1981
1984
1982
1985
-- Helpers
1983
1986
0 commit comments