Skip to content

Commit

Permalink
Merge pull request #558 from IntersectMBO/felix-lipski/remove-cardano…
Browse files Browse the repository at this point in the history
…-ledger-imports

Remove direct imports from `Cardano.Ledger`
  • Loading branch information
palas authored Feb 23, 2024
2 parents 615beb8 + ac64002 commit 7fad582
Show file tree
Hide file tree
Showing 87 changed files with 386 additions and 602 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

env:
# Modify this value to "invalidate" the cabal cache.
CABAL_CACHE_VERSION: "2024-02-12-2"
CABAL_CACHE_VERSION: "2024-02-23-3"

concurrency:
group: >
Expand Down
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ repository cardano-haskell-packages
-- See CONTRIBUTING for information about these, including some Nix commands
-- you need to run if you change them
index-state:
, hackage.haskell.org 2024-02-14T11:32:54Z
, cardano-haskell-packages 2024-02-14T10:17:08Z
, hackage.haskell.org 2024-02-23T02:09:28Z
, cardano-haskell-packages 2024-02-22T17:04:08Z

packages:
cardano-cli
Expand Down
9 changes: 1 addition & 8 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,14 @@ library
, binary
, bytestring
, canonical-json
, cardano-api ^>= 8.38.0.2
, cardano-api ^>= 8.39.0.0
, cardano-binary
, cardano-crypto
, cardano-crypto-class ^>= 2.1.2
, cardano-crypto-wrapper ^>= 1.5.1
, cardano-data >= 1.1
, cardano-git-rev
, cardano-ledger-alonzo >= 1.6.0.0
, cardano-ledger-binary >= 1.2
, cardano-ledger-byron >= 1.0.0.2
, cardano-ledger-conway >= 1.10
, cardano-ledger-core >= 1.8
, cardano-ledger-shelley >=1.7.0.0
, cardano-ping ^>= 0.2.0.7
, cardano-prelude
, cardano-slotting ^>= 0.1
Expand Down Expand Up @@ -275,7 +270,6 @@ library cardano-cli-test-lib
, hedgehog-extras ^>= 0.6.1.0
, process
, text
, transformers

test-suite cardano-cli-test
import: project-config
Expand All @@ -301,7 +295,6 @@ test-suite cardano-cli-test
, tasty-hedgehog
, text
, time
, transformers

build-tool-depends: tasty-discover:tasty-discover

Expand Down
18 changes: 7 additions & 11 deletions cardano-cli/src/Cardano/CLI/Byron/Delegation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@ module Cardano.CLI.Byron.Delegation
where

import Cardano.Api.Byron
import Cardano.Api.Pretty
import qualified Cardano.Api.Ledger as L

import qualified Cardano.Chain.Delegation as Dlg
import Cardano.Chain.Slotting (EpochNumber)
import Cardano.CLI.Byron.Key (ByronKeyFailure, renderByronKeyFailure)
import Cardano.CLI.Types.Common (CertificateFile (..))
import Cardano.Crypto (ProtocolMagicId)
import qualified Cardano.Crypto as Crypto
import Cardano.Ledger.Binary (Annotated (..), byronProtVer, serialize')
import Cardano.Prelude (canonicalDecodePretty, canonicalEncodePretty)

import Prelude hiding ((.))

import Control.Category
import Control.Monad (unless)
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (left)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as LB
import Data.Text (Text)
Expand Down Expand Up @@ -103,18 +99,18 @@ checkDlgCert cert magic issuerVK' delegateVK' =
]
]
where
magic' :: Annotated ProtocolMagicId ByteString
magic' = Annotated magic (serialize' byronProtVer magic)
magic' :: L.Annotated ProtocolMagicId ByteString
magic' = L.Annotated magic (L.serialize' L.byronProtVer magic)

epoch :: EpochNumber
epoch = unAnnotated $ Dlg.aEpoch cert
epoch = L.unAnnotated $ Dlg.aEpoch cert

cert' :: Dlg.ACertificate ByteString
cert' =
let unannotated = cert { Dlg.aEpoch = Annotated epoch ()
let unannotated = cert { Dlg.aEpoch = L.Annotated epoch ()
, Dlg.annotation = () }
in unannotated { Dlg.annotation = serialize' byronProtVer unannotated
, Dlg.aEpoch = Annotated epoch (serialize' byronProtVer epoch) }
in unannotated { Dlg.annotation = L.serialize' L.byronProtVer unannotated
, Dlg.aEpoch = L.Annotated epoch (L.serialize' L.byronProtVer epoch) }

vkF :: forall r. Format r (Crypto.VerificationKey -> r)
vkF = Crypto.fullVerificationKeyF
Expand Down
3 changes: 1 addition & 2 deletions cardano-cli/src/Cardano/CLI/Byron/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ where
import Cardano.Api (Key (..), NetworkId, writeSecrets)
import Cardano.Api.Byron (ByronKey, SerialiseAsRawBytes (..), SigningKey (..),
toByronRequiresNetworkMagic)
import Cardano.Api.Pretty
import Cardano.CLI.Pretty

import qualified Cardano.Chain.Common as Common
import Cardano.Chain.Delegation hiding (Map, epoch)
Expand All @@ -28,7 +28,6 @@ import Cardano.CLI.Types.Common (GenesisFile (..))
import qualified Cardano.Crypto as Crypto
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)
Expand Down
4 changes: 0 additions & 4 deletions cardano-cli/src/Cardano/CLI/Byron/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ module Cardano.CLI.Byron.Key
where

import Cardano.Api.Byron
import Cardano.Api.Pretty

import qualified Cardano.Chain.Common as Common
import Cardano.CLI.Types.Common
import qualified Cardano.Crypto.Signing as Crypto

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 (IsString, fromString)
Expand Down
5 changes: 2 additions & 3 deletions cardano-cli/src/Cardano/CLI/Byron/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Cardano.CLI.Byron.Parsers
import Cardano.Api hiding (GenesisParameters, UpdateProposal)
import Cardano.Api.Byron (Address (..), ByronProtocolParametersUpdate (..),
toByronLovelace)
import Cardano.Api.Pretty
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (ReferenceScript (ReferenceScriptNone))

import Cardano.Chain.Common (BlockCount (..), TxFeePolicy (..), TxSizeLinear (..),
Expand All @@ -50,7 +50,6 @@ import Cardano.Crypto (RequiresNetworkMagic (..))
import Cardano.Crypto.Hashing (hashRaw)
import Cardano.Crypto.ProtocolMagic (AProtocolMagic (..), ProtocolMagic,
ProtocolMagicId (..))
import Cardano.Ledger.Binary (Annotated (..))

import Control.Monad (when)
import qualified Data.Attoparsec.ByteString.Char8 as Atto
Expand Down Expand Up @@ -654,7 +653,7 @@ parseProtocolMagicId arg =

parseProtocolMagic :: Parser ProtocolMagic
parseProtocolMagic =
flip AProtocolMagic RequiresMagic . flip Annotated ()
flip AProtocolMagic RequiresMagic . flip L.Annotated ()
<$> parseProtocolMagicId "protocol-magic"

parseTxFile :: String -> Parser (TxFile In)
Expand Down
4 changes: 0 additions & 4 deletions cardano-cli/src/Cardano/CLI/Byron/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ import Cardano.CLI.Types.Common
import qualified Cardano.Crypto.Hashing as Crypto
import qualified Cardano.Crypto.Signing as Crypto

import Control.Monad.IO.Class (MonadIO (liftIO))
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, hoistEither, left)
import Data.Bifunctor (Bifunctor (..))
import qualified Data.ByteString.Char8 as BS
import Data.Text (Text)
import qualified Data.Text.IO as Text
import qualified Data.Text.Lazy.Builder as Builder
import qualified Data.Text.Lazy.IO as TL
import qualified Formatting as F
import Prettyprinter

-- | Data type that encompasses all the possible errors of the
-- Byron client.
Expand Down
9 changes: 2 additions & 7 deletions cardano-cli/src/Cardano/CLI/Byron/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ where
import Cardano.Api
import Cardano.Api.Byron
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Pretty

import qualified Cardano.Binary as Binary
import qualified Cardano.Chain.Common as Common
Expand All @@ -37,15 +36,11 @@ import qualified Cardano.Chain.UTxO as UTxO
import Cardano.CLI.Byron.Key (byronWitnessToVerKey)
import Cardano.CLI.Types.Common (TxFile)
import qualified Cardano.Crypto.Signing as Crypto
import qualified Cardano.Ledger.Binary.Decoding as LedgerBinary
import Ouroboros.Consensus.Byron.Ledger (ByronBlock, GenTx (..))
import qualified Ouroboros.Consensus.Byron.Ledger as Byron
import Ouroboros.Consensus.Cardano.Block (EraMismatch (..))
import qualified Ouroboros.Network.Protocol.LocalTxSubmission.Client as Net.Tx

import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (left)
import Data.Bifunctor (Bifunctor (..))
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
Expand Down Expand Up @@ -215,8 +210,8 @@ fromCborTxAux lbs =
<$> Binary.decodeFullDecoder "Cardano.Chain.UTxO.TxAux.fromCborTxAux"
Binary.fromCBOR lbs
where
annotationBytes :: Functor f => LB.ByteString -> f LedgerBinary.ByteSpan -> f B.ByteString
annotationBytes bytes = fmap (LB.toStrict . LedgerBinary.slice bytes)
annotationBytes :: Functor f => LB.ByteString -> f L.ByteSpan -> f B.ByteString
annotationBytes bytes = fmap (LB.toStrict . L.slice bytes)

toCborTxAux :: UTxO.ATxAux ByteString -> LB.ByteString
toCborTxAux = LB.fromStrict . UTxO.aTaAnnotation -- The ByteString anotation is the CBOR encoded version.
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Byron/UpdateProposal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Cardano.CLI.Byron.UpdateProposal
import Cardano.Api (NetworkId, SerialiseAsRawBytes (..), SocketPath)
import Cardano.Api.Byron (AsType (AsByronUpdateProposal), ByronProtocolParametersUpdate,
ByronUpdateProposal, makeByronUpdateProposal, toByronLedgerUpdateProposal)
import Cardano.Api.Pretty
import Cardano.CLI.Pretty

import Cardano.Chain.Update (InstallerHash (..), ProtocolVersion (..),
SoftwareVersion (..), SystemTag (..))
Expand Down
4 changes: 0 additions & 4 deletions cardano-cli/src/Cardano/CLI/Byron/Vote.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module Cardano.CLI.Byron.Vote
) where

import Cardano.Api.Byron
import Cardano.Api.Pretty

import qualified Cardano.Binary as Binary
import Cardano.CLI.Byron.Genesis (ByronGenesisError)
Expand All @@ -24,9 +23,6 @@ import Cardano.CLI.Types.Common
import Ouroboros.Consensus.Ledger.SupportsMempool (txId)
import Ouroboros.Consensus.Util.Condense (condense)

import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, hoistEither)
import Control.Tracer (stdoutTracer, traceWith)
import Data.Bifunctor (first)
import qualified Data.ByteString as BS
Expand Down
34 changes: 15 additions & 19 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ module Cardano.CLI.EraBased.Commands.Governance.Actions
) where

import Cardano.Api
import qualified Cardano.Api.Ledger as Ledger
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley

import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.Crypto as Crypto
import qualified Cardano.Ledger.SafeHash as Ledger

import Data.Text (Text)
import Data.Word
Expand All @@ -48,11 +44,11 @@ data GovernanceActionCmds era
data GoveranceActionUpdateCommitteeCmdArgs era
= GoveranceActionUpdateCommitteeCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, networkId :: !L.Network
, deposit :: !Lovelace
, returnAddress :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, oldCommitteeVkeySource :: ![VerificationKeyOrHashOrFile CommitteeColdKey]
, newCommitteeVkeySource :: ![(VerificationKeyOrHashOrFile CommitteeColdKey, EpochNo)]
, requiredQuorum :: !Rational
Expand All @@ -63,37 +59,37 @@ data GoveranceActionUpdateCommitteeCmdArgs era
data GovernanceActionCreateConstitutionCmdArgs era
= GovernanceActionCreateConstitutionCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, networkId :: !L.Network
, deposit :: !Lovelace
, stakeCredential :: !(VerificationKeyOrHashOrFile StakeKey)
, mPrevGovernanceActionId :: !(Maybe (TxId, Word32))
, proposalUrl :: !ProposalUrl
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, constitutionUrl :: !ConstitutionUrl
, constitutionHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, constitutionHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, outFile :: !(File () Out)
} deriving Show

-- | Datatype to carry data for the create-info governance action
data GovernanceActionInfoCmdArgs era
= GovernanceActionInfoCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, networkId :: !L.Network
, deposit :: !Lovelace
, returnStakeAddress :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, outFile :: !(File () Out)
} deriving Show

data GovernanceActionCreateNoConfidenceCmdArgs era
= GovernanceActionCreateNoConfidenceCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, networkId :: !L.Network
, deposit :: !Lovelace
, returnStakeAddress :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, governanceActionId :: !TxId
, governanceActionIndex :: !Word32
, outFile :: !(File () Out)
Expand All @@ -119,11 +115,11 @@ data GovernanceActionProtocolParametersUpdateCmdArgs era
data GovernanceActionTreasuryWithdrawalCmdArgs era
= GovernanceActionTreasuryWithdrawalCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, networkId :: !L.Network
, deposit :: !Lovelace
, returnAddr :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, treasuryWithdrawal :: ![(VerificationKeyOrHashOrFile StakeKey, Lovelace)]
, constitutionScriptHash :: !(Maybe ScriptHash)
, outFile :: !(File () Out)
Expand All @@ -140,19 +136,19 @@ data GovernanceActionViewCmdArgs era
data UpdateProtocolParametersConwayOnwards era
= UpdateProtocolParametersConwayOnwards
{ eon :: !(ConwayEraOnwards era)
, networkId :: !Ledger.Network
, networkId :: !L.Network
, deposit :: !Lovelace
, returnAddr :: !(VerificationKeyOrHashOrFile StakeKey)
, proposalUrl :: !ProposalUrl
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, governanceActionId :: !(Maybe (TxId, Word32))
, constitutionScriptHash :: !(Maybe ScriptHash)
}

data CostModelsFile era
= CostModelsFile
{ eon :: !(AlonzoEraOnwards era)
, costModelsFile :: !(File Alonzo.CostModels In)
, costModelsFile :: !(File L.CostModels In)
} deriving Show

deriving instance Show (UpdateProtocolParametersConwayOnwards era)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Cardano.CLI.EraBased.Commands.Governance.Committee
) where

import Cardano.Api
import qualified Cardano.Api.Ledger as Ledger
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley

import Cardano.CLI.Types.Key
Expand Down Expand Up @@ -61,7 +61,7 @@ data GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs era =
GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs
{ eon :: !(ConwayEraOnwards era)
, vkeyColdKeySource :: !(VerificationKeyOrHashOrFile CommitteeColdKey)
, anchor :: !(Maybe (Ledger.Anchor (Ledger.EraCrypto (ShelleyLedgerEra era))))
, anchor :: !(Maybe (L.Anchor (L.EraCrypto (ShelleyLedgerEra era))))
, outFile :: !(File () Out)
} deriving Show

Expand Down
Loading

0 comments on commit 7fad582

Please sign in to comment.