Skip to content

Commit 2074ee5

Browse files
Merge pull request #1232 from input-output-hk/lc/cardano-api-8.37
cardano-api: 8.29.1.0 -> 8.37.0.0
2 parents 9bff167 + eb3dd66 commit 2074ee5

File tree

25 files changed

+168
-163
lines changed

25 files changed

+168
-163
lines changed

cabal.project

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ repository cardano-haskell-packages
1212

1313
-- See CONTRIBUTING.md for information about when and how to update these.
1414
index-state:
15-
, hackage.haskell.org 2023-12-06T15:07:04Z
16-
, cardano-haskell-packages 2023-12-04T19:04:02Z
15+
, hackage.haskell.org 2024-01-29T15:07:04Z
16+
, cardano-haskell-packages 2024-01-29T19:04:02Z
1717

1818
packages:
1919
hydra-prelude

flake.lock

+30-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hydra-cardano-api/hydra-cardano-api.cabal

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ library
8787
, base >=4.16
8888
, base16-bytestring
8989
, bytestring
90-
, cardano-api >=8.29.1 && <8.30
90+
, cardano-api >=8.37.0 && <8.38
9191
, cardano-binary >=1.7.0 && <1.8
9292
, cardano-crypto-class >=2.1.1 && <2.2
9393
, cardano-ledger-allegra >=1.2.1 && <1.3
@@ -96,9 +96,9 @@ library
9696
, cardano-ledger-babbage >=1.5 && <1.6
9797
, cardano-ledger-binary >=1.2 && <1.3
9898
, cardano-ledger-byron >=1.0.0 && <1.1
99-
, cardano-ledger-core >=1.8 && <1.9
100-
, cardano-ledger-mary >=1.3.1 && <1.4
101-
, cardano-ledger-shelley >=1.7 && <1.8
99+
, cardano-ledger-core >=1.9 && <1.10
100+
, cardano-ledger-mary >=1.4 && <1.5
101+
, cardano-ledger-shelley >=1.8 && <1.9
102102
, containers
103103
, lens
104104
, plutus-ledger-api >=1.15.0.1 && <1.16

hydra-cardano-api/src/Cardano/Api/UTxO.hs

