diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/Tx.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/Tx.hs index 8fb4b5766e1..a38accdc1af 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Tx.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Tx.hs @@ -2,13 +2,6 @@ module Hydra.Cardano.Api.Tx where import Hydra.Cardano.Api.Prelude -import Hydra.Cardano.Api.KeyWitness ( - fromLedgerTxWitness, - toLedgerBootstrapWitness, - toLedgerKeyWitness, - ) -import Hydra.Cardano.Api.TxScriptValidity (toLedgerScriptValidity) - import Cardano.Api.UTxO qualified as UTxO import Cardano.Ledger.Allegra.Scripts (translateTimelock) import Cardano.Ledger.Alonzo qualified as Ledger @@ -31,8 +24,6 @@ import Cardano.Ledger.Api ( dataTxOutL, datsTxWitsL, feeTxBodyL, - hashScriptTxWitsL, - hashTxAuxData, inputsTxBodyL, isValidTxL, mintTxBodyL, @@ -55,9 +46,8 @@ import Cardano.Ledger.Api ( ) import Cardano.Ledger.Api qualified as Ledger import Cardano.Ledger.Babbage qualified as Ledger -import Cardano.Ledger.Babbage.Tx qualified as Ledger import Cardano.Ledger.Babbage.TxWits (upgradeTxDats) -import Cardano.Ledger.BaseTypes (StrictMaybe (..), maybeToStrictMaybe, strictMaybeToMaybe) +import Cardano.Ledger.BaseTypes (maybeToStrictMaybe) import Cardano.Ledger.Coin (Coin (..)) import Cardano.Ledger.Conway.Scripts (PlutusScript (..)) import Cardano.Ledger.Conway.Scripts qualified as Conway @@ -207,55 +197,14 @@ txFee' (getTxBody -> TxBody body) = -- | Convert a cardano-api 'Tx' into a matching cardano-ledger 'Tx'. toLedgerTx :: - forall era. - ( Ledger.EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto - , Ledger.AlonzoEraTx (ShelleyLedgerEra era) - ) => Tx era -> Ledger.Tx (ShelleyLedgerEra era) -toLedgerTx = \case - Tx (ShelleyTxBody _era body scripts scriptsData auxData validity) vkWits -> - let (datums, redeemers) = - case scriptsData of - TxBodyScriptData _ ds rs -> (ds, rs) - TxBodyNoScriptData -> (mempty, Ledger.Redeemers mempty) - wits = - mkBasicTxWits - & addrTxWitsL .~ toLedgerKeyWitness vkWits - & bootAddrTxWitsL .~ toLedgerBootstrapWitness vkWits - & hashScriptTxWitsL .~ scripts - & datsTxWitsL .~ datums - & rdmrsTxWitsL .~ redeemers - in mkBasicTx - (body & auxDataHashTxBodyL .~ maybe SNothing (SJust . hashTxAuxData) auxData) - & isValidTxL .~ toLedgerScriptValidity validity - & auxDataTxL .~ maybeToStrictMaybe auxData - & witsTxL .~ wits +toLedgerTx (ShelleyTx _era tx) = tx -- | Convert a cardano-ledger's 'Tx' in the Babbage era into a cardano-api 'Tx'. -fromLedgerTx :: Ledger.Tx (ShelleyLedgerEra Era) -> Tx Era -fromLedgerTx ledgerTx = - Tx - (ShelleyTxBody shelleyBasedEra body' scripts scriptsData (strictMaybeToMaybe auxData) validity) - (fromLedgerTxWitness wits) - where - -- XXX: The suggested way (by the ledger team) forward is to use lenses to - -- introspect ledger transactions. - Ledger.AlonzoTx body wits isValid auxData = ledgerTx - body' = body & auxDataHashTxBodyL .~ (hashTxAuxData <$> auxData) - - scripts = - Map.elems $ Ledger.txscripts' wits - - scriptsData :: TxBodyScriptData Era - scriptsData = - TxBodyScriptData - alonzoEraOnwards - (Ledger.txdats' wits) - (Ledger.txrdmrs' wits) - - validity = case isValid of - Ledger.IsValid True -> - TxScriptValidity alonzoEraOnwards ScriptValid - Ledger.IsValid False -> - TxScriptValidity alonzoEraOnwards ScriptInvalid +fromLedgerTx :: + IsShelleyBasedEra era => + Ledger.Tx (ShelleyLedgerEra era) -> + Tx era +fromLedgerTx = + ShelleyTx shelleyBasedEra diff --git a/hydra-node/test/Hydra/Ledger/CardanoSpec.hs b/hydra-node/test/Hydra/Ledger/CardanoSpec.hs index 3dbed3aca5c..b1bd3e38ae1 100644 --- a/hydra-node/test/Hydra/Ledger/CardanoSpec.hs +++ b/hydra-node/test/Hydra/Ledger/CardanoSpec.hs @@ -8,11 +8,9 @@ import Hydra.Prelude import Test.Hydra.Prelude import Cardano.Binary (decodeFull, serialize') -import Cardano.Ledger.Api (auxDataHashTxBodyL, bodyTxL, ensureMinCoinTxOut) -import Cardano.Ledger.BaseTypes (StrictMaybe (..)) +import Cardano.Ledger.Api (ensureMinCoinTxOut) import Cardano.Ledger.Core (PParams ()) import Cardano.Ledger.Credential (Credential (..)) -import Control.Lens ((.~)) import Data.Aeson (eitherDecode, encode) import Data.Aeson qualified as Aeson import Data.Aeson.Lens (key) @@ -73,8 +71,6 @@ spec = prop "Roundtrip to and from Ledger" roundtripLedger - prop "Roundtrip tx metadata" roundtripTxMetadata - prop "Roundtrip CBOR encoding" $ roundtripCBOR @Tx prop "JSON encoding of Tx according to schema" $ @@ -156,10 +152,6 @@ roundtripLedger :: Tx -> Property roundtripLedger tx = fromLedgerTx (toLedgerTx tx) === tx -roundtripTxMetadata :: Tx -> Property -roundtripTxMetadata tx = - fromLedgerTx (toLedgerTx tx & bodyTxL . auxDataHashTxBodyL .~ SNothing) === tx - roundtripCBOR :: (Eq a, Show a, ToCBOR a, FromCBOR a) => a -> Property roundtripCBOR a = let encoded = serialize' a