15
15
{-# LANGUAGE TypeFamilies #-}
16
16
{-# LANGUAGE ViewPatterns #-}
17
17
18
+ {- HLINT ignore "Avoid lambda using `infix`" -}
19
+ {- HLINT ignore "Redundant flip" -}
20
+ {- HLINT ignore "Use section" -}
18
21
19
22
-- | Transaction bodies
20
23
--
@@ -181,8 +184,8 @@ import Data.Type.Equality (TestEquality (..), (:~:) (Refl))
181
184
import Data.Word (Word16 , Word32 , Word64 )
182
185
import GHC.Generics
183
186
import GHC.Records (HasField (.. ))
184
- import Text.Parsec ((<?>) )
185
187
import qualified Text.Parsec as Parsec
188
+ import Text.Parsec ((<?>) )
186
189
import qualified Text.Parsec.String as Parsec
187
190
188
191
import Cardano.Binary (Annotated (.. ), reAnnotate , recoverBytes )
@@ -239,10 +242,11 @@ import Ouroboros.Consensus.Shelley.Eras (StandardAllegra, StandardAlon
239
242
240
243
import Cardano.Api.Address
241
244
import Cardano.Api.Certificate
245
+ import Cardano.Api.EraCast
242
246
import Cardano.Api.Eras
243
247
import Cardano.Api.Error
244
- import Cardano.Api.HasTypeProxy
245
248
import Cardano.Api.Hash
249
+ import Cardano.Api.HasTypeProxy
246
250
import Cardano.Api.KeysByron
247
251
import Cardano.Api.KeysShelley
248
252
import Cardano.Api.NetworkId
@@ -259,10 +263,6 @@ import Cardano.Api.Utils
259
263
import Cardano.Api.Value
260
264
import Cardano.Api.ValueParser
261
265
262
-
263
- {- HLINT ignore "Redundant flip" -}
264
- {- HLINT ignore "Use section" -}
265
-
266
266
-- | Indicates whether a script is expected to fail or pass validation.
267
267
data ScriptValidity
268
268
= ScriptInvalid -- ^ Script is expected to fail validation.
@@ -356,6 +356,14 @@ data TxOut ctx era = TxOut (AddressInEra era)
356
356
deriving instance Eq (TxOut ctx era )
357
357
deriving instance Show (TxOut ctx era )
358
358
359
+ instance EraCast (TxOut ctx ) where
360
+ eraCast toEra (TxOut addressInEra txOutValue txOutDatum referenceScript) =
361
+ TxOut
362
+ <$> eraCast toEra addressInEra
363
+ <*> eraCast toEra txOutValue
364
+ <*> eraCast toEra txOutDatum
365
+ <*> eraCast toEra referenceScript
366
+
359
367
data TxOutInAnyEra where
360
368
TxOutInAnyEra :: CardanoEra era
361
369
-> TxOut CtxTx era
@@ -1188,6 +1196,18 @@ data TxOutValue era where
1188
1196
1189
1197
TxOutValue :: MultiAssetSupportedInEra era -> Value -> TxOutValue era
1190
1198
1199
+ instance EraCast TxOutValue where
1200
+ eraCast toEra v = case v of
1201
+ TxOutAdaOnly _previousEra lovelace ->
1202
+ case multiAssetSupportedInEra toEra of
1203
+ Left adaOnly -> Right $ TxOutAdaOnly adaOnly lovelace
1204
+ Right multiAssetSupp -> Right $ TxOutValue multiAssetSupp $ lovelaceToValue lovelace
1205
+ TxOutValue (_ :: MultiAssetSupportedInEra fromEra ) value ->
1206
+ case multiAssetSupportedInEra toEra of
1207
+ Left _adaOnly -> Left $ EraCastError v (cardanoEra @ fromEra ) toEra
1208
+ Right multiAssetSupp -> Right $ TxOutValue multiAssetSupp value
1209
+
1210
+
1191
1211
deriving instance Eq (TxOutValue era )
1192
1212
deriving instance Show (TxOutValue era )
1193
1213
deriving instance Generic (TxOutValue era )
@@ -1333,6 +1353,24 @@ data TxOutDatum ctx era where
1333
1353
deriving instance Eq (TxOutDatum ctx era )
1334
1354
deriving instance Show (TxOutDatum ctx era )
1335
1355
1356
+ instance EraCast (TxOutDatum ctx ) where
1357
+ eraCast toEra v = case v of
1358
+ TxOutDatumNone -> pure TxOutDatumNone
1359
+ TxOutDatumHash (_ :: ScriptDataSupportedInEra fromEra ) hash ->
1360
+ case scriptDataSupportedInEra toEra of
1361
+ Nothing -> Left $ EraCastError v (cardanoEra @ fromEra ) toEra
1362
+ Just sDatumsSupported ->
1363
+ Right $ TxOutDatumHash sDatumsSupported hash
1364
+ TxOutDatumInTx' (_ :: ScriptDataSupportedInEra fromEra ) scriptData hash ->
1365
+ case scriptDataSupportedInEra toEra of
1366
+ Nothing -> Left $ EraCastError v (cardanoEra @ fromEra ) toEra
1367
+ Just sDatumsSupported ->
1368
+ Right $ TxOutDatumInTx' sDatumsSupported scriptData hash
1369
+ TxOutDatumInline (_ :: ReferenceTxInsScriptsInlineDatumsSupportedInEra fromEra ) scriptData ->
1370
+ case refInsScriptsAndInlineDatsSupportedInEra toEra of
1371
+ Nothing -> Left $ EraCastError v (cardanoEra @ fromEra ) toEra
1372
+ Just refInsAndInlineSupported ->
1373
+ Right $ TxOutDatumInline refInsAndInlineSupported scriptData
1336
1374
1337
1375
pattern TxOutDatumInTx
1338
1376
:: ScriptDataSupportedInEra era
0 commit comments