diff --git a/cabal.project b/cabal.project index b6ac83803ff..e3977ca3248 100644 --- a/cabal.project +++ b/cabal.project @@ -276,6 +276,9 @@ package cardano-wallet-read package cardano-wallet-text-class tests: True +package cardano-wallet-unit + tests: True + package cardano-numeric tests: True diff --git a/lib/primitive/lib/Cardano/Wallet/Primitive/Ledger/Read/Tx/Sealed.hs b/lib/primitive/lib/Cardano/Wallet/Primitive/Ledger/Read/Tx/Sealed.hs index 4396ad502d2..f74b3d3428c 100644 --- a/lib/primitive/lib/Cardano/Wallet/Primitive/Ledger/Read/Tx/Sealed.hs +++ b/lib/primitive/lib/Cardano/Wallet/Primitive/Ledger/Read/Tx/Sealed.hs @@ -8,26 +8,29 @@ module Cardano.Wallet.Primitive.Ledger.Read.Tx.Sealed ( fromSealedTx - , anythingFromSealedTx ) where -import Prelude - import Cardano.Api ( InAnyCardanoEra (..) ) -import Cardano.Read.Ledger.Tx.Cardano - ( fromCardanoApiTx - ) import Cardano.Wallet.Primitive.Types.Tx.SealedTx ( SealedTx (unsafeCardanoTx) ) import Cardano.Wallet.Read - ( EraValue - , Tx - , applyEraFun + ( EraValue (..) + , Tx (..) + ) +import Cardano.Wallet.Read.Eras + ( Allegra + , Alonzo + , Babbage + , Conway + , Mary + , Shelley ) +import qualified Cardano.Api as Cardano +import qualified Cardano.Api.Shelley as Cardano import qualified Cardano.Wallet.Primitive.Types.Tx.SealedTx as W fromSealedTx:: W.SealedTx -> EraValue Tx @@ -35,5 +38,12 @@ fromSealedTx sealed = case unsafeCardanoTx sealed of InAnyCardanoEra _ce tx -> fromCardanoApiTx tx -anythingFromSealedTx :: (forall era . Tx era -> a) -> SealedTx -> a -anythingFromSealedTx f = applyEraFun f . fromSealedTx +fromCardanoApiTx :: Cardano.Tx era -> EraValue Tx +fromCardanoApiTx tx0 = case tx0 of + Cardano.ShelleyTx era tx -> case era of + Cardano.ShelleyBasedEraShelley -> EraValue (Tx tx :: Tx Shelley) + Cardano.ShelleyBasedEraAllegra -> EraValue (Tx tx :: Tx Allegra) + Cardano.ShelleyBasedEraMary -> EraValue (Tx tx :: Tx Mary) + Cardano.ShelleyBasedEraAlonzo -> EraValue (Tx tx :: Tx Alonzo) + Cardano.ShelleyBasedEraBabbage -> EraValue (Tx tx :: Tx Babbage) + Cardano.ShelleyBasedEraConway -> EraValue (Tx tx :: Tx Conway) diff --git a/lib/read/cardano-wallet-read.cabal b/lib/read/cardano-wallet-read.cabal index 1e315729865..45155a5ddae 100644 --- a/lib/read/cardano-wallet-read.cabal +++ b/lib/read/cardano-wallet-read.cabal @@ -55,7 +55,6 @@ library Cardano.Read.Ledger.Tx.Inputs Cardano.Read.Ledger.Tx.Outputs Cardano.Read.Ledger.Tx.TxId - Cardano.Read.Ledger.Tx.Cardano Cardano.Read.Ledger.Tx.Certificates Cardano.Read.Ledger.Tx.CBOR Cardano.Read.Ledger.Tx.CollateralInputs @@ -106,7 +105,6 @@ library build-depends: , base , bytestring - , cardano-api , cardano-crypto , cardano-crypto-class , cardano-crypto-praos diff --git a/lib/read/lib/Cardano/Read/Ledger/Tx/Cardano.hs b/lib/read/lib/Cardano/Read/Ledger/Tx/Cardano.hs deleted file mode 100644 index fbdd9dba22c..00000000000 --- a/lib/read/lib/Cardano/Read/Ledger/Tx/Cardano.hs +++ /dev/null @@ -1,44 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE TypeApplications #-} - --- | --- Copyright: © 2020-2022 IOHK --- License: Apache-2.0 --- - -module Cardano.Read.Ledger.Tx.Cardano - ( fromCardanoApiTx - ) where - -import Prelude - -import Cardano.Read.Ledger.Eras - ( Allegra - , Alonzo - , Babbage - , Conway - , Mary - , Shelley - ) -import Cardano.Wallet.Read.Eras - ( EraValue (..) - , eraValue - ) -import Cardano.Wallet.Read.Tx - ( Tx (..) - ) - -import qualified Cardano.Api as Cardano -import qualified Cardano.Api.Shelley as Cardano - -fromCardanoApiTx :: Cardano.Tx era -> EraValue Tx -fromCardanoApiTx = \case - Cardano.ShelleyTx era tx -> case era of - Cardano.ShelleyBasedEraShelley -> eraValue @Shelley $ Tx tx - Cardano.ShelleyBasedEraAllegra -> eraValue @Allegra $ Tx tx - Cardano.ShelleyBasedEraMary -> eraValue @Mary $ Tx tx - Cardano.ShelleyBasedEraAlonzo -> eraValue @Alonzo $ Tx tx - Cardano.ShelleyBasedEraBabbage -> eraValue @Babbage $ Tx tx - Cardano.ShelleyBasedEraConway -> eraValue @Conway $ Tx tx diff --git a/lib/unit/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs b/lib/unit/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs index 64a94cc5948..468131a4019 100644 --- a/lib/unit/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs +++ b/lib/unit/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs @@ -57,9 +57,6 @@ import Cardano.Api.Gen import Cardano.Mnemonic ( SomeMnemonic (SomeMnemonic) ) -import Cardano.Read.Ledger.Tx.Cardano - ( fromCardanoApiTx - ) import Cardano.Wallet ( Fee (..) , Percentile (..) @@ -93,6 +90,9 @@ import Cardano.Wallet.Primitive.Ledger.Convert import Cardano.Wallet.Primitive.Ledger.Read.Tx.Features.Integrity ( txIntegrity ) +import Cardano.Wallet.Primitive.Ledger.Read.Tx.Sealed + ( fromSealedTx + ) import Cardano.Wallet.Primitive.Ledger.Shelley ( toCardanoTxIn ) @@ -926,18 +926,14 @@ prop_signTransaction_preservesScriptIntegrity Nothing sealedTx - txIntegrityCardanoApi = txIntegrity . fromCardanoApiTx - - getScriptIntegrityHashInAnyCardanoEra - :: InAnyCardanoEra Cardano.Tx - -> Maybe ByteString - getScriptIntegrityHashInAnyCardanoEra (InAnyCardanoEra _ tx') = - getHash <$> txIntegrityCardanoApi tx' + getScriptIntegrityHash :: SealedTx -> Maybe ByteString + getScriptIntegrityHash = + fmap getHash . txIntegrity . fromSealedTx scriptIntegrityHashBefore = - getScriptIntegrityHashInAnyCardanoEra $ cardanoTx sealedTx + getScriptIntegrityHash sealedTx scriptIntegrityHashAfter = - getScriptIntegrityHashInAnyCardanoEra $ cardanoTx sealedTx' + getScriptIntegrityHash sealedTx' checkCoverage $ cover 30 (isJust scriptIntegrityHashBefore)