From e82d95f26226a1f33e28b27ea05065bcb6301c5d Mon Sep 17 00:00:00 2001 From: John Ky Date: Wed, 27 Sep 2023 00:10:20 +1000 Subject: [PATCH 1/3] Delete AuxScriptsSupportedInEra --- cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs | 9 +-- cardano-api/internal/Cardano/Api/TxBody.hs | 55 ++++--------------- cardano-api/src/Cardano/Api.hs | 3 - 3 files changed, 14 insertions(+), 53 deletions(-) diff --git a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs index 6bcf9d154a..748028f905 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs @@ -571,12 +571,9 @@ genTxMetadataInEra = genTxAuxScripts :: CardanoEra era -> Gen (TxAuxScripts era) genTxAuxScripts era = - case auxScriptsSupportedInEra era of - Nothing -> pure TxAuxScriptsNone - Just supported -> - TxAuxScripts supported <$> - Gen.list (Range.linear 0 3) - (genScriptInEra era) + forEraInEon era + (pure TxAuxScriptsNone) + (\w -> TxAuxScripts w <$> Gen.list (Range.linear 0 3) (genScriptInEra era)) genTxWithdrawals :: CardanoEra era -> Gen (TxWithdrawals BuildTx era) genTxWithdrawals = diff --git a/cardano-api/internal/Cardano/Api/TxBody.hs b/cardano-api/internal/Cardano/Api/TxBody.hs index e19eff759f..413d99836f 100644 --- a/cardano-api/internal/Cardano/Api/TxBody.hs +++ b/cardano-api/internal/Cardano/Api/TxBody.hs @@ -112,9 +112,6 @@ module Cardano.Api.TxBody ( BuildTx, ViewTx, - -- * Era-dependent transaction body features - auxScriptsSupportedInEra, - -- * Inspecting 'ScriptWitness'es AnyScriptWitness(..), ScriptWitnessIndex(..), @@ -840,38 +837,6 @@ fromBabbageTxOutDatum _ w (Babbage.Datum binData) = TxOutDatumInline w $ binaryDataToScriptData w binData - --- ---------------------------------------------------------------------------- --- Era-dependent transaction body features --- - --- | A representation of whether the era supports auxiliary scripts in --- transactions. --- --- Auxiliary scripts are supported from the Allegra era onwards. --- -data AuxScriptsSupportedInEra era where - - AuxScriptsInAllegraEra :: AuxScriptsSupportedInEra AllegraEra - AuxScriptsInMaryEra :: AuxScriptsSupportedInEra MaryEra - AuxScriptsInAlonzoEra :: AuxScriptsSupportedInEra AlonzoEra - AuxScriptsInBabbageEra :: AuxScriptsSupportedInEra BabbageEra - AuxScriptsInConwayEra :: AuxScriptsSupportedInEra ConwayEra - -deriving instance Eq (AuxScriptsSupportedInEra era) -deriving instance Show (AuxScriptsSupportedInEra era) - -auxScriptsSupportedInEra :: CardanoEra era - -> Maybe (AuxScriptsSupportedInEra era) -auxScriptsSupportedInEra ByronEra = Nothing -auxScriptsSupportedInEra ShelleyEra = Nothing -auxScriptsSupportedInEra AllegraEra = Just AuxScriptsInAllegraEra -auxScriptsSupportedInEra MaryEra = Just AuxScriptsInMaryEra -auxScriptsSupportedInEra AlonzoEra = Just AuxScriptsInAlonzoEra -auxScriptsSupportedInEra BabbageEra = Just AuxScriptsInBabbageEra -auxScriptsSupportedInEra ConwayEra = Just AuxScriptsInConwayEra - - -- ---------------------------------------------------------------------------- -- Building vs viewing transactions -- @@ -1197,11 +1162,13 @@ deriving instance Show (TxMetadataInEra era) data TxAuxScripts era where - TxAuxScriptsNone :: TxAuxScripts era + TxAuxScriptsNone + :: TxAuxScripts era - TxAuxScripts :: AuxScriptsSupportedInEra era - -> [ScriptInEra era] - -> TxAuxScripts era + TxAuxScripts + :: AllegraEraOnwards era + -> [ScriptInEra era] + -> TxAuxScripts era deriving instance Eq (TxAuxScripts era) deriving instance Show (TxAuxScripts era) @@ -2602,23 +2569,23 @@ fromLedgerTxAuxiliaryData sbe (Just auxData) = ShelleyBasedEraAllegra -> case ss of [] -> TxAuxScriptsNone - _ -> TxAuxScripts AuxScriptsInAllegraEra ss + _ -> TxAuxScripts AllegraEraOnwardsAllegra ss ShelleyBasedEraMary -> case ss of [] -> TxAuxScriptsNone - _ -> TxAuxScripts AuxScriptsInMaryEra ss + _ -> TxAuxScripts AllegraEraOnwardsMary ss ShelleyBasedEraAlonzo -> case ss of [] -> TxAuxScriptsNone - _ -> TxAuxScripts AuxScriptsInAlonzoEra ss + _ -> TxAuxScripts AllegraEraOnwardsAlonzo ss ShelleyBasedEraBabbage -> case ss of [] -> TxAuxScriptsNone - _ -> TxAuxScripts AuxScriptsInBabbageEra ss + _ -> TxAuxScripts AllegraEraOnwardsBabbage ss ShelleyBasedEraConway -> case ss of [] -> TxAuxScriptsNone - _ -> TxAuxScripts AuxScriptsInConwayEra ss + _ -> TxAuxScripts AllegraEraOnwardsConway ss (ms, ss) = fromLedgerAuxiliaryData sbe auxData diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index fb67112025..54df35d8a1 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -380,9 +380,6 @@ module Cardano.Api ( BuildTx, ViewTx, - -- ** Era-dependent transaction body features - auxScriptsSupportedInEra, - -- ** Era-dependent protocol features ProtocolUTxOCostPerByteFeature(..), ProtocolUTxOCostPerWordFeature(..), From 936e73782b2f8e1e63466c87abff866bf606a998 Mon Sep 17 00:00:00 2001 From: John Ky Date: Wed, 27 Sep 2023 00:25:39 +1000 Subject: [PATCH 2/3] New caseShelleyEraOnlyOrAllegraEraOnwards function --- cardano-api/internal/Cardano/Api/Eras/Case.hs | 14 ++++++++++++++ cardano-api/src/Cardano/Api.hs | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/Eras/Case.hs b/cardano-api/internal/Cardano/Api/Eras/Case.hs index 4e07229754..31fe6eb19e 100644 --- a/cardano-api/internal/Cardano/Api/Eras/Case.hs +++ b/cardano-api/internal/Cardano/Api/Eras/Case.hs @@ -13,6 +13,7 @@ module Cardano.Api.Eras.Case , caseByronAndAllegraEraOnwardsOrShelleyEraOnly -- Case on ShelleyBasedEra + , caseShelleyEraOnlyOrAllegraEraOnwards , caseShelleyToAllegraOrMaryEraOnwards , caseShelleyToMaryOrAlonzoEraOnwards , caseShelleyToAlonzoOrBabbageEraOnwards @@ -25,6 +26,7 @@ module Cardano.Api.Eras.Case , alonzoEraOnwardsToMaryEraOnwards ) where +import Cardano.Api.Eon.AllegraEraOnwards import Cardano.Api.Eon.AlonzoEraOnwards import Cardano.Api.Eon.BabbageEraOnwards import Cardano.Api.Eon.ByronAndAllegraEraOnwards @@ -113,6 +115,18 @@ caseByronAndAllegraEraOnwardsOrShelleyEraOnly l r = \case BabbageEra -> l ByronAndAllegraEraOnwardsBabbage ConwayEra -> l ByronAndAllegraEraOnwardsConway +caseShelleyEraOnlyOrAllegraEraOnwards :: () + => (ShelleyEraOnlyConstraints era => ShelleyEraOnly era -> a) + -> (AllegraEraOnwardsConstraints era => AllegraEraOnwards era -> a) + -> ShelleyBasedEra era + -> a +caseShelleyEraOnlyOrAllegraEraOnwards l r = \case + ShelleyBasedEraShelley -> l ShelleyEraOnlyShelley + ShelleyBasedEraAllegra -> r AllegraEraOnwardsAllegra + ShelleyBasedEraMary -> r AllegraEraOnwardsMary + ShelleyBasedEraAlonzo -> r AllegraEraOnwardsAlonzo + ShelleyBasedEraBabbage -> r AllegraEraOnwardsBabbage + ShelleyBasedEraConway -> r AllegraEraOnwardsConway caseShelleyToAllegraOrMaryEraOnwards :: () => (ShelleyToAllegraEraConstraints era => ShelleyToAllegraEra era -> a) diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index 54df35d8a1..965523fad1 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -142,11 +142,12 @@ module Cardano.Api ( -- ** Case on CardanoEra caseByronOrShelleyBasedEra, - - -- ** Case on ShelleyBasedEra caseByronToAllegraOrMaryEraOnwards, caseByronToMaryOrAlonzoEraOnwards, caseByronToAlonzoOrBabbageEraOnwards, + + -- ** Case on ShelleyBasedEra + caseShelleyEraOnlyOrAllegraEraOnwards, caseShelleyToAllegraOrMaryEraOnwards, caseShelleyToMaryOrAlonzoEraOnwards, caseShelleyToAlonzoOrBabbageEraOnwards, From d54ebe4870f759df57a50ec3109457e83c4b2c51 Mon Sep 17 00:00:00 2001 From: John Ky Date: Wed, 27 Sep 2023 00:28:22 +1000 Subject: [PATCH 3/3] Simplify definition of auxData --- cardano-api/internal/Cardano/Api/TxBody.hs | 27 +++++----------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/TxBody.hs b/cardano-api/internal/Cardano/Api/TxBody.hs index 413d99836f..7f6ca32456 100644 --- a/cardano-api/internal/Cardano/Api/TxBody.hs +++ b/cardano-api/internal/Cardano/Api/TxBody.hs @@ -2563,29 +2563,14 @@ fromLedgerTxAuxiliaryData sbe (Just auxData) = metadata = if null ms then TxMetadataNone else TxMetadataInEra sbe $ TxMetadata ms auxdata = - case sbe of - ShelleyBasedEraShelley -> - TxAuxScriptsNone - ShelleyBasedEraAllegra -> + caseShelleyEraOnlyOrAllegraEraOnwards + (const TxAuxScriptsNone) + (\w -> case ss of [] -> TxAuxScriptsNone - _ -> TxAuxScripts AllegraEraOnwardsAllegra ss - ShelleyBasedEraMary -> - case ss of - [] -> TxAuxScriptsNone - _ -> TxAuxScripts AllegraEraOnwardsMary ss - ShelleyBasedEraAlonzo -> - case ss of - [] -> TxAuxScriptsNone - _ -> TxAuxScripts AllegraEraOnwardsAlonzo ss - ShelleyBasedEraBabbage -> - case ss of - [] -> TxAuxScriptsNone - _ -> TxAuxScripts AllegraEraOnwardsBabbage ss - ShelleyBasedEraConway -> - case ss of - [] -> TxAuxScriptsNone - _ -> TxAuxScripts AllegraEraOnwardsConway ss + _ -> TxAuxScripts w ss + ) + sbe (ms, ss) = fromLedgerAuxiliaryData sbe auxData