From f8024e87e497887eb250c9ece82cc665d477f319 Mon Sep 17 00:00:00 2001 From: John Ky Date: Fri, 22 Sep 2023 23:52:20 +1000 Subject: [PATCH] Replace TxMetadataSupportedInEra --- cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs | 11 +- cardano-api/internal/Cardano/Api/TxBody.hs | 120 +++++------------- cardano-api/src/Cardano/Api.hs | 2 - 3 files changed, 41 insertions(+), 92 deletions(-) diff --git a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs index fd631451f6..3aa375091d 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs @@ -562,14 +562,15 @@ genTxValidityRange era = <*> genTxValidityUpperBound era genTxMetadataInEra :: CardanoEra era -> Gen (TxMetadataInEra era) -genTxMetadataInEra era = - case txMetadataSupportedInEra era of - Nothing -> pure TxMetadataNone - Just supported -> +genTxMetadataInEra = + inEonForEra + (pure TxMetadataNone) + (\w -> Gen.choice [ pure TxMetadataNone - , TxMetadataInEra supported <$> genTxMetadata + , TxMetadataInEra w <$> genTxMetadata ] + ) genTxAuxScripts :: CardanoEra era -> Gen (TxAuxScripts era) genTxAuxScripts era = diff --git a/cardano-api/internal/Cardano/Api/TxBody.hs b/cardano-api/internal/Cardano/Api/TxBody.hs index 4af91ad5ca..04a0c6ce9d 100644 --- a/cardano-api/internal/Cardano/Api/TxBody.hs +++ b/cardano-api/internal/Cardano/Api/TxBody.hs @@ -120,7 +120,6 @@ module Cardano.Api.TxBody ( ValidityUpperBoundSupportedInEra(..), ValidityNoUpperBoundSupportedInEra(..), ValidityLowerBoundSupportedInEra(..), - TxMetadataSupportedInEra(..), AuxScriptsSupportedInEra(..), TxExtraKeyWitnessesSupportedInEra(..), ScriptDataSupportedInEra(..), @@ -135,7 +134,6 @@ module Cardano.Api.TxBody ( validityUpperBoundSupportedInEra, validityNoUpperBoundSupportedInEra, validityLowerBoundSupportedInEra, - txMetadataSupportedInEra, auxScriptsSupportedInEra, extraKeyWitnessesSupportedInEra, scriptDataSupportedInEra, @@ -1121,32 +1119,6 @@ validityLowerBoundSupportedInEra AlonzoEra = Just ValidityLowerBoundInAlonzoEra validityLowerBoundSupportedInEra BabbageEra = Just ValidityLowerBoundInBabbageEra validityLowerBoundSupportedInEra ConwayEra = Just ValidityLowerBoundInConwayEra --- | A representation of whether the era supports transaction metadata. --- --- Transaction metadata is supported from the Shelley era onwards. --- -data TxMetadataSupportedInEra era where - - TxMetadataInShelleyEra :: TxMetadataSupportedInEra ShelleyEra - TxMetadataInAllegraEra :: TxMetadataSupportedInEra AllegraEra - TxMetadataInMaryEra :: TxMetadataSupportedInEra MaryEra - TxMetadataInAlonzoEra :: TxMetadataSupportedInEra AlonzoEra - TxMetadataInBabbageEra :: TxMetadataSupportedInEra BabbageEra - TxMetadataInConwayEra :: TxMetadataSupportedInEra ConwayEra - -deriving instance Eq (TxMetadataSupportedInEra era) -deriving instance Show (TxMetadataSupportedInEra era) - -txMetadataSupportedInEra :: CardanoEra era - -> Maybe (TxMetadataSupportedInEra era) -txMetadataSupportedInEra ByronEra = Nothing -txMetadataSupportedInEra ShelleyEra = Just TxMetadataInShelleyEra -txMetadataSupportedInEra AllegraEra = Just TxMetadataInAllegraEra -txMetadataSupportedInEra MaryEra = Just TxMetadataInMaryEra -txMetadataSupportedInEra AlonzoEra = Just TxMetadataInAlonzoEra -txMetadataSupportedInEra BabbageEra = Just TxMetadataInBabbageEra -txMetadataSupportedInEra ConwayEra = Just TxMetadataInConwayEra - -- | A representation of whether the era supports auxiliary scripts in -- transactions. @@ -1626,11 +1598,13 @@ deriving instance Show (TxValidityLowerBound era) data TxMetadataInEra era where - TxMetadataNone :: TxMetadataInEra era + TxMetadataNone + :: TxMetadataInEra era - TxMetadataInEra :: TxMetadataSupportedInEra era - -> TxMetadata - -> TxMetadataInEra era + TxMetadataInEra + :: ShelleyBasedEra era + -> TxMetadata + -> TxMetadataInEra era deriving instance Eq (TxMetadataInEra era) deriving instance Show (TxMetadataInEra era) @@ -3065,60 +3039,36 @@ fromLedgerTxAuxiliaryData -> (TxMetadataInEra era, TxAuxScripts era) fromLedgerTxAuxiliaryData _ Nothing = (TxMetadataNone, TxAuxScriptsNone) fromLedgerTxAuxiliaryData sbe (Just auxData) = - case sbe of - ShelleyBasedEraShelley -> - ( if null ms then - TxMetadataNone - else - TxMetadataInEra TxMetadataInShelleyEra $ TxMetadata ms - , TxAuxScriptsNone - ) - ShelleyBasedEraAllegra -> - ( if null ms then - TxMetadataNone - else - TxMetadataInEra TxMetadataInAllegraEra $ TxMetadata ms - , case ss of - [] -> TxAuxScriptsNone - _ -> TxAuxScripts AuxScriptsInAllegraEra ss - ) - ShelleyBasedEraMary -> - ( if null ms then - TxMetadataNone - else - TxMetadataInEra TxMetadataInMaryEra $ TxMetadata ms - , case ss of - [] -> TxAuxScriptsNone - _ -> TxAuxScripts AuxScriptsInMaryEra ss - ) - ShelleyBasedEraAlonzo -> - ( if null ms then - TxMetadataNone - else - TxMetadataInEra TxMetadataInAlonzoEra $ TxMetadata ms - , case ss of - [] -> TxAuxScriptsNone - _ -> TxAuxScripts AuxScriptsInAlonzoEra ss - ) - ShelleyBasedEraBabbage -> - ( if null ms then - TxMetadataNone - else - TxMetadataInEra TxMetadataInBabbageEra $ TxMetadata ms - , case ss of - [] -> TxAuxScriptsNone - _ -> TxAuxScripts AuxScriptsInBabbageEra ss - ) - ShelleyBasedEraConway -> - ( if null ms then - TxMetadataNone - else - TxMetadataInEra TxMetadataInConwayEra $ TxMetadata ms - , case ss of - [] -> TxAuxScriptsNone - _ -> TxAuxScripts AuxScriptsInConwayEra ss - ) + (metadata, auxdata) + where + metadata = if null ms then TxMetadataNone else TxMetadataInEra sbe $ TxMetadata ms + + auxdata = + case sbe of + ShelleyBasedEraShelley -> + TxAuxScriptsNone + ShelleyBasedEraAllegra -> + case ss of + [] -> TxAuxScriptsNone + _ -> TxAuxScripts AuxScriptsInAllegraEra ss + ShelleyBasedEraMary -> + case ss of + [] -> TxAuxScriptsNone + _ -> TxAuxScripts AuxScriptsInMaryEra ss + ShelleyBasedEraAlonzo -> + case ss of + [] -> TxAuxScriptsNone + _ -> TxAuxScripts AuxScriptsInAlonzoEra ss + ShelleyBasedEraBabbage -> + case ss of + [] -> TxAuxScriptsNone + _ -> TxAuxScripts AuxScriptsInBabbageEra ss + ShelleyBasedEraConway -> + case ss of + [] -> TxAuxScriptsNone + _ -> TxAuxScripts AuxScriptsInConwayEra ss + (ms, ss) = fromLedgerAuxiliaryData sbe auxData diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index 8e9bf7f3f9..0a94e1e25d 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -347,7 +347,6 @@ module Cardano.Api ( ValidityUpperBoundSupportedInEra(..), ValidityNoUpperBoundSupportedInEra(..), ValidityLowerBoundSupportedInEra(..), - TxMetadataSupportedInEra(..), AuxScriptsSupportedInEra(..), TxExtraKeyWitnessesSupportedInEra(..), ScriptDataSupportedInEra(..), @@ -362,7 +361,6 @@ module Cardano.Api ( validityUpperBoundSupportedInEra, validityNoUpperBoundSupportedInEra, validityLowerBoundSupportedInEra, - txMetadataSupportedInEra, auxScriptsSupportedInEra, extraKeyWitnessesSupportedInEra, withdrawalsSupportedInEra,