+29-25
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Cardano.Api.UTxO where
1111
import Cardano.Api hiding (UTxO, toLedgerUTxO)
1212
import Cardano.Api qualified
1313
import Cardano.Api.Shelley (ReferenceScript (..))
14+
import Cardano.Ledger.Babbage ()
1415
import Data.Bifunctor (second)
1516
import Data.Coerce (coerce)
1617
import Data.List qualified as List
@@ -89,33 +90,36 @@ min = UTxO . uncurry Map.singleton . Map.findMin . toMap
8990
-- | Transforms a UTxO containing tx outs from any era into Babbage era.
9091
fromApi :: Cardano.Api.UTxO era -> UTxO
9192
fromApi (Cardano.Api.UTxO eraUTxO) =
92-
let eraPairs = Map.toList eraUTxO
93-
babbagePairs = second coerceOutputToEra <$> eraPairs
94-
in fromPairs babbagePairs
93+
fromPairs $ second convertOutputToEra <$> Map.toList eraUTxO
9594
where
96-
coerceOutputToEra :: TxOut CtxUTxO era -> TxOut CtxUTxO Era
97-
coerceOutputToEra (TxOut eraAddress eraValue eraDatum eraRefScript) =
95+
-- NOTE: At latest the TxOutValue is an existential where we need to case on
96+
-- the 'sbe' witness to get constraints on the contained 'value', but the
97+
-- 'cardano-api' does that already when allowing conversion of their
98+
-- (complicated) constrained types to the cardano-ledger types - so we just
99+
-- convert forth and back.
100+
convertOutputToEra :: TxOut CtxUTxO era -> TxOut CtxUTxO Era
101+
convertOutputToEra (TxOut eraAddress eraValue eraDatum eraRefScript) =
98102
TxOut
99-
(coerceAddressToEra eraAddress)
100-
(coerceValueToEra eraValue)
101-
(coerceDatumToEra eraDatum)
102-
(coerceRefScriptToEra eraRefScript)
103-
104-
coerceAddressToEra :: AddressInEra era -> AddressInEra Era
105-
coerceAddressToEra (AddressInEra _ eraAddress) = anyAddressInShelleyBasedEra ShelleyBasedEraBabbage (toAddressAny eraAddress)
106-
107-
coerceValueToEra :: TxOutValue era -> TxOutValue Era
108-
coerceValueToEra (TxOutAdaOnly _ eraLovelace) = lovelaceToTxOutValue BabbageEra eraLovelace
109-
coerceValueToEra (TxOutValue _ value) = TxOutValue MaryEraOnwardsBabbage value
110-
111-
coerceDatumToEra :: TxOutDatum CtxUTxO era -> TxOutDatum CtxUTxO Era
112-
coerceDatumToEra TxOutDatumNone = TxOutDatumNone
113-
coerceDatumToEra (TxOutDatumHash _ hashScriptData) = TxOutDatumHash AlonzoEraOnwardsBabbage hashScriptData
114-
coerceDatumToEra (TxOutDatumInline _ hashableScriptData) = TxOutDatumInline BabbageEraOnwardsBabbage hashableScriptData
115-
116-
coerceRefScriptToEra :: ReferenceScript era -> ReferenceScript Era
117-
coerceRefScriptToEra ReferenceScriptNone = ReferenceScriptNone
118-
coerceRefScriptToEra (ReferenceScript _ scriptInAnyLang) = ReferenceScript BabbageEraOnwardsBabbage scriptInAnyLang
103+
(convertAddressToEra eraAddress)
104+
(convertValueToEra eraValue)
105+
(convertDatumToEra eraDatum)
106+
(convertRefScriptToEra eraRefScript)
107+
108+
convertAddressToEra :: AddressInEra era -> AddressInEra Era
109+
convertAddressToEra (AddressInEra _ eraAddress) = anyAddressInShelleyBasedEra ShelleyBasedEraBabbage (toAddressAny eraAddress)
110+
111+
convertValueToEra :: TxOutValue era -> TxOutValue Era
112+
convertValueToEra (TxOutValueByron lovelace) = lovelaceToTxOutValue shelleyBasedEra lovelace
113+
convertValueToEra (TxOutValueShelleyBased sbe value) = TxOutValueShelleyBased shelleyBasedEra (toLedgerValue MaryEraOnwardsBabbage $ fromLedgerValue sbe value)
114+
115+
convertDatumToEra :: TxOutDatum CtxUTxO era -> TxOutDatum CtxUTxO Era
116+
convertDatumToEra TxOutDatumNone = TxOutDatumNone
117+
convertDatumToEra (TxOutDatumHash _ hashScriptData) = TxOutDatumHash AlonzoEraOnwardsBabbage hashScriptData
118+
convertDatumToEra (TxOutDatumInline _ hashableScriptData) = TxOutDatumInline BabbageEraOnwardsBabbage hashableScriptData
119+
120+
convertRefScriptToEra :: ReferenceScript era -> ReferenceScript Era
121+
convertRefScriptToEra ReferenceScriptNone = ReferenceScriptNone
122+
convertRefScriptToEra (ReferenceScript _ scriptInAnyLang) = ReferenceScript BabbageEraOnwardsBabbage scriptInAnyLang
119123

120124
toApi :: UTxO -> Cardano.Api.UTxO Era
121125
toApi = coerce

hydra-cardano-api/src/Hydra/Cardano/Api.hs

