Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IsList(toList,fromList) instead of specialised functions #865

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ library
transformers-except ^>=0.1.3,
unliftio-core,
utf8-string,
vector,
yaml,

executable cardano-cli
Expand Down Expand Up @@ -337,7 +336,7 @@ test-suite cardano-cli-test
Test.Cli.Governance.DRep
Test.Cli.Governance.Hash
Test.Cli.ITN
Test.Cli.JSON
Test.Cli.Json
Test.Cli.MonadWarning
Test.Cli.Pioneers.Exercise1
Test.Cli.Pioneers.Exercise2
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Byron/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ genesisUTxOTxIn gc vk genAddr =
where
initialUtxo :: Map Common.Address (UTxO.TxIn, UTxO.TxOut)
initialUtxo =
Map.fromList
fromList
. mapMaybe (\(inp, out) -> mkEntry inp genAddr <$> keyMatchesUTxO vk out)
. fromCompactTxInTxOutList
. toList
Expand Down
9 changes: 4 additions & 5 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ import Data.Foldable
import Data.Functor (($>))
import qualified Data.IP as IP
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NE
import Data.Maybe
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Time.Clock (UTCTime)
import Data.Time.Format (defaultTimeLocale, parseTimeOrError)
import Data.Word
import GHC.Exts (IsList (..))
import GHC.Natural (Natural)
import Network.Socket (PortNumber)
import Options.Applicative hiding (help, str)
Expand Down Expand Up @@ -328,7 +327,7 @@ readVerificationKey asType =
Opt.eitherReader deserialiseFromBech32OrHex
where
keyFormats :: NonEmpty (InputFormat (VerificationKey keyrole))
keyFormats = NE.fromList [InputFormatBech32, InputFormatHex]
keyFormats = fromList [InputFormatBech32, InputFormatHex]

deserialiseFromBech32OrHex
:: String
Expand Down Expand Up @@ -2747,7 +2746,7 @@ pQueryUTxOFilter =
]

pQueryUTxOByAddress :: Parser QueryUTxOFilter
pQueryUTxOByAddress = QueryUTxOByAddress . Set.fromList <$> some pByAddress
pQueryUTxOByAddress = QueryUTxOByAddress . fromList <$> some pByAddress

pByAddress :: Parser AddressAny
pByAddress =
Expand All @@ -2759,7 +2758,7 @@ pQueryUTxOFilter =
]

pQueryUTxOByTxIn :: Parser QueryUTxOFilter
pQueryUTxOByTxIn = QueryUTxOByTxIn . Set.fromList <$> some pByTxIn
pQueryUTxOByTxIn = QueryUTxOByTxIn . fromList <$> some pByTxIn

pByTxIn :: Parser TxIn
pByTxIn =
Expand Down
16 changes: 8 additions & 8 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ generateShelleyNodeSecrets shelleyDelegateKeys shelleyGenesisvkeys = do
-> (Hash GenesisKey, (Hash GenesisDelegateKey, Hash VrfKey))
hashKeys (genesis, delegate, vrf) = (verificationKeyHash genesis, (verificationKeyHash delegate, verificationKeyHash vrf))
delegateMap :: Map (Hash GenesisKey) (Hash GenesisDelegateKey, Hash VrfKey)
delegateMap = Map.fromList . map hashKeys $ combinedMap
delegateMap = fromList . map hashKeys $ combinedMap

return (delegateMap, vrfKeys, kesKeys, opCerts)

Expand Down Expand Up @@ -806,7 +806,7 @@ updateOutputTemplate
L.Coin minUtxoVal = sgProtocolParams ^. L.ppMinUTxOValueL

shelleyDelKeys =
Map.fromList
fromList
[ (gh, L.GenDelegPair gdh h)
| ( GenesisKeyHash gh
, (GenesisDelegateKeyHash gdh, VrfKeyHash h)
Expand Down Expand Up @@ -956,7 +956,7 @@ buildPoolParams nw dir index specifiedRelays = do
lookupPoolRelay m =
case index of
Nothing -> mempty
Just index' -> maybe mempty Seq.fromList (Map.lookup index' m)
Just index' -> maybe mempty fromList (Map.lookup index' m)

strIndex = maybe "" show index
poolColdVKF = File $ dir </> "cold" ++ strIndex ++ ".vkey"
Expand Down Expand Up @@ -1133,7 +1133,7 @@ updateTemplate
L.Coin minUtxoVal = sgProtocolParams template ^. L.ppMinUTxOValueL

