Skip to content

Commit

Permalink
remove qualified fromList
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Aug 5, 2024
1 parent 061ebe1 commit 9f65da7
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 95 deletions.
3 changes: 2 additions & 1 deletion cardano-api/gen/Test/Gen/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Cardano.Ledger.Shelley.TxAuxData (Metadatum (..), ShelleyTxAuxD

import qualified Data.Map.Strict as Map
import Data.Word (Word64)
import GHC.Exts (IsList (..))

import Test.Gen.Cardano.Api.Typed (genCostModel, genRational)

Expand All @@ -32,7 +33,7 @@ genMetadata = do
numberOfIndices <- Gen.integral (Range.linear 1 15)
let indices = map (\i -> fromIntegral i :: Word64) [1 .. numberOfIndices]
mData <- Gen.list (Range.singleton numberOfIndices) genMetadatum
return . ShelleyTxAuxData . Map.fromList $ zip indices mData
return . ShelleyTxAuxData . fromList $ zip indices mData

genMetadatum :: Gen Metadatum
genMetadatum = do
Expand Down
7 changes: 3 additions & 4 deletions cardano-api/gen/Test/Gen/Cardano/Api/Metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import qualified Data.Aeson.Key as Aeson
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Base16 as Base16
import qualified Data.Map.Strict as Map
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.Word (Word64)
import GHC.Exts (IsList (..))

import Hedgehog (Gen)
import qualified Hedgehog.Gen as Gen
Expand All @@ -36,8 +36,7 @@ genJsonForTxMetadata mapping =
Aeson.object
<$> Gen.list
(Range.linear 0 (fromIntegral sz))
( (,)
<$> (Aeson.fromString . show <$> Gen.word64 Range.constantBounded)
( ((,) . Aeson.fromString . show <$> Gen.word64 Range.constantBounded)
<*> genJsonForTxMetadataValue mapping
)

Expand Down Expand Up @@ -167,7 +166,7 @@ genJsonForTxMetadataValue TxMetadataJsonDetailedSchema = genJsonValue
genTxMetadata :: Gen TxMetadata
genTxMetadata =
Gen.sized $ \sz ->
TxMetadata . Map.fromList
TxMetadata . fromList
<$> Gen.list
(Range.linear 0 (fromIntegral sz))
( (,)
Expand Down
23 changes: 13 additions & 10 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ genTxAuxScripts era =
(genScriptInEra (allegraEraOnwardsToShelleyBasedEra w))
)

genTxWithdrawals :: CardanoEra era -> Gen (TxWithdrawals BuildTx era)
genTxWithdrawals :: CardanoEra era -> Gen (TxWithdrawals build era)
genTxWithdrawals =
inEonForEra
(pure TxWithdrawalsNone)
Expand Down Expand Up @@ -648,12 +648,11 @@ genTxMintValue :: CardanoEra era -> Gen (TxMintValue BuildTx era)
genTxMintValue =
inEonForEra
(pure TxMintNone)
( \supported ->
Gen.choice
[ pure TxMintNone
, TxMintValue supported <$> genValueForMinting supported <*> return (BuildTxWith mempty) -- FIXME!!!
]
)
$ \supported ->
Gen.choice
[ pure TxMintNone
, TxMintValue supported <$> genValueForMinting supported <*> return (pure mempty)
]

genTxBodyContent :: ShelleyBasedEra era -> Gen (TxBodyContent BuildTx era)
genTxBodyContent sbe = do
Expand Down Expand Up @@ -1123,7 +1122,9 @@ genGovernancePollAnswer =
genGovernancePollHash =
GovernancePollHash . mkDummyHash <$> Gen.int (Range.linear 0 10)

genProposals :: ConwayEraOnwards era -> Gen (TxProposalProcedures BuildTx era)
genProposals :: Applicative (BuildTxWith build)
=> ConwayEraOnwards era
-> Gen (TxProposalProcedures build era)
genProposals w = conwayEraOnwardsConstraints w $ do
proposals <- fmap Proposal <$> Gen.list (Range.constant 0 10) (genProposal w)
let sbe = conwayEraOnwardsToShelleyBasedEra w
Expand All @@ -1135,13 +1136,15 @@ genProposal :: ConwayEraOnwards era -> Gen (L.ProposalProcedure (ShelleyLedgerEr
genProposal w =
conwayEraOnwardsTestConstraints w Q.arbitrary

genVotingProcedures :: ConwayEraOnwards era -> Gen (Api.TxVotingProcedures BuildTx era)
genVotingProcedures :: Applicative (BuildTxWith build)
=> ConwayEraOnwards era
-> Gen (Api.TxVotingProcedures build era)
genVotingProcedures w = conwayEraOnwardsConstraints w $ do
voters <- Gen.list (Range.constant 0 10) Q.arbitrary
let sbe = conwayEraOnwardsToShelleyBasedEra w
votersWithWitnesses <- fmap fromList . forM voters $ \voter ->
(voter,) <$> genScriptWitnessForStake sbe
Api.TxVotingProcedures <$> Q.arbitrary <*> return (BuildTxWith votersWithWitnesses)
Api.TxVotingProcedures <$> Q.arbitrary <*> pure (pure votersWithWitnesses)

genCurrentTreasuryValue :: ConwayEraOnwards era -> Gen L.Coin
genCurrentTreasuryValue _era = Q.arbitrary
Expand Down
6 changes: 2 additions & 4 deletions cardano-api/internal/Cardano/Api/Certificate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.IP (IPv4, IPv6)
import Data.Maybe
import qualified Data.Sequence.Strict as Seq
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
Expand Down Expand Up @@ -610,10 +608,10 @@ toShelleyPoolParams
(Ledger.boundRational stakePoolMargin)
, Ledger.ppRewardAccount = toShelleyStakeAddr stakePoolRewardAccount
, Ledger.ppOwners =
Set.fromList
fromList
[kh | StakeKeyHash kh <- stakePoolOwners]
, Ledger.ppRelays =
Seq.fromList
fromList
(map toShelleyStakePoolRelay stakePoolRelays)
, Ledger.ppMetadata =
toShelleyPoolMetadata
Expand Down
4 changes: 2 additions & 2 deletions cardano-api/internal/Cardano/Api/Convenience/Construction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import qualified Cardano.Ledger.Keys as L
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as Text
import GHC.Exts (IsList (..))

-- | Construct a balanced transaction.
-- See Cardano.Api.Convenience.Query.queryStateForBalancedTx for a
Expand Down Expand Up @@ -120,7 +120,7 @@ renderNotScriptLockedTxInsError (ScriptLockedTxIns txins) =

notScriptLockedTxIns :: [TxIn] -> UTxO era -> Either ScriptLockedTxInsError ()
notScriptLockedTxIns collTxIns (UTxO utxo) = do
let onlyCollateralUTxOs = Map.restrictKeys utxo $ Set.fromList collTxIns
let onlyCollateralUTxOs = Map.restrictKeys utxo $ fromList collTxIns
scriptLockedTxIns =
filter (\(_, TxOut aInEra _ _ _) -> not $ isKeyAddress aInEra) $ Map.assocs onlyCollateralUTxOs
if null scriptLockedTxIns
Expand Down
9 changes: 4 additions & 5 deletions cardano-api/internal/Cardano/Api/Convenience/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe (mapMaybe)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Text (Text)
import GHC.Exts (IsString (..))
import GHC.Exts (IsList (..), IsString (..))

data QueryConvenienceError
= AcqFailure AcquiringFailure
Expand Down Expand Up @@ -122,12 +121,12 @@ queryStateForBalancedTx era allTxIns certs = runExceptT $ do
requireShelleyBasedEra era
& onNothing (left ByronEraNotSupported)

let stakeCreds = Set.fromList $ mapMaybe filterUnRegCreds certs
drepCreds = Set.fromList $ mapMaybe filterUnRegDRepCreds certs
let stakeCreds = fromList $ mapMaybe filterUnRegCreds certs
drepCreds = fromList $ mapMaybe filterUnRegDRepCreds certs

-- Query execution
utxo <-
lift (queryUtxo sbe (QueryUTxOByTxIn (Set.fromList allTxIns)))
lift (queryUtxo sbe (QueryUTxOByTxIn (fromList allTxIns)))
& onLeft (left . QceUnsupportedNtcVersion)
& onLeft (left . QueryEraMismatch)

Expand Down
1 change: 0 additions & 1 deletion cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,6 @@ substituteExecutionUnits
Right . TxMintValue supported value . BuildTxWith $
fromList final

-- REMOVE THIS
traverseScriptWitnesses
:: [(a, Either (TxBodyErrorAutoBalance era) (ScriptWitness ctx era))]
-> Either (TxBodyErrorAutoBalance era) [(a, ScriptWitness ctx era)]
Expand Down
5 changes: 3 additions & 2 deletions cardano-api/internal/Cardano/Api/Governance/Poll.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import qualified Data.Text.Lazy as Text.Lazy
import qualified Data.Text.Lazy.Builder as Text.Builder
import Data.Word (Word64)
import Formatting (build, sformat)
import GHC.Exts (IsList (..))

-- | Associated metadata label as defined in CIP-0094
pollMetadataLabel :: Word64
Expand Down Expand Up @@ -124,7 +125,7 @@ instance HasTypeProxy GovernancePoll where
instance AsTxMetadata GovernancePoll where
asTxMetadata GovernancePoll{govPollQuestion, govPollAnswers, govPollNonce} =
makeTransactionMetadata $
Map.fromList
fromList
[
( pollMetadataLabel
, TxMetaMap $
Expand Down Expand Up @@ -220,7 +221,7 @@ instance HasTypeProxy GovernancePollAnswer where
instance AsTxMetadata GovernancePollAnswer where
asTxMetadata GovernancePollAnswer{govAnsPoll, govAnsChoice} =
makeTransactionMetadata $
Map.fromList
fromList
[
( pollMetadataLabel
, TxMetaMap
Expand Down
7 changes: 4 additions & 3 deletions cardano-api/internal/Cardano/Api/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Lazy as LBS
import Data.ByteString.Short as BSS
import Data.Foldable
import Data.Foldable (asum)
import Data.IORef
import qualified Data.List as List
import Data.Map.Strict (Map)
Expand All @@ -219,6 +219,7 @@ import Data.Text.Lazy.Builder (toLazyText)
import Data.Word
import qualified Data.Yaml as Yaml
import Formatting.Buildable (build)
import GHC.Exts (IsList (..))
import Lens.Micro
import Network.TypedProtocol.Pipelined (Nat (..))
import System.FilePath
Expand Down Expand Up @@ -1885,7 +1886,7 @@ nextEpochEligibleLeadershipSlots sbe sGen serCurrEpochState ptclState poolid (Vr
slotRangeOfInterest pp' =
Set.filter
(not . Ledger.isOverlaySlot firstSlotOfEpoch (pp' ^. Core.ppDG))
$ Set.fromList [firstSlotOfEpoch .. lastSlotofEpoch]
$ fromList [firstSlotOfEpoch .. lastSlotofEpoch]

caseShelleyToAlonzoOrBabbageEraOnwards
( const
Expand Down Expand Up @@ -1999,7 +2000,7 @@ currentEpochEligibleLeadershipSlots sbe sGen eInfo pp ptclState poolid (VrfSigni
slotRangeOfInterest pp' =
Set.filter
(not . Ledger.isOverlaySlot firstSlotOfEpoch (pp' ^. Core.ppDG))
$ Set.fromList [firstSlotOfEpoch .. lastSlotofEpoch]
$ fromList [firstSlotOfEpoch .. lastSlotofEpoch]

caseShelleyToAlonzoOrBabbageEraOnwards
( const
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/internal/Cardano/Api/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ parsePlutusParamName t =

deriving instance Show V2.ParamName

-- needed to be able to use it as a map key
-- Required instance, to be able to use the type as the map key
deriving instance Ord (L.VotingProcedures ledgerera)

deriving instance Ord (L.VotingProcedure ledgerera)
10 changes: 5 additions & 5 deletions cardano-api/internal/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-orphans #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

{- HLINT ignore "Redundant ==" -}
{- HLINT ignore "Use mapM" -}
{-# HLINT ignore "Redundant ==" #-}

-- | The various Cardano protocol parameters, including:
--
Expand Down Expand Up @@ -1016,7 +1016,7 @@ toAlonzoCostModels
-> Either ProtocolParametersConversionError Alonzo.CostModels
toAlonzoCostModels m = do
f <- mapM conv $ toList m
Right $ Plutus.mkCostModels $ Map.fromList f
Right $ Plutus.mkCostModels $ fromList f
where
conv
:: (AnyPlutusScriptVersion, CostModel)
Expand All @@ -1029,7 +1029,7 @@ fromAlonzoCostModels
:: Plutus.CostModels
-> Map AnyPlutusScriptVersion CostModel
fromAlonzoCostModels cModels =
Map.fromList
fromList
. map (bimap fromAlonzoScriptLanguage fromAlonzoCostModel)
$ toList
$ Plutus.costModelsValid cModels
Expand Down Expand Up @@ -1091,7 +1091,7 @@ makeShelleyUpdateProposal params genesisKeyHashes =
-- TODO decide how to handle parameter validation
-- for example we need to validate the Rational values can convert
-- into the UnitInterval type ok.
UpdateProposal (Map.fromList [(kh, params) | kh <- genesisKeyHashes])
UpdateProposal (fromList [(kh, params) | kh <- genesisKeyHashes])

-- ----------------------------------------------------------------------------
-- Conversion functions: updates to ledger types
Expand Down
14 changes: 7 additions & 7 deletions cardano-api/internal/Cardano/Api/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ instance
parseJSON = withObject "UTxO" $ \hm -> do
let l = toList $ KeyMap.toHashMapText hm
res <- mapM toTxIn l
pure . UTxO $ Map.fromList res
pure . UTxO $ fromList res
where
toTxIn :: (Text, Aeson.Value) -> Parser (TxIn, TxOut CtxUTxO era)
toTxIn (txinText, txOutVal) = do
Expand Down Expand Up @@ -473,7 +473,7 @@ toShelleyAddrSet
-> Set AddressAny
-> Set (Shelley.Addr Consensus.StandardCrypto)
toShelleyAddrSet era =
Set.fromList
fromList
. map toShelleyAddr
-- Ignore any addresses that are not appropriate for the era,
-- e.g. Shelley addresses in the Byron era, as these would not
Expand All @@ -489,7 +489,7 @@ toLedgerUTxO
toLedgerUTxO sbe (UTxO utxo) =
shelleyBasedEraConstraints sbe
$ Shelley.UTxO
. Map.fromList
. fromList
. map (bimap toShelleyTxIn (toShelleyTxOut sbe))
. toList
$ utxo
Expand All @@ -502,7 +502,7 @@ fromLedgerUTxO
fromLedgerUTxO sbe (Shelley.UTxO utxo) =
shelleyBasedEraConstraints sbe
$ UTxO
. Map.fromList
. fromList
. map (bimap fromShelleyTxIn (fromShelleyTxOut sbe))
. toList
$ utxo
Expand All @@ -513,7 +513,7 @@ fromShelleyPoolDistr
fromShelleyPoolDistr =
-- TODO: write an appropriate property to show it is safe to use
-- Map.fromListAsc or to use Map.mapKeysMonotonic
Map.fromList
fromList
. map (bimap StakePoolKeyHash Consensus.individualPoolStake)
. toList
. Consensus.unPoolDistr
Expand All @@ -528,7 +528,7 @@ fromShelleyDelegations =
-- Map.fromListAsc or to use Map.mapKeysMonotonic
-- In this case it may not be: the Ord instances for Shelley.Credential
-- do not match the one for StakeCredential
Map.fromList
fromList
. map (bimap fromShelleyStakeCredential StakePoolKeyHash)
. toList

Expand All @@ -538,7 +538,7 @@ fromShelleyRewardAccounts
fromShelleyRewardAccounts =
-- TODO: write an appropriate property to show it is safe to use
-- Map.fromListAsc or to use Map.mapKeysMonotonic
Map.fromList
fromList
. map (first fromShelleyStakeCredential)
. toList

Expand Down
3 changes: 1 addition & 2 deletions cardano-api/internal/Cardano/Api/Rewards.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import qualified Data.Aeson.Types as Aeson
import Data.List (nub)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Data.Vector as Vector
import GHC.Exts (IsList (..))

-- | A mapping of Shelley reward accounts to both the stake pool that they
Expand All @@ -27,7 +26,7 @@ newtype DelegationsAndRewards
instance ToJSON DelegationsAndRewards where
toJSON delegsAndRwds =
Aeson.Array
. Vector.fromList
. fromList
. map delegAndRwdToJson
$ mergeDelegsAndRewards delegsAndRwds
where
Expand Down
Loading

0 comments on commit 9f65da7

Please sign in to comment.