@@ -69,7 +69,6 @@ import Cardano.Slotting.Time (RelativeTime (..), toRelativeTime)
69
69
70
70
import Control.Monad (forM , join )
71
71
import Data.Aeson as Aeson
72
- import Data.Aeson qualified as A
73
72
import Data.Aeson.Encode.Pretty qualified as Aeson
74
73
import Data.Bifunctor (Bifunctor (.. ))
75
74
import Data.ByteString.Base16.Lazy qualified as Base16
@@ -1663,10 +1662,23 @@ runQueryConstitution
1663
1662
{ Cmd. nodeConnInfo
1664
1663
, Cmd. target
1665
1664
}
1665
+ , Cmd. outputFormat
1666
1666
, Cmd. mOutFile
1667
1667
} = conwayEraOnwardsConstraints eon $ do
1668
1668
constitution <- runQuery nodeConnInfo target $ queryConstitution eon
1669
- writeOutput mOutFile constitution
1669
+
1670
+ let output =
1671
+ outputFormat
1672
+ & ( id
1673
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1674
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1675
+ $ Vary. exhaustiveCase
1676
+ )
1677
+ $ constitution
1678
+
1679
+ firstExceptT QueryCmdWriteFileError
1680
+ . newExceptT
1681
+ $ writeLazyByteStringOutput mOutFile output
1670
1682
1671
1683
runQueryGovState
1672
1684
:: Cmd. QueryNoArgCmdArgs era
@@ -1679,10 +1691,23 @@ runQueryGovState
1679
1691
{ Cmd. nodeConnInfo
1680
1692
, Cmd. target
1681
1693
}
1694
+ , Cmd. outputFormat
1682
1695
, Cmd. mOutFile
1683
1696
} = conwayEraOnwardsConstraints eon $ do
1684
1697
govState <- runQuery nodeConnInfo target $ queryGovState eon
1685
- writeOutput mOutFile govState
1698
+
1699
+ let output =
1700
+ outputFormat
1701
+ & ( id
1702
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1703
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1704
+ $ Vary. exhaustiveCase
1705
+ )
1706
+ $ govState
1707
+
1708
+ firstExceptT QueryCmdWriteFileError
1709
+ . newExceptT
1710
+ $ writeLazyByteStringOutput mOutFile output
1686
1711
1687
1712
runQueryRatifyState
1688
1713
:: Cmd. QueryNoArgCmdArgs era
@@ -1695,10 +1720,23 @@ runQueryRatifyState
1695
1720
{ Cmd. nodeConnInfo
1696
1721
, Cmd. target
1697
1722
}
1723
+ , Cmd. outputFormat
1698
1724
, Cmd. mOutFile
1699
1725
} = conwayEraOnwardsConstraints eon $ do
1700
1726
ratifyState <- runQuery nodeConnInfo target $ queryRatifyState eon
1701
- writeOutput mOutFile ratifyState
1727
+
1728
+ let output =
1729
+ outputFormat
1730
+ & ( id
1731
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1732
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1733
+ $ Vary. exhaustiveCase
1734
+ )
1735
+ $ ratifyState
1736
+
1737
+ firstExceptT QueryCmdWriteFileError
1738
+ . newExceptT
1739
+ $ writeLazyByteStringOutput mOutFile output
1702
1740
1703
1741
runQueryFuturePParams
1704
1742
:: Cmd. QueryNoArgCmdArgs era
@@ -1711,10 +1749,23 @@ runQueryFuturePParams
1711
1749
{ Cmd. nodeConnInfo
1712
1750
, Cmd. target
1713
1751
}
1752
+ , Cmd. outputFormat
1714
1753
, Cmd. mOutFile
1715
1754
} = conwayEraOnwardsConstraints eon $ do
1716
1755
futurePParams <- runQuery nodeConnInfo target $ queryFuturePParams eon
1717
- writeOutput mOutFile futurePParams
1756
+
1757
+ let output =
1758
+ outputFormat
1759
+ & ( id
1760
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1761
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1762
+ $ Vary. exhaustiveCase
1763
+ )
1764
+ $ futurePParams
1765
+
1766
+ firstExceptT QueryCmdWriteFileError
1767
+ . newExceptT
1768
+ $ writeLazyByteStringOutput mOutFile output
1718
1769
1719
1770
runQueryDRepState
1720
1771
:: Cmd. QueryDRepStateCmdArgs era
@@ -1729,6 +1780,7 @@ runQueryDRepState
1729
1780
{ Cmd. nodeConnInfo
1730
1781
, Cmd. target
1731
1782
}
1783
+ , Cmd. outputFormat
1732
1784
, Cmd. mOutFile
1733
1785
} = conwayEraOnwardsConstraints eon $ do
1734
1786
let drepHashSources = case drepHashSources' of All -> [] ; Only l -> l
@@ -1744,9 +1796,20 @@ runQueryDRepState
1744
1796
Cmd. NoStake -> return mempty
1745
1797
1746
1798
let assocs :: [(L. Credential L. DRepRole , L. DRepState )] = Map. assocs drepState
1747
- toWrite = toDRepStateOutput drepStakeDistribution <$> assocs
1799
+ drepStateOutputs = toDRepStateOutput drepStakeDistribution <$> assocs
1748
1800
1749
- writeOutput mOutFile toWrite
1801
+ let output =
1802
+ outputFormat
1803
+ & ( id
1804
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1805
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1806
+ $ Vary. exhaustiveCase
1807
+ )
1808
+ $ drepStateOutputs
1809
+
1810
+ firstExceptT QueryCmdWriteFileError
1811
+ . newExceptT
1812
+ $ writeLazyByteStringOutput mOutFile output
1750
1813
where
1751
1814
toDRepStateOutput
1752
1815
:: ()
@@ -1774,6 +1837,7 @@ runQueryDRepStakeDistribution
1774
1837
, Cmd. target
1775
1838
}
1776
1839
, Cmd. drepHashSources = drepHashSources'
1840
+ , Cmd. outputFormat
1777
1841
, Cmd. mOutFile
1778
1842
} = conwayEraOnwardsConstraints eon $ do
1779
1843
let drepFromSource =
@@ -1786,8 +1850,19 @@ runQueryDRepStakeDistribution
1786
1850
dreps <- fromList <$> mapM drepFromSource drepHashSources
1787
1851
1788
1852
drepStakeDistribution <- runQuery nodeConnInfo target $ queryDRepStakeDistribution eon dreps
1789
- writeOutput mOutFile $
1790
- Map. assocs drepStakeDistribution
1853
+
1854
+ let output =
1855
+ outputFormat
1856
+ & ( id
1857
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1858
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1859
+ $ Vary. exhaustiveCase
1860
+ )
1861
+ $ drepStakeDistribution
1862
+
1863
+ firstExceptT QueryCmdWriteFileError
1864
+ . newExceptT
1865
+ $ writeLazyByteStringOutput mOutFile output
1791
1866
1792
1867
runQuerySPOStakeDistribution
1793
1868
:: Cmd. QuerySPOStakeDistributionCmdArgs era
@@ -1880,6 +1955,7 @@ runQueryCommitteeMembersState
1880
1955
, Cmd. committeeColdKeys = coldCredKeys
1881
1956
, Cmd. committeeHotKeys = hotCredKeys
1882
1957
, Cmd. memberStatuses = memberStatuses
1958
+ , Cmd. outputFormat
1883
1959
, Cmd. mOutFile
1884
1960
} = conwayEraOnwardsConstraints eon $ do
1885
1961
let coldKeysFromVerKeyHashOrFile =
@@ -1895,7 +1971,19 @@ runQueryCommitteeMembersState
1895
1971
committeeState <-
1896
1972
runQuery nodeConnInfo target $
1897
1973
queryCommitteeMembersState eon coldKeys hotKeys (fromList memberStatuses)
1898
- writeOutput mOutFile $ A. toJSON committeeState
1974
+
1975
+ let output =
1976
+ outputFormat
1977
+ & ( id
1978
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1979
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1980
+ $ Vary. exhaustiveCase
1981
+ )
1982
+ $ committeeState
1983
+
1984
+ firstExceptT QueryCmdWriteFileError
1985
+ . newExceptT
1986
+ $ writeLazyByteStringOutput mOutFile output
1899
1987
1900
1988
runQueryTreasuryValue
1901
1989
:: Cmd. QueryTreasuryValueCmdArgs era
@@ -1931,6 +2019,7 @@ runQueryProposals
1931
2019
, Cmd. target
1932
2020
}
1933
2021
, Cmd. govActionIds = govActionIds'
2022
+ , Cmd. outputFormat
1934
2023
, Cmd. mOutFile
1935
2024
} = conwayEraOnwardsConstraints eon $ do
1936
2025
let govActionIds = case govActionIds' of
@@ -1940,7 +2029,18 @@ runQueryProposals
1940
2029
govActionStates :: (Seq. Seq (L. GovActionState (ShelleyLedgerEra era ))) <-
1941
2030
runQuery nodeConnInfo target $ queryProposals eon $ Set. fromList govActionIds
1942
2031
1943
- writeOutput mOutFile govActionStates
2032
+ let output =
2033
+ outputFormat
2034
+ & ( id
2035
+ . Vary. on (\ FormatJson -> Json. encodeJson)
2036
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
2037
+ $ Vary. exhaustiveCase
2038
+ )
2039
+ $ govActionStates
2040
+
2041
+ firstExceptT QueryCmdWriteFileError
2042
+ . newExceptT
2043
+ $ writeLazyByteStringOutput mOutFile output
1944
2044
1945
2045
runQueryEraHistoryCmd :: Cmd. QueryEraHistoryCmdArgs -> ExceptT QueryCmdError IO ()
1946
2046
runQueryEraHistoryCmd
@@ -2022,17 +2122,6 @@ runQuery localNodeConnInfo target query =
2022
2122
& onLeft (left . QueryCmdUnsupportedNtcVersion )
2023
2123
& onLeft (left . QueryCmdEraMismatch )
2024
2124
2025
- writeOutput
2026
- :: ToJSON b
2027
- => Maybe (File a Out )
2028
- -> b
2029
- -> ExceptT QueryCmdError IO ()
2030
- writeOutput mOutFile content = case mOutFile of
2031
- Nothing -> liftIO . LBS. putStrLn . Aeson. encodePretty $ content
2032
- Just (File f) ->
2033
- handleIOExceptT (QueryCmdWriteFileError . FileIOError f) $
2034
- LBS. writeFile f (Aeson. encodePretty content)
2035
-
2036
2125
-- Helpers
2037
2126
2038
2127
toEpochInfo :: EraHistory -> EpochInfo (Either Text )
0 commit comments