shelleyDelKeys =
Map.fromList
fromList
[ (gh, L.GenDelegPair gdh h)
| ( GenesisKeyHash gh
, (GenesisDelegateKeyHash gdh, VrfKeyHash h)
Expand Down Expand Up @@ -1218,7 +1218,7 @@ readGenDelegsMap gendir deldir = do
(Hash GenesisKey)
(Hash GenesisDelegateKey, Hash VrfKey)
delegsMap =
Map.fromList
fromList
[ (gh, (dh, vh))
| (g, (d, v)) <- Map.elems combinedMap
, let gh = verificationKeyHash g
Expand All @@ -1243,7 +1243,7 @@ readGenesisKeys gendir = do
, takeExtension file == ".vkey"
]
firstExceptT GenesisCmdTextEnvReadFileError $
Map.fromList
fromList
<$> sequence
[ (,) ix <$> readKey (File file)
| (file, ix) <- fileIxs
Expand All @@ -1268,7 +1268,7 @@ readDelegateKeys deldir = do
, takeExtensions file == ".vkey"
]
firstExceptT GenesisCmdTextEnvReadFileError $
Map.fromList
fromList
<$> sequence
[ (,) ix <$> readKey (File file)
| (file, ix) <- fileIxs
Expand All @@ -1293,7 +1293,7 @@ readDelegateVrfKeys deldir = do
, takeExtensions file == ".vrf.vkey"
]
firstExceptT GenesisCmdTextEnvReadFileError $
Map.fromList
fromList
<$> sequence
[ (,) ix <$> readKey (File file)
| (file, ix) <- fileIxs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ import Data.Bifunctor (Bifunctor (..))
import qualified Data.ByteString.Lazy.Char8 as LBS
import Data.ListMap (ListMap (..))
import qualified Data.ListMap as ListMap
import Data.Map.Strict (Map, fromList, toList)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe)
import qualified Data.Sequence.Strict as Seq
import Data.String (fromString)
import qualified Data.Text as Text
import Data.Tuple (swap)
import Data.Word (Word64)
import GHC.Exts (IsList (..))
import GHC.Generics (Generic)
import GHC.Num (Natural)
import Lens.Micro ((^.))
Expand Down Expand Up @@ -627,7 +628,7 @@ buildPoolParams nw dir index specifiedRelays = do
}
where
lookupPoolRelay :: Map Word [L.StakePoolRelay] -> Seq.StrictSeq L.StakePoolRelay
lookupPoolRelay m = Seq.fromList $ Map.findWithDefault [] index m
lookupPoolRelay m = fromList $ Map.findWithDefault [] index m
poolColdVKF = File $ dir </> "cold.vkey"
poolVrfVKF = File $ dir </> "vrf.vkey"
poolRewardVKF = File $ dir </> "staking-reward.vkey"
Expand Down Expand Up @@ -754,7 +755,7 @@ updateOutputTemplate
where
L.Coin minUtxoVal = sgProtocolParams ^. L.ppMinUTxOValueL
shelleyDelKeys =
Map.fromList
fromList
[ (gh, L.GenDelegPair gdh h)
| ( GenesisKeyHash gh
, (GenesisDelegateKeyHash gdh, VrfKeyHash h)
Expand Down Expand Up @@ -811,7 +812,7 @@ readGenDelegsMap genesisKeys delegateKeys delegateVrfKeys = do
(Hash GenesisKey)
(Hash GenesisDelegateKey, Hash VrfKey)
delegsMap =
Map.fromList
fromList
[ (gh, (dh, vh))
| (g, (d, v)) <- Map.elems combinedMap
, let gh = verificationKeyHash g
Expand All @@ -832,7 +833,7 @@ readKeys
-> ExceptT GenesisCmdError IO (Map k a)
readKeys asType genesisVKeys = do
firstExceptT GenesisCmdTextEnvReadFileError $
Map.fromList
fromList
<$> sequence
[ (,) ix <$> readKey (File file)
| (ix, file) <- toList genesisVKeys
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Cardano.CLI.Types.Errors.GovernanceCmdError

import Control.Monad
import Data.Function
import qualified Data.Map.Strict as Map
import GHC.Exts (IsList (..))

runGovernanceCmds
:: ()
Expand Down Expand Up @@ -84,7 +84,7 @@ runGovernanceMIRCertificatePayStakeAddrs w mirPot sAddrs rwdAmts oFp = do
let sCreds = map stakeAddressCredential sAddrs
mirTarget =
L.StakeAddressesMIR $
Map.fromList
fromList
[ (toShelleyStakeCredential scred, L.toDeltaCoin rwdAmt)
| (scred, rwdAmt) <- zip sCreds rwdAmts
]
Expand Down
23 changes: 12 additions & 11 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ runQueryPoolStateCmd

let poolFilter = case allOrOnlyPoolIds of
All -> Nothing
Only poolIds -> Just $ Set.fromList poolIds
Only poolIds -> Just $ fromList poolIds

result <-
lift (queryPoolState beo poolFilter)
Expand Down Expand Up @@ -836,7 +836,7 @@ runQueryStakeSnapshotCmd

let poolFilter = case allOrOnlyPoolIds of
All -> Nothing
Only poolIds -> Just $ Set.fromList poolIds
Only poolIds -> Just $ fromList poolIds

beo <- requireEon BabbageEra era

Expand Down Expand Up @@ -1104,16 +1104,17 @@ writePoolState mOutFile serialisedCurrentEpochState = do
pure (decodePoolState serialisedCurrentEpochState)
& onLeft (left . QueryCmdPoolStateDecodeError)

let hks =
let hks :: [L.KeyHash L.StakePool StandardCrypto]
hks =
toList $
Set.fromList $
fromList @(Set (L.KeyHash L.StakePool StandardCrypto)) $
Map.keys (L.psStakePoolParams poolState)
<> Map.keys (L.psFutureStakePoolParams poolState)
<> Map.keys (L.psRetiring poolState)

let poolStates :: Map (L.KeyHash 'L.StakePool StandardCrypto) (Params StandardCrypto)
poolStates =
Map.fromList $
fromList $
hks
<&> ( \hk ->
( hk
Expand Down Expand Up @@ -1644,13 +1645,13 @@ runQueryDRepState
let drepHashSources = case drepHashSources' of All -> []; Only l -> l
drepCreds <- modifyError QueryCmdDRepKeyError $ mapM readDRepCredential drepHashSources

drepState <- runQuery localNodeConnInfo target $ queryDRepState eon $ Set.fromList drepCreds
drepState <- runQuery localNodeConnInfo target $ queryDRepState eon $ fromList drepCreds

drepStakeDistribution <-
case includeStake of
Cmd.WithStake ->
runQuery localNodeConnInfo target $
queryDRepStakeDistribution eon (Set.fromList $ L.DRepCredential <$> drepCreds)
queryDRepStakeDistribution eon (fromList $ L.DRepCredential <$> drepCreds)
Cmd.NoStake -> return mempty

let assocs :: [(L.Credential L.DRepRole StandardCrypto, L.DRepState StandardCrypto)] = Map.assocs drepState
Expand Down Expand Up @@ -1694,7 +1695,7 @@ runQueryDRepStakeDistribution
drepHashSources = case drepHashSources' of
All -> []
Only l -> l
dreps <- Set.fromList <$> mapM drepFromSource drepHashSources
dreps <- fromList <$> mapM drepFromSource drepHashSources

drepStakeDistribution <- runQuery localNodeConnInfo target $ queryDRepStakeDistribution eon dreps
writeOutput mOutFile $
Expand All @@ -1720,16 +1721,16 @@ runQueryCommitteeMembersState
let coldKeysFromVerKeyHashOrFile =
modifyError QueryCmdCommitteeColdKeyError
. readVerificationKeyOrHashOrFileOrScriptHash AsCommitteeColdKey unCommitteeColdKeyHash
coldKeys <- Set.fromList <$> mapM coldKeysFromVerKeyHashOrFile coldCredKeys
coldKeys <- fromList <$> mapM coldKeysFromVerKeyHashOrFile coldCredKeys

let hotKeysFromVerKeyHashOrFile =
modifyError QueryCmdCommitteeHotKeyError
. readVerificationKeyOrHashOrFileOrScriptHash AsCommitteeHotKey unCommitteeHotKeyHash
hotKeys <- Set.fromList <$> mapM hotKeysFromVerKeyHashOrFile hotCredKeys
hotKeys <- fromList <$> mapM hotKeysFromVerKeyHashOrFile hotCredKeys

committeeState <-
runQuery localNodeConnInfo target $
queryCommitteeMembersState eon coldKeys hotKeys (Set.fromList memberStatuses)
queryCommitteeMembersState eon coldKeys hotKeys (fromList memberStatuses)
writeOutput mOutFile $ A.toJSON committeeState

runQueryTreasuryValue
Expand Down
Loading
Loading