+6-6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import Cardano.Api as X hiding (
6767
Witness (..),
6868
createAndValidateTransactionBody,
6969
defaultTxBodyContent,
70+
fromLedgerValue,
7071
makeShelleyKeyWitness,
7172
policyId,
7273
queryEraHistory,
@@ -76,6 +77,7 @@ import Cardano.Api as X hiding (
7677
scriptLanguageSupportedInEra,
7778
signShelleyTransaction,
7879
toLedgerUTxO,
80+
toLedgerValue,
7981
)
8082
import Cardano.Api.Byron as X (
8183
Address (..),
@@ -94,10 +96,8 @@ import Cardano.Api.Shelley as X (
9496
VerificationKey (..),
9597
fromAlonzoCostModels,
9698
fromAlonzoPrices,
97-
fromConsensusPointInMode,
9899
fromPlutusData,
99100
toAlonzoPrices,
100-
toConsensusPointInMode,
101101
toPlutusData,
102102
toShelleyNetwork,
103103
)
@@ -372,10 +372,10 @@ pattern TxBody{txBodyContent} <-
372372
{-# COMPLETE TxBody #-}
373373

374374
createAndValidateTransactionBody :: TxBodyContent BuildTx -> Either TxBodyError TxBody
375-
createAndValidateTransactionBody = Cardano.Api.createAndValidateTransactionBody cardanoEra
375+
createAndValidateTransactionBody = Cardano.Api.createAndValidateTransactionBody shelleyBasedEra
376376

377377
defaultTxBodyContent :: TxBodyContent BuildTx
378-
defaultTxBodyContent = Cardano.Api.defaultTxBodyContent cardanoEra
378+
defaultTxBodyContent = Cardano.Api.defaultTxBodyContent shelleyBasedEra
379379

380380
-- ** TxBodyContent
381381

@@ -595,14 +595,14 @@ pattern TxOut :: AddressInEra -> Value -> TxOutDatum ctx -> ReferenceScript -> T
595595
pattern TxOut{txOutAddress, txOutValue, txOutDatum, txOutReferenceScript} <-
596596
Cardano.Api.TxOut
597597
txOutAddress
598-
(TxOutValue MaryEraOnwardsBabbage txOutValue)
598+
(TxOutValueShelleyBased ShelleyBasedEraBabbage (Extras.fromLedgerValue -> txOutValue))
599599
txOutDatum
600600
txOutReferenceScript
601601
where
602602
TxOut addr value datum ref =
603603
Cardano.Api.TxOut
604604
addr
605-
(TxOutValue MaryEraOnwardsBabbage value)
605+
(TxOutValueShelleyBased ShelleyBasedEraBabbage (Extras.toLedgerValue value))
606606
datum
607607
ref
608608

hydra-cardano-api/src/Hydra/Cardano/Api/Hash.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Hydra.Cardano.Api.Hash where
22

33
import Hydra.Cardano.Api.Prelude
44

5-
import Cardano.Ledger.Alonzo.TxInfo qualified as Ledger
5+
import Cardano.Ledger.Alonzo.Plutus.TxInfo qualified as Ledger
66
import Cardano.Ledger.Keys qualified as Ledger
77
import Cardano.Ledger.SafeHash (unsafeMakeSafeHash)
88
import Cardano.Ledger.Shelley.Scripts qualified as Ledger

hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module Hydra.Cardano.Api.PlutusScript where
44

55
import Hydra.Cardano.Api.Prelude
66

7-
import Cardano.Ledger.Alonzo.Language qualified as Ledger
87
import Cardano.Ledger.Alonzo.Scripts qualified as Ledger
8+
import Cardano.Ledger.Plutus.Language qualified as Ledger
99
import Data.ByteString.Short qualified as SBS
1010
import PlutusLedgerApi.Common qualified as Plutus
1111
import Test.QuickCheck (listOf)

hydra-cardano-api/src/Hydra/Cardano/Api/PolicyId.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Hydra.Cardano.Api.PolicyId where
44

55
import Hydra.Cardano.Api.Prelude
66

7-
import Cardano.Ledger.Alonzo.TxInfo qualified as Ledger
7+
import Cardano.Ledger.Alonzo.Plutus.TxInfo qualified as Ledger
88
import Cardano.Ledger.Hashes qualified as Ledger
99
import Cardano.Ledger.Mary.Value qualified as Ledger
1010
import Hydra.Cardano.Api.ScriptHash ()

hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ module Hydra.Cardano.Api.ScriptData where
44

55
import Hydra.Cardano.Api.Prelude
66

7-
import Cardano.Api.Byron (TxBody (..))
8-
import Cardano.Ledger.Alonzo.Scripts.Data qualified as Ledger
97
import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
108
import Cardano.Ledger.Era qualified as Ledger
9+
import Cardano.Ledger.Plutus.Data qualified as Ledger
1110
import Codec.Serialise (deserialiseOrFail, serialise)
1211
import Control.Arrow (left)
1312
import Data.Aeson (Value (String), withText)
@@ -55,7 +54,6 @@ lookupScriptData ::
5554
Tx era ->
5655
TxOut CtxUTxO era ->
5756
Maybe HashableScriptData
58-
lookupScriptData (Tx ByronTxBody{} _) _ = Nothing
5957
lookupScriptData (Tx (ShelleyTxBody _ _ _ scriptsData _ _) _) (TxOut _ _ datum _) =
6058
case datum of
6159
TxOutDatumNone ->

hydra-cardano-api/src/Hydra/Cardano/Api/Tx.hs

+1-5
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ utxoProducedByTx tx =
4545
TxBody body = getTxBody tx
4646

4747
-- | Get explicit fees allocated to a transaction.
48-
--
49-
-- NOTE: this function is partial and throws if given a Byron transaction for
50-
-- which fees are necessarily implicit.
51-
txFee' :: HasCallStack => Tx era -> Lovelace
48+
txFee' :: Tx era -> Lovelace
5249
txFee' (getTxBody -> TxBody body) =
5350
case txFee body of
5451
TxFeeExplicit _ y -> y
55-
TxFeeImplicit _ -> error "impossible: TxFeeImplicit on non-Byron transaction."
5652

5753
-- * Type Conversions
5854

hydra-cardano-api/src/Hydra/Cardano/Api/TxBody.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ module Hydra.Cardano.Api.TxBody where
22

33
import Hydra.Cardano.Api.Prelude
44

5-
import Cardano.Ledger.Alonzo.Scripts.Data qualified as Ledger
65
import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
76
import Cardano.Ledger.Babbage.Tx qualified as Ledger
87
import Cardano.Ledger.BaseTypes (strictMaybeToMaybe)
98
import Cardano.Ledger.Core qualified as Ledger
9+
import Cardano.Ledger.Plutus.Data qualified as Ledger
1010
import Data.List (find)
1111
import Data.Map qualified as Map
1212
import Hydra.Cardano.Api.PlutusScript (fromLedgerScript)

hydra-cardano-api/src/Hydra/Cardano/Api/TxIn.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ module Hydra.Cardano.Api.TxIn where
44

55
import Hydra.Cardano.Api.Prelude
66

7-
import Cardano.Ledger.Alonzo.TxInfo qualified as Ledger
87
import Cardano.Ledger.BaseTypes qualified as Ledger
98
import Cardano.Ledger.Binary qualified as Ledger
9+
import Cardano.Ledger.Plutus.TxInfo qualified as Ledger
1010
import Cardano.Ledger.TxIn qualified as Ledger
1111
import Data.ByteString qualified as BS
1212
import Data.Set qualified as Set

hydra-cardano-api/src/Hydra/Cardano/Api/TxOut.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ mkTxOutAutoBalance ::
4646
ReferenceScript Era ->
4747
TxOut CtxTx Era
4848
mkTxOutAutoBalance pparams addr val dat ref =
49-
let out = TxOut addr (TxOutValue maryEraOnwards val) dat ref
49+
let out = TxOut addr (TxOutValueShelleyBased (shelleyBasedEra @Era) (toLedgerValue (maryEraOnwards @Era) val)) dat ref
5050
minValue = minUTxOValue pparams out
5151
in modifyTxOutValue (const minValue) out
5252

@@ -61,6 +61,7 @@ modifyTxOutAddress fn (TxOut addr value dat ref) =
6161
-- | Alter the value of a 'TxOut' with the given transformation.
6262
modifyTxOutValue ::
6363
IsMaryEraOnwards era =>
64+
IsShelleyBasedEra era =>
6465
(Value -> Value) ->
6566
TxOut ctx era ->
6667
TxOut ctx era
@@ -160,12 +161,13 @@ toLedgerTxOut =
160161
-- NOTE: Requires the 'Network' discriminator (Testnet or Mainnet) because
161162
-- Plutus addresses are stripped off it.
162163
fromPlutusTxOut ::
164+
forall era.
163165
(IsMaryEraOnwards era, IsAlonzoEraOnwards era, IsBabbageEraOnwards era, IsShelleyBasedEra era) =>
164166
Network ->
165167
Plutus.TxOut ->
166168
Maybe (TxOut CtxUTxO era)
167169
fromPlutusTxOut network out = do
168-
value <- TxOutValue maryEraOnwards <$> fromPlutusValue plutusValue
170+
value <- shelleyBasedEraConstraints (shelleyBasedEra @era) $ TxOutValueShelleyBased (shelleyBasedEra @era) <$> (toLedgerValue (maryEraOnwards @era) <$> fromPlutusValue plutusValue)
169171
pure $ TxOut addressInEra value datum ReferenceScriptNone
170172
where
171173
addressInEra = fromPlutusAddress network plutusAddress

hydra-cardano-api/src/Hydra/Cardano/Api/TxOutValue.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import Hydra.Cardano.Api.MaryEraOnwards (IsMaryEraOnwards (..))
77
-- | Inject some 'Value' into a 'TxOutValue'
88
mkTxOutValue ::
99
forall era.
10+
IsShelleyBasedEra era =>
1011
IsMaryEraOnwards era =>
1112
Value ->
1213
TxOutValue era
13-
mkTxOutValue =
14-
TxOutValue (maryEraOnwards @era)
14+
mkTxOutValue v =
15+
shelleyBasedEraConstraints (shelleyBasedEra @era) $ TxOutValueShelleyBased (shelleyBasedEra @era) (toLedgerValue (maryEraOnwards @era) v)

hydra-cardano-api/src/Hydra/Cardano/Api/ValidityInterval.hs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ toLedgerValidityInterval (lowerBound, upperBound) =
1919
TxValidityLowerBound _ s -> SJust s
2020
, Ledger.invalidHereafter =
2121
case upperBound of
22-
TxValidityNoUpperBound _ -> SNothing
2322
TxValidityUpperBound _ s -> maybeToStrictMaybe s
2423
}
2524
fromLedgerValidityInterval ::

0 commit comments

Comments
 (0)