@@ -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
@@ -1676,10 +1675,23 @@ runQueryConstitution
1676
1675
{ Cmd. nodeConnInfo
1677
1676
, Cmd. target
1678
1677
}
1678
+ , Cmd. outputFormat
1679
1679
, Cmd. mOutFile
1680
1680
} = conwayEraOnwardsConstraints eon $ do
1681
1681
constitution <- runQuery nodeConnInfo target $ queryConstitution eon
1682
- writeOutput mOutFile constitution
1682
+
1683
+ let output =
1684
+ outputFormat
1685
+ & ( id
1686
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1687
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1688
+ $ Vary. exhaustiveCase
1689
+ )
1690
+ $ constitution
1691
+
1692
+ firstExceptT QueryCmdWriteFileError
1693
+ . newExceptT
1694
+ $ writeLazyByteStringOutput mOutFile output
1683
1695
1684
1696
runQueryGovState
1685
1697
:: Cmd. QueryNoArgCmdArgs era
@@ -1692,10 +1704,23 @@ runQueryGovState
1692
1704
{ Cmd. nodeConnInfo
1693
1705
, Cmd. target
1694
1706
}
1707
+ , Cmd. outputFormat
1695
1708
, Cmd. mOutFile
1696
1709
} = conwayEraOnwardsConstraints eon $ do
1697
1710
govState <- runQuery nodeConnInfo target $ queryGovState eon
1698
- writeOutput mOutFile govState
1711
+
1712
+ let output =
1713
+ outputFormat
1714
+ & ( id
1715
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1716
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1717
+ $ Vary. exhaustiveCase
1718
+ )
1719
+ $ govState
1720
+
1721
+ firstExceptT QueryCmdWriteFileError
1722
+ . newExceptT
1723
+ $ writeLazyByteStringOutput mOutFile output
1699
1724
1700
1725
runQueryRatifyState
1701
1726
:: Cmd. QueryNoArgCmdArgs era
@@ -1708,10 +1733,23 @@ runQueryRatifyState
1708
1733
{ Cmd. nodeConnInfo
1709
1734
, Cmd. target
1710
1735
}
1736
+ , Cmd. outputFormat
1711
1737
, Cmd. mOutFile
1712
1738
} = conwayEraOnwardsConstraints eon $ do
1713
1739
ratifyState <- runQuery nodeConnInfo target $ queryRatifyState eon
1714
- writeOutput mOutFile ratifyState
1740
+
1741
+ let output =
1742
+ outputFormat
1743
+ & ( id
1744
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1745
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1746
+ $ Vary. exhaustiveCase
1747
+ )
1748
+ $ ratifyState
1749
+
1750
+ firstExceptT QueryCmdWriteFileError
1751
+ . newExceptT
1752
+ $ writeLazyByteStringOutput mOutFile output
1715
1753
1716
1754
runQueryFuturePParams
1717
1755
:: Cmd. QueryNoArgCmdArgs era
@@ -1724,10 +1762,23 @@ runQueryFuturePParams
1724
1762
{ Cmd. nodeConnInfo
1725
1763
, Cmd. target
1726
1764
}
1765
+ , Cmd. outputFormat
1727
1766
, Cmd. mOutFile
1728
1767
} = conwayEraOnwardsConstraints eon $ do
1729
1768
futurePParams <- runQuery nodeConnInfo target $ queryFuturePParams eon
1730
- writeOutput mOutFile futurePParams
1769
+
1770
+ let output =
1771
+ outputFormat
1772
+ & ( id
1773
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1774
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1775
+ $ Vary. exhaustiveCase
1776
+ )
1777
+ $ futurePParams
1778
+
1779
+ firstExceptT QueryCmdWriteFileError
1780
+ . newExceptT
1781
+ $ writeLazyByteStringOutput mOutFile output
1731
1782
1732
1783
runQueryDRepState
1733
1784
:: Cmd. QueryDRepStateCmdArgs era
@@ -1742,6 +1793,7 @@ runQueryDRepState
1742
1793
{ Cmd. nodeConnInfo
1743
1794
, Cmd. target
1744
1795
}
1796
+ , Cmd. outputFormat
1745
1797
, Cmd. mOutFile
1746
1798
} = conwayEraOnwardsConstraints eon $ do
1747
1799
let drepHashSources = case drepHashSources' of All -> [] ; Only l -> l
@@ -1757,9 +1809,20 @@ runQueryDRepState
1757
1809
Cmd. NoStake -> return mempty
1758
1810
1759
1811
let assocs :: [(L. Credential L. DRepRole , L. DRepState )] = Map. assocs drepState
1760
- toWrite = toDRepStateOutput drepStakeDistribution <$> assocs
1812
+ drepStateOutputs = toDRepStateOutput drepStakeDistribution <$> assocs
1761
1813
1762
- writeOutput mOutFile toWrite
1814
+ let output =
1815
+ outputFormat
1816
+ & ( id
1817
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1818
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1819
+ $ Vary. exhaustiveCase
1820
+ )
1821
+ $ drepStateOutputs
1822
+
1823
+ firstExceptT QueryCmdWriteFileError
1824
+ . newExceptT
1825
+ $ writeLazyByteStringOutput mOutFile output
1763
1826
where
1764
1827
toDRepStateOutput
1765
1828
:: ()
@@ -1787,6 +1850,7 @@ runQueryDRepStakeDistribution
1787
1850
, Cmd. target
1788
1851
}
1789
1852
, Cmd. drepHashSources = drepHashSources'
1853
+ , Cmd. outputFormat
1790
1854
, Cmd. mOutFile
1791
1855
} = conwayEraOnwardsConstraints eon $ do
1792
1856
let drepFromSource =
@@ -1799,8 +1863,19 @@ runQueryDRepStakeDistribution
1799
1863
dreps <- fromList <$> mapM drepFromSource drepHashSources
1800
1864
1801
1865
drepStakeDistribution <- runQuery nodeConnInfo target $ queryDRepStakeDistribution eon dreps
1802
- writeOutput mOutFile $
1803
- Map. assocs drepStakeDistribution
1866
+
1867
+ let output =
1868
+ outputFormat
1869
+ & ( id
1870
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1871
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1872
+ $ Vary. exhaustiveCase
1873
+ )
1874
+ $ drepStakeDistribution
1875
+
1876
+ firstExceptT QueryCmdWriteFileError
1877
+ . newExceptT
1878
+ $ writeLazyByteStringOutput mOutFile output
1804
1879
1805
1880
runQuerySPOStakeDistribution
1806
1881
:: Cmd. QuerySPOStakeDistributionCmdArgs era
@@ -1896,6 +1971,7 @@ runQueryCommitteeMembersState
1896
1971
, Cmd. committeeColdKeys = coldCredKeys
1897
1972
, Cmd. committeeHotKeys = hotCredKeys
1898
1973
, Cmd. memberStatuses = memberStatuses
1974
+ , Cmd. outputFormat
1899
1975
, Cmd. mOutFile
1900
1976
} = conwayEraOnwardsConstraints eon $ do
1901
1977
let coldKeysFromVerKeyHashOrFile =
@@ -1911,7 +1987,19 @@ runQueryCommitteeMembersState
1911
1987
committeeState <-
1912
1988
runQuery nodeConnInfo target $
1913
1989
queryCommitteeMembersState eon coldKeys hotKeys (fromList memberStatuses)
1914
- writeOutput mOutFile $ A. toJSON committeeState
1990
+
1991
+ let output =
1992
+ outputFormat
1993
+ & ( id
1994
+ . Vary. on (\ FormatJson -> Json. encodeJson)
1995
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
1996
+ $ Vary. exhaustiveCase
1997
+ )
1998
+ $ committeeState
1999
+
2000
+ firstExceptT QueryCmdWriteFileError
2001
+ . newExceptT
2002
+ $ writeLazyByteStringOutput mOutFile output
1915
2003
1916
2004
runQueryTreasuryValue
1917
2005
:: Cmd. QueryTreasuryValueCmdArgs era
@@ -1947,6 +2035,7 @@ runQueryProposals
1947
2035
, Cmd. target
1948
2036
}
1949
2037
, Cmd. govActionIds = govActionIds'
2038
+ , Cmd. outputFormat
1950
2039
, Cmd. mOutFile
1951
2040
} = conwayEraOnwardsConstraints eon $ do
1952
2041
let govActionIds = case govActionIds' of
@@ -1956,7 +2045,18 @@ runQueryProposals
1956
2045
govActionStates :: (Seq. Seq (L. GovActionState (ShelleyLedgerEra era ))) <-
1957
2046
runQuery nodeConnInfo target $ queryProposals eon $ Set. fromList govActionIds
1958
2047
1959
- writeOutput mOutFile govActionStates
2048
+ let output =
2049
+ outputFormat
2050
+ & ( id
2051
+ . Vary. on (\ FormatJson -> Json. encodeJson)
2052
+ . Vary. on (\ FormatYaml -> Json. encodeYaml)
2053
+ $ Vary. exhaustiveCase
2054
+ )
2055
+ $ govActionStates
2056
+
2057
+ firstExceptT QueryCmdWriteFileError
2058
+ . newExceptT
2059
+ $ writeLazyByteStringOutput mOutFile output
1960
2060
1961
2061
runQueryEraHistoryCmd :: Cmd. QueryEraHistoryCmdArgs -> ExceptT QueryCmdError IO ()
1962
2062
runQueryEraHistoryCmd
@@ -2038,17 +2138,6 @@ runQuery localNodeConnInfo target query =
2038
2138
& onLeft (left . QueryCmdUnsupportedNtcVersion )
2039
2139
& onLeft (left . QueryCmdEraMismatch )
2040
2140
2041
- writeOutput
2042
- :: ToJSON b
2043
- => Maybe (File a Out )
2044
- -> b
2045
- -> ExceptT QueryCmdError IO ()
2046
- writeOutput mOutFile content = case mOutFile of
2047
- Nothing -> liftIO . LBS. putStrLn . Aeson. encodePretty $ content
2048
- Just (File f) ->
2049
- handleIOExceptT (QueryCmdWriteFileError . FileIOError f) $
2050
- LBS. writeFile f (Aeson. encodePretty content)
2051
-
2052
2141
-- Helpers
2053
2142
2054
2143
toEpochInfo :: EraHistory -> EpochInfo (Either Text )
0 commit comments