Skip to content

Commit

Permalink
Merge #4857
Browse files Browse the repository at this point in the history
4857: Remove NoImplicitPrelude r=newhoggy a=newhoggy

Remove from `NoImplicitPrelude` from `cardano-api` `cardano-submit-api` `cardano-cli` `cardano-testnet` `cardano-node-chairman` `cardano-node` and `cardano-git-rev`.
Remove dependency on `cardano-prelude` wherever possible.

Removed imported of `Cardano.Prelude` where possible (excluding `bench`).  Remaining occurrences are those that are still required:

* `canonicalDecodePretty`
* `canonicalEncodePretty`
* `cborError`
* `ConvertText (..)`
* `FatalError (..)`
* `maximumDef`

Co-authored-by: John Ky <john.ky@iohk.io>
  • Loading branch information
iohk-bors[bot] and newhoggy authored Feb 11, 2023
2 parents 75130f1 + 88e6501 commit b038efc
Show file tree
Hide file tree
Showing 204 changed files with 733 additions and 706 deletions.
2 changes: 0 additions & 2 deletions cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ library
, cardano-ledger-byron ^>= 0.1
, cardano-ledger-core ^>= 0.1
, cardano-ledger-shelley-ma ^>= 0.1
, cardano-prelude
, cardano-protocol-tpraos >= 0.1
, cardano-slotting >= 0.1
, cborg
Expand Down Expand Up @@ -197,7 +196,6 @@ library gen
, cardano-ledger-alonzo-test
, cardano-ledger-byron-test ^>= 1.4
, cardano-ledger-core ^>= 0.1
, cardano-prelude
, containers
, hedgehog
, cardano-ledger-shelley ^>= 0.1
Expand Down
5 changes: 1 addition & 4 deletions cardano-api/gen/Test/Gen/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ module Test.Gen.Cardano.Api
, genAlonzoGenesis
) where

import Cardano.Prelude (panic)

import Cardano.Api.Shelley as Api

import qualified Data.Map.Strict as Map
import qualified Data.Text as Text
import Data.Word (Word64)

--TODO: why do we have this odd split? We can get rid of the old name "typed"
Expand Down Expand Up @@ -92,7 +89,7 @@ genCostModels = do
CostModel cModel <- genCostModel
lang <- genLanguage
case Alonzo.mkCostModel lang cModel of
Left err -> panic . Text.pack $ "genCostModels: " <> show err
Left err -> error $ "genCostModels: " <> show err
Right alonzoCostModel ->
Alonzo.CostModels . conv <$> Gen.list (Range.linear 1 3) (return alonzoCostModel)
where
Expand Down
7 changes: 2 additions & 5 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ module Test.Gen.Cardano.Api.Typed
, genRational
) where

import Cardano.Prelude (panic)

import Cardano.Api hiding (txIns)
import qualified Cardano.Api as Api
import Cardano.Api.Byron (KeyWitness (ByronKeyWitness),
Expand All @@ -127,7 +125,6 @@ import Data.Map.Strict (Map)
import Data.Maybe (maybeToList)
import Data.Ratio (Ratio, (%))
import Data.String
import qualified Data.Text as Text
import Data.Word (Word64)
import Numeric.Natural (Natural)

Expand Down Expand Up @@ -498,7 +495,7 @@ genTxValidityUpperBound era =
pure (TxValidityNoUpperBound supported)

(Nothing, Nothing) ->
panic "genTxValidityUpperBound: unexpected era support combination"
error "genTxValidityUpperBound: unexpected era support combination"

genTxValidityRange
:: CardanoEra era
Expand Down Expand Up @@ -863,7 +860,7 @@ genCostModel = do
eCostModel <- Alonzo.mkCostModel <$> genPlutusLanguage
<*> mapM (const $ Gen.integral (Range.linear 0 5000)) costModelParams
case eCostModel of
Left err -> panic $ Text.pack $ "genCostModel: " <> show err
Left err -> error $ "genCostModel: " <> show err
Right cModel -> return . CostModel $ Alonzo.getCostModelParams cModel

genPlutusLanguage :: Gen Language
Expand Down
6 changes: 2 additions & 4 deletions cardano-api/src/Cardano/Api/Keys/Byron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ module Cardano.Api.Keys.Byron (
toByronSigningKey
) where

import qualified Cardano.Prelude as CBOR (toCborError)

import qualified Codec.CBOR.Decoding as CBOR
import qualified Codec.CBOR.Read as CBOR
import Control.Monad
Expand All @@ -42,6 +40,7 @@ import Data.Either.Combinators
import Data.String (IsString)
import Data.Text (Text)
import qualified Data.Text as Text
import Formatting (build, formatToString)

import qualified Cardano.Crypto.DSIGN.Class as Crypto
import qualified Cardano.Crypto.Seed as Crypto
Expand Down Expand Up @@ -272,8 +271,7 @@ instance SerialiseAsRawBytes (SigningKey ByronKeyLegacy) where
)

