Skip to content

Commit

Permalink
Remove NoImplicitPrelude and avoid import of Cardano.Prelude where po…
Browse files Browse the repository at this point in the history
…ssible.
  • Loading branch information
newhoggy committed Feb 7, 2023
1 parent 6d755f3 commit c742dfc
Show file tree
Hide file tree
Showing 74 changed files with 404 additions and 275 deletions.
3 changes: 2 additions & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -119,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 @@ -174,7 +176,6 @@ test-suite cardano-cli-test
, cardano-api:gen
, cardano-cli
, cardano-node
, cardano-prelude
, cardano-slotting ^>= 0.1
, containers
, directory
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
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
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
20 changes: 13 additions & 7 deletions cardano-cli/src/Cardano/CLI/Byron/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ module Cardano.CLI.Byron.Tx
)
where

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

import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, left, newExceptT)
import Data.Bifunctor (Bifunctor (..))
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
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 qualified Data.Text as T
import Data.Maybe (fromMaybe, mapMaybe)
import Data.String (IsString)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import Formatting (sformat, (%))

import Cardano.Api
Expand Down Expand Up @@ -128,9 +134,9 @@ genesisUTxOTxIn gc vk genAddr =
handleMissingAddr :: Maybe UTxO.TxIn -> UTxO.TxIn
handleMissingAddr = fromMaybe . error
$ "\nGenesis UTxO has no address\n"
<> T.unpack (prettyAddress (ByronAddress genAddr))
<> Text.unpack (prettyAddress (ByronAddress genAddr))
<> "\n\nIt has the following, though:\n\n"
<> Cardano.Prelude.concat (T.unpack . prettyAddress <$> map ByronAddress (Map.keys initialUtxo))
<> List.concatMap (Text.unpack . prettyAddress . ByronAddress) (Map.keys initialUtxo)

-- | Generate a transaction spending genesis UTxO at a given address,
-- to given outputs, signed by the given key.
Expand Down Expand Up @@ -233,7 +239,7 @@ nodeSubmitTx network gentx = do
}
res <- liftIO $ submitTxToNodeLocal connctInfo (TxInByronSpecial gentx ByronEraInCardanoMode)
case res of
Net.Tx.SubmitSuccess -> liftIO $ putTextLn "Transaction successfully submitted."
Net.Tx.SubmitSuccess -> liftIO $ Text.putStrLn "Transaction successfully submitted."
Net.Tx.SubmitFail reason ->
case reason of
TxValidationErrorInMode err _eraInMode -> left . ByronTxSubmitError . Text.pack $ show err
Expand Down
22 changes: 15 additions & 7 deletions cardano-cli/src/Cardano/CLI/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ module Cardano.CLI.Helpers
, hushM
) where

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

import Codec.CBOR.Pretty (prettyHexEnc)
import Codec.CBOR.Read (DeserialiseFailure, deserialiseFromBytes)
Expand All @@ -35,6 +34,15 @@ import qualified Cardano.Chain.Update as Update
import qualified Cardano.Chain.UTxO as UTxO
import Cardano.CLI.Types

import Control.Exception (Exception (..), IOException)
import Control.Monad (unless, when)
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except (ExceptT)
import Data.Bifunctor (Bifunctor (..))
import Data.ByteString (ByteString)
import Data.Functor (void)
import Data.Text (Text)
import qualified Data.Text.IO as Text
import qualified System.Directory as IO

data HelpersError
Expand All @@ -55,7 +63,7 @@ renderHelpersError err =
IOError' fp ioE -> "Error at: " <> Text.pack fp <> " Error: " <> Text.pack (show ioE)

decodeCBOR
:: LByteString
:: LB.ByteString
-> (forall s. Decoder s a)
-> Either HelpersError (LB.ByteString, a)
decodeCBOR bs decoder =
Expand Down Expand Up @@ -85,22 +93,22 @@ ensureNewFile writer outFile blob = do
ensureNewFileLBS :: FilePath -> ByteString -> ExceptT HelpersError IO ()
ensureNewFileLBS = ensureNewFile BS.writeFile

pPrintCBOR :: LByteString -> ExceptT HelpersError IO ()
pPrintCBOR :: LB.ByteString -> ExceptT HelpersError IO ()
pPrintCBOR bs = do
case deserialiseFromBytes decodeTerm bs of
Left err -> left $ CBORPrettyPrintError err
Right (remaining, decodedVal) -> do
liftIO . putTextLn . toS . prettyHexEnc $ encodeTerm decodedVal
liftIO . Text.putStrLn . toS . prettyHexEnc $ encodeTerm decodedVal
unless (LB.null remaining) $
pPrintCBOR remaining

readCBOR :: FilePath -> ExceptT HelpersError IO LByteString
readCBOR :: FilePath -> ExceptT HelpersError IO LB.ByteString
readCBOR fp =
handleIOExceptT
(ReadCBORFileFailure fp . toS . displayException)
(LB.readFile fp)

validateCBOR :: CBORObject -> LByteString -> Either HelpersError Text
validateCBOR :: CBORObject -> LB.ByteString -> Either HelpersError Text
validateCBOR cborObject bs =
case cborObject of
CBORBlockByron epochSlots -> do
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import Cardano.CLI.Byron.Parsers (backwardsCompatibilityCommands, pars
import Cardano.CLI.Render (customRenderHelp)
import Cardano.CLI.Run (ClientCommand (..))
import Cardano.CLI.Shelley.Parsers (parseShelleyCommands)
import Cardano.Prelude

import Data.Foldable
import Options.Applicative
import Prelude (String)

import qualified Options.Applicative as Opt

Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ module Cardano.CLI.Render
( customRenderHelp
) where

import Cardano.Prelude
import Data.Function (id)
import Data.Text (Text)
import Options.Applicative
import Options.Applicative.Help.Ann
import Options.Applicative.Help.Types (helpText, renderHelp)
import Prelude (String)
import Prettyprinter
import Prettyprinter.Render.Util.SimpleDocTree

import qualified Data.Text as T
import qualified System.Environment as IO
import qualified System.IO.Unsafe as IO

import Cardano.Api (textShow)

cliHelpTraceEnabled :: Bool
cliHelpTraceEnabled = IO.unsafePerformIO $ do
mValue <- IO.lookupEnv "CLI_HELP_TRACE"
Expand Down Expand Up @@ -44,7 +44,7 @@ customRenderHelpAsHtml cols
renderElement :: Ann -> Text -> Text
renderElement ann x = if cliHelpTraceEnabled
then case ann of
AnnTrace _ name -> "<span name=" <> show name <> ">" <> x <> "</span>"
AnnTrace _ name -> "<span name=" <> textShow name <> ">" <> x <> "</span>"
AnnStyle _ -> x
else x
wrapper = if cliHelpTraceEnabled
Expand Down
4 changes: 3 additions & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ module Cardano.CLI.Shelley.Key
) where

import Cardano.Api
import Cardano.Prelude

import Control.Monad.IO.Class (MonadIO (..))
import Data.Bifunctor (Bifunctor (..))
import qualified Data.ByteString as BS
import qualified Data.List.NonEmpty as NE
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text

Expand Down
17 changes: 13 additions & 4 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,30 @@ module Cardano.CLI.Shelley.Parsers
, parseTxIn
) where

import Cardano.Prelude hiding (All, Any)
import Prelude (String)
import Cardano.Prelude (ConvertText (..))

import Control.Monad.Fail (fail)
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Parser as Aeson.Parser
import qualified Data.Attoparsec.ByteString.Char8 as Atto
import Data.Bifunctor
import Data.ByteString (ByteString)
import qualified Data.ByteString.Base16 as B16
import qualified Data.ByteString.Char8 as BSC
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 (fromMaybe)
import Data.Ratio ((%))
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.Time.Clock (UTCTime)
import Data.Time.Format (defaultTimeLocale, parseTimeOrError)
import Data.Word (Word64)
import GHC.Natural (Natural)
import Network.Socket (PortNumber)
import Options.Applicative hiding (help, str)
import qualified Options.Applicative as Opt
Expand All @@ -41,6 +49,7 @@ import qualified Text.Parsec.Error as Parsec
import qualified Text.Parsec.Language as Parsec
import qualified Text.Parsec.String as Parsec
import qualified Text.Parsec.Token as Parsec
import Text.Read (readEither, readMaybe)

import qualified Cardano.Ledger.BaseTypes as Shelley
import qualified Cardano.Ledger.Shelley.TxBody as Shelley
Expand Down Expand Up @@ -2799,7 +2808,7 @@ pSingleHostAddress = singleHostAddress
singleHostAddress ipv4 ipv6 port =
case (ipv4, ipv6) of
(Nothing, Nothing) ->
panic "Please enter either an IPv4 or IPv6 address for the pool relay"
error "Please enter either an IPv4 or IPv6 address for the pool relay"
(Just i4, Nothing) ->
StakePoolRelayIp (Just i4) Nothing (Just port)
(Nothing, Just i6) ->
Expand Down
5 changes: 3 additions & 2 deletions cardano-cli/src/Cardano/CLI/Shelley/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module Cardano.CLI.Shelley.Run
, runShelleyClientCommand
) where

import Control.Monad.Trans.Except (ExceptT)
import Data.Text (Text)

import Cardano.Api

import Control.Monad.Trans.Except.Extra (firstExceptT)
Expand All @@ -22,8 +25,6 @@ import Cardano.CLI.Shelley.Run.Transaction
-- Block, System, DevOps
import Cardano.CLI.Shelley.Run.Genesis
import Cardano.CLI.Shelley.Run.TextView
import Cardano.Prelude (ExceptT)
import Data.Text (Text)

data ShelleyClientCmdError
= ShelleyCmdAddressError !ShelleyAddressCmdError
Expand Down
Loading

0 comments on commit c742dfc

Please sign in to comment.