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

Remove direct dependencies from cardano-ledger-* #941

Merged
merged 3 commits into from
Oct 21, 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
4 changes: 0 additions & 4 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ library
cardano-crypto-wrapper ^>=1.5.1,
cardano-data >=1.1,
cardano-git-rev ^>=0.2.2,
cardano-ledger-api,
cardano-ledger-core,
cardano-ledger-shelley,
cardano-ping ^>=0.5,
cardano-prelude,
cardano-slotting ^>=0.2.0.0,
Expand Down Expand Up @@ -377,7 +374,6 @@ test-suite cardano-cli-golden
cardano-cli,
cardano-cli:cardano-cli-test-lib,
cardano-crypto-wrapper,
cardano-ledger-shelley >=1.10.0.0,
cardano-strict-containers ^>=0.1,
cborg,
containers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Cardano.CLI.EraBased.Options.Governance.DRep
where

import Cardano.Api
import Cardano.Api.Ledger (extractHash)
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (Hash (DRepMetadataHash))

Expand All @@ -22,7 +21,6 @@ import Cardano.CLI.Parser
import Cardano.CLI.Read
import Cardano.CLI.Types.Common hiding (CheckHash)
import Cardano.CLI.Types.Key
import Cardano.Ledger.SafeHash (castSafeHash)

import Control.Applicative
import Data.Foldable
Expand Down Expand Up @@ -135,7 +133,7 @@ pDrepMetadataUrl =

pExpectedDrepMetadataHash :: Parser (Hash DRepMetadata)
pExpectedDrepMetadataHash =
pExpectedHash (DRepMetadataHash . extractHash . castSafeHash) "DRep metadata"
pExpectedHash (DRepMetadataHash . L.extractHash . L.castSafeHash) "DRep metadata"

pDrepMetadataHash :: Parser (L.SafeHash L.StandardCrypto L.AnchorData)
pDrepMetadataHash =
Expand Down
12 changes: 4 additions & 8 deletions cardano-cli/src/Cardano/CLI/Json/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ where

import Cardano.Api as Api
import Cardano.Api.Byron (KeyWitness (ByronKeyWitness))
import Cardano.Api.Ledger (extractHash, strictMaybeToMaybe)
import Cardano.Api.Ledger (ExUnits (..), extractHash, strictMaybeToMaybe)
import qualified Cardano.Api.Ledger as L
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley (Hash (..),
KeyWitness (ShelleyBootstrapWitness, ShelleyKeyWitness), Proposal (..),
ShelleyLedgerEra, StakeAddress (..), Tx (ShelleyTx),
Expand All @@ -54,11 +55,6 @@ import Cardano.CLI.Orphans ()
import Cardano.CLI.Types.Common (ViewOutputFormat (..))
import Cardano.CLI.Types.MonadWarning (MonadWarning, runWarningIO)
import Cardano.Crypto.Hash (hashToTextAsHex)
import qualified Cardano.Ledger.Api as Ledger
import Cardano.Ledger.Api.Tx.In (txIxToInt)
import Cardano.Ledger.Plutus (ExUnits (..))
import Cardano.Ledger.Plutus.Data (unData)
import qualified Cardano.Ledger.TxIn as Ledger

import Data.Aeson (Value (..), object, toJSON, (.=))
import qualified Data.Aeson as Aeson
Expand Down Expand Up @@ -359,7 +355,7 @@ getRedeemerDetails aeo tb =
friendlyRedeemer :: Ledger.Data (ShelleyLedgerEra era) -> ExUnits -> Aeson.Value
friendlyRedeemer scriptData ExUnits{exUnitsSteps = exSteps, exUnitsMem = exMemUnits} =
object
[ "data" .= Aeson.String (T.pack $ show $ unData scriptData)
[ "data" .= Aeson.String (T.pack $ show $ Ledger.unData scriptData)
, "execution units"
.= object
[ "steps" .= Aeson.Number (fromIntegral exSteps)
Expand Down Expand Up @@ -394,7 +390,7 @@ getRedeemerDetails aeo tb =
friendlyInput (Ledger.TxIn (Ledger.TxId txidHash) ix) =
Aeson.String $
T.pack $
T.unpack (hashToTextAsHex (extractHash txidHash)) ++ "#" ++ show (txIxToInt ix)
T.unpack (hashToTextAsHex (extractHash txidHash)) ++ "#" ++ show (Ledger.txIxToInt ix)

addLabelToPurpose :: ToJSON v => EraIndependentPlutusScriptPurpose -> v -> Aeson.Value
addLabelToPurpose Spending sp = Aeson.object ["spending script witnessed input" .= sp]
Expand Down
4 changes: 1 addition & 3 deletions cardano-cli/src/Cardano/CLI/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ module Cardano.CLI.Orphans
where

import Cardano.Api
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (scriptDataToJsonDetailedSchema)

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

import Data.Aeson

-- TODO upstream this orphaned instance to the ledger
Expand Down
9 changes: 4 additions & 5 deletions cardano-cli/src/Cardano/CLI/Types/Errors/HashCmdError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Cardano.Api
import qualified Cardano.Api.Ledger as L

import Cardano.CLI.Read (ScriptDecodeError)
import Cardano.Ledger.SafeHash (extractHash)
import Cardano.Prelude (Exception (displayException), IOException)

import Network.HTTP.Client (HttpException)
Expand All @@ -35,9 +34,9 @@ instance Error HashCmdError where
HashMismatchedHashError expectedHash actualHash ->
"Hashes do not match!"
<> "\nExpected:"
<+> pretty (show (extractHash expectedHash))
<+> pretty (show (L.extractHash expectedHash))
<> "\n Actual:"
<+> pretty (show (extractHash actualHash))
<+> pretty (show (L.extractHash actualHash))
HashReadFileError filepath exc ->
"Cannot read" <+> pretty filepath <> ":" <+> pretty (displayException exc)
HashWriteFileError fileErr ->
Expand Down Expand Up @@ -92,7 +91,7 @@ instance Exception HashCheckError where
displayException (HashMismatchError expectedHash actualHash) =
"Hashes do not match!"
<> "\nExpected: "
<> show (extractHash expectedHash)
<> show (L.extractHash expectedHash)
<> "\n Actual: "
<> show (extractHash actualHash)
<> show (L.extractHash actualHash)
displayException (FetchURLError fetchErr) = displayException fetchErr
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Test.Golden.CreateStaked where

import Cardano.Api.Ledger (StandardCrypto)
import Cardano.Api.Ledger (ShelleyGenesisStaking (sgsPools, sgsStake), StandardCrypto)
import Cardano.Api.Shelley (ShelleyGenesis (sgNetworkMagic, sgStaking))

import Cardano.Ledger.Shelley.Genesis (ShelleyGenesisStaking (sgsPools, sgsStake))

import Control.Monad (filterM, void)
import Control.Monad.IO.Class
import qualified Data.Aeson as Aeson
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ module Test.Golden.CreateTestnetData where

import Cardano.Api
import Cardano.Api.Ledger (ConwayGenesis (..), StandardCrypto)
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (ShelleyGenesis (..))

import qualified Cardano.Ledger.Shelley.API as L

import Control.Monad
import Data.List (intercalate, sort)
import qualified Data.Sequence.Strict as Seq
Expand Down Expand Up @@ -177,9 +176,9 @@ hprop_golden_create_testnet_data_deleg_non_deleg =
genesis :: ShelleyGenesis StandardCrypto <- H.readJsonFileOk $ outputDir </> "shelley-genesis.json"

-- Because we don't test this elsewhere in this file:
(L.sgMaxLovelaceSupply genesis) H.=== (fromIntegral totalSupply)
(sgMaxLovelaceSupply genesis) H.=== (fromIntegral totalSupply)

let initialFunds = toList $ L.sgInitialFunds genesis
let initialFunds = toList $ sgInitialFunds genesis
-- This checks that there is actually only one funded address
(length initialFunds) H.=== 1

Expand All @@ -205,7 +204,7 @@ hprop_golden_create_testnet_data_shelley_genesis_output =
vanillaShelleyGenesis :: ShelleyGenesis StandardCrypto <-
H.readJsonFileOk "test/cardano-cli-golden/files/input/shelley/genesis/genesis.spec.json"
let tweakedValue = 3_123_456_000_000
tweakedShelleyGenesis = vanillaShelleyGenesis{L.sgMaxLovelaceSupply = tweakedValue}
tweakedShelleyGenesis = vanillaShelleyGenesis{sgMaxLovelaceSupply = tweakedValue}
tweakedShelleyGenesisFp = tempDir </> "tweaked-shelley-genesis.json"

void $ liftIO $ writeFileJSON tweakedShelleyGenesisFp tweakedShelleyGenesis
Expand Down
Loading