decodeXPrv :: CBOR.Decoder s Wallet.XPrv
decodeXPrv = CBOR.decodeBytesCanonical >>= CBOR.toCborError . Wallet.xprv

decodeXPrv = CBOR.decodeBytesCanonical >>= either (fail . formatToString build) pure . Wallet.xprv

-- | Decoder for a Byron/Classic signing key.
-- Lifted from cardano-sl legacy codebase.
Expand Down
3 changes: 2 additions & 1 deletion cardano-api/src/Cardano/Api/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Data.Type.Equality (TestEquality (..), (:~:) (Refl))
import qualified Data.Vector as Vector
import Formatting (build, formatToString)

--
-- Common types, consensus, network
Expand Down Expand Up @@ -431,7 +432,7 @@ decodeShelleyBasedWitness era =
case t of
0 -> fmap (fmap (ShelleyKeyWitness era)) fromCBOR
1 -> fmap (fmap (ShelleyBootstrapWitness era)) fromCBOR
_ -> CBOR.cborError $ CBOR.DecoderErrorUnknownTag
_ -> fail . formatToString build $ CBOR.DecoderErrorUnknownTag
"Shelley Witness" (fromIntegral t)


Expand Down
2 changes: 0 additions & 2 deletions cardano-cli/app/cardano-cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#define UNIX
#endif

import Cardano.Prelude

import Control.Monad.Trans.Except.Exit (orDie)
import qualified Options.Applicative as Opt

Expand Down
9 changes: 5 additions & 4 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ Flag unexpected_thunks
common project-config
default-language: Haskell2010

default-extensions: NoImplicitPrelude
OverloadedStrings
default-extensions: OverloadedStrings
build-depends: base >= 4.14 && < 4.17

ghc-options: -Wall
Expand Down Expand Up @@ -120,10 +119,12 @@ library
, cborg >= 0.2.4 && < 0.3
, containers
, cryptonite
, deepseq
, directory
, filepath
, formatting
, iproute
, mtl
, network
, optparse-applicative-fork
, ouroboros-consensus
Expand Down Expand Up @@ -157,7 +158,6 @@ executable cardano-cli

build-depends: cardano-cli
, cardano-crypto-class ^>= 2.0
, cardano-prelude
, optparse-applicative-fork
, transformers-except

Expand All @@ -171,11 +171,11 @@ test-suite cardano-cli-test
build-depends: aeson
, bech32 >= 1.1.0
, base16-bytestring
, bytestring
, cardano-api
, cardano-api:gen
, cardano-cli
, cardano-node
, cardano-prelude
, cardano-slotting ^>= 0.1
, containers
, directory
Expand Down Expand Up @@ -231,6 +231,7 @@ test-suite cardano-cli-golden
, hedgehog-extras
, text
, time
, transformers
, unordered-containers
build-tool-depends: cardano-cli:cardano-cli

Expand Down
6 changes: 3 additions & 3 deletions cardano-cli/src/Cardano/CLI/Byron/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ module Cardano.CLI.Byron.Commands
, NewCertificateFile (..)
) where

import Cardano.Prelude
import Data.String (IsString)

import Cardano.Chain.Update (InstallerHash (..), ProtocolVersion (..),
SoftwareVersion (..), SystemTag (..))
SoftwareVersion (..), SystemTag (..))

import Cardano.Api hiding (GenesisParameters)
import Cardano.Api hiding (GenesisParameters)
import Cardano.Api.Byron hiding (GenesisParameters)

import Cardano.CLI.Byron.Genesis
Expand Down
9 changes: 8 additions & 1 deletion cardano-cli/src/Cardano/CLI/Byron/Delegation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ module Cardano.CLI.Byron.Delegation
)
where

import Cardano.Prelude hiding (show, trace)
import Prelude hiding ((.))

import Control.Category
import Control.Monad.Trans.Except.Extra (left)
import qualified Data.ByteString.Lazy as LB
import Formatting (Format, sformat)
Expand All @@ -28,6 +29,12 @@ import qualified Cardano.Crypto as Crypto

import Cardano.CLI.Byron.Key (ByronKeyFailure, renderByronKeyFailure)
import Cardano.CLI.Types (CertificateFile (..))
import Cardano.Prelude (canonicalDecodePretty, canonicalEncodePretty)
import Control.Monad (unless)
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except (ExceptT)
import Data.ByteString (ByteString)
import Data.Text (Text)

data ByronDelegationError
= CertificateValidationErrors !FilePath ![Text]
Expand Down
17 changes: 13 additions & 4 deletions cardano-cli/src/Cardano/CLI/Byron/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ module Cardano.CLI.Byron.Genesis
)
where

import Cardano.Prelude hiding (show, trace)
import Prelude (String)
import Cardano.Prelude (canonicalDecodePretty, canonicalEncodePretty)

import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans (MonadTrans (..))
import Control.Monad.Trans.Except (ExceptT (..), withExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, left, right)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as LB
import qualified Data.List as List
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.String (IsString)
import Data.Text (Text)
import qualified Data.Text.Encoding as Text
import Data.Text.Lazy (toStrict)
import Data.Text.Lazy.Builder (toLazyText)
import Data.Time (UTCTime)
import Formatting.Buildable
Expand Down Expand Up @@ -187,7 +196,7 @@ dumpGenesis (NewDirectory outDir) genesisData gs = do

findDelegateCert :: SigningKey ByronKey -> ExceptT ByronGenesisError IO Certificate
findDelegateCert bSkey@(ByronSigningKey sk) =
case find (isCertForSK sk) (Map.elems dlgCertMap) of
case List.find (isCertForSK sk) (Map.elems dlgCertMap) of
Nothing -> left . NoGenesisDelegationForKey
. prettyPublicKey $ getVerificationKey bSkey
Just x -> right x
Expand All @@ -196,7 +205,7 @@ dumpGenesis (NewDirectory outDir) genesisData gs = do
genesisJSONFile = outDir <> "/genesis.json"

printFakeAvvmSecrets :: Crypto.RedeemSigningKey -> ByteString
printFakeAvvmSecrets rskey = encodeUtf8 . toStrict . toLazyText $ build rskey
printFakeAvvmSecrets rskey = Text.encodeUtf8 . toStrict . toLazyText $ build rskey

-- Compare a given 'SigningKey' with a 'Certificate' 'VerificationKey'
isCertForSK :: Crypto.SigningKey -> Certificate -> Bool
Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/Byron/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ module Cardano.CLI.Byron.Key
)
where

import Cardano.Prelude hiding (show, trace, (%))
import Prelude (show)

import Control.Exception (Exception (..))
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, hoistEither, left,
right)
import qualified Data.ByteString as SB
import qualified Data.ByteString.UTF8 as UTF8
import Data.String (fromString)
import Data.String (IsString, fromString)
import Data.Text (Text)
import qualified Data.Text as T
import Formatting (build, sformat, (%))

Expand Down
13 changes: 9 additions & 4 deletions cardano-cli/src/Cardano/CLI/Byron/Legacy.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}

Expand All @@ -10,13 +9,19 @@ module Cardano.CLI.Byron.Legacy (
, decodeLegacyDelegateKey
) where

import Cardano.Prelude
import Cardano.Prelude (cborError)

import Control.Monad (when)
import Formatting (build, formatToString)

import qualified Codec.CBOR.Decoding as D
import qualified Codec.CBOR.Encoding as E

import Cardano.Api (textShow)
import Cardano.Crypto.Signing (SigningKey (..))
import qualified Cardano.Crypto.Wallet as Wallet
import Data.Text (Text)


-- | LegacyDelegateKey is a subset of the UserSecret's from the legacy codebase:
-- 1. the VSS keypair must be present
Expand All @@ -31,7 +36,7 @@ encodeXPrv a = E.encodeBytes $ Wallet.unXPrv a

decodeXPrv :: D.Decoder s Wallet.XPrv
decodeXPrv =
toCborError . Wallet.xprv =<< D.decodeBytesCanonical
either (fail . formatToString build) pure . Wallet.xprv =<< D.decodeBytesCanonical

-- Stolen from: cardano-sl/binary/src/Pos/Binary/Class/Core.hs
-- | Enforces that the input size is the same as the decoded one, failing in
Expand All @@ -44,7 +49,7 @@ enforceSize lbl requestedSize = D.decodeListLenCanonical >>= matchSize requested
matchSize :: Int -> Text -> Int -> D.Decoder s ()
matchSize requestedSize lbl actualSize =
when (actualSize /= requestedSize) $
cborError (lbl <> " failed the size check. Expected " <> show requestedSize <> ", found " <> show actualSize)
cborError (lbl <> " failed the size check. Expected " <> textShow requestedSize <> ", found " <> textShow actualSize)

-- | Encoder for a Byron/Classic signing key.
-- Lifted from cardano-sl legacy codebase.
Expand Down
19 changes: 11 additions & 8 deletions cardano-cli/src/Cardano/CLI/Byron/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ module Cardano.CLI.Byron.Parsers
, parseUpdateVoteThd
) where

import Cardano.Prelude
import Prelude (String)
import Cardano.Prelude (ConvertText (..))

import Control.Monad (fail)
import Control.Monad (when)
import qualified Data.Attoparsec.ByteString.Char8 as Atto
import Data.Attoparsec.Combinator ((<?>))
import qualified Data.ByteString.Char8 as BSC
import qualified Data.ByteString.Lazy.Char8 as C8
import qualified Data.Char as Char
import qualified Data.Text as Text
import Data.Foldable
import Data.Text (Text)
import Data.Time (UTCTime)
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
import Data.Word (Word16, Word64)
import Formatting (build, sformat)
import GHC.Natural (Natural)
import GHC.Word (Word8)

import Options.Applicative
import qualified Options.Applicative as Opt
Expand Down Expand Up @@ -301,13 +304,13 @@ parseTxOut =
pAddressInEra :: Text -> AddressInEra ByronEra
pAddressInEra t =
case decodeAddressBase58 t of
Left err -> panic $ "Bad Base58 address: " <> Text.pack (show err)
Left err -> error $ "Bad Base58 address: " <> show err
Right byronAddress -> AddressInEra ByronAddressInAnyEra $ ByronAddress byronAddress

pLovelaceTxOut :: Word64 -> TxOutValue ByronEra
pLovelaceTxOut l =
if l > (maxBound :: Word64)
then panic $ show l <> " lovelace exceeds the Word64 upper bound"
then error $ show l <> " lovelace exceeds the Word64 upper bound"
else TxOutAdaOnly AdaOnlyInByronEra . Lovelace $ toInteger l

readerFromAttoParser :: Atto.Parser a -> Opt.ReadM a
Expand Down Expand Up @@ -706,7 +709,7 @@ parseUTCTime optname desc =
cliParseBase58Address :: Text -> Address ByronAddr
cliParseBase58Address t =
case decodeAddressBase58 t of
Left err -> panic $ "Bad Base58 address: " <> Text.pack (show err)
Left err -> error $ "Bad Base58 address: " <> show err
Right byronAddress -> ByronAddress byronAddress

parseFraction :: String -> String -> Parser Rational
Expand Down Expand Up @@ -735,7 +738,7 @@ parseLovelace optname desc =
then fail $ show i <> " lovelace exceeds the Word64 upper bound"
else case toByronLovelace (Lovelace i) of
Just byronLovelace -> return byronLovelace
Nothing -> panic $ "Error converting lovelace: " <> Text.pack (show i)
Nothing -> error $ "Error converting lovelace: " <> show i

readDouble :: ReadM Double
readDouble = do
Expand Down
Loading

0 comments on commit b038efc

Please sign in to comment.