Skip to content

Commit

Permalink
Delete ValidityUpperBoundSupportedInEra and ValidityNoUpperBoundSuppo…
Browse files Browse the repository at this point in the history
…rtedInEra
  • Loading branch information
newhoggy committed Sep 26, 2023
1 parent fbe122d commit 08ba0fe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 108 deletions.
16 changes: 6 additions & 10 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -543,16 +543,12 @@ genTxValidityLowerBound era =
-- TODO: Accept a range for generating ttl.
genTxValidityUpperBound :: CardanoEra era -> Gen (TxValidityUpperBound era)
genTxValidityUpperBound era =
case (validityUpperBoundSupportedInEra era,
validityNoUpperBoundSupportedInEra era) of
(Just supported, _) ->
TxValidityUpperBound supported <$> genTtl

(Nothing, Just supported) ->
pure (TxValidityNoUpperBound supported)

(Nothing, Nothing) ->
error "genTxValidityUpperBound: unexpected era support combination"
forEraInEon era
( forEraInEon era
(error "genTxValidityUpperBound: unexpected era support combination")
(pure . TxValidityNoUpperBound)
)
(\w -> TxValidityUpperBound w <$> genTtl)

genTxValidityRange
:: CardanoEra era
Expand Down
121 changes: 27 additions & 94 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,13 @@ module Cardano.Api.TxBody (

-- * Era-dependent transaction body features
CollateralSupportedInEra(..),
ValidityUpperBoundSupportedInEra(..),
ValidityNoUpperBoundSupportedInEra(..),
ValidityLowerBoundSupportedInEra(..),
AuxScriptsSupportedInEra(..),
TxExtraKeyWitnessesSupportedInEra(..),
TxTotalAndReturnCollateralSupportedInEra(..),

-- ** Feature availability functions
collateralSupportedInEra,
validityUpperBoundSupportedInEra,
validityNoUpperBoundSupportedInEra,
validityLowerBoundSupportedInEra,
auxScriptsSupportedInEra,
extraKeyWitnessesSupportedInEra,
Expand Down Expand Up @@ -173,11 +169,13 @@ import Cardano.Api.Certificate
import Cardano.Api.Convenience.Constraints
import Cardano.Api.Eon.AlonzoEraOnwards
import Cardano.Api.Eon.BabbageEraOnwards
import Cardano.Api.Eon.ByronAndAllegraEraOnwards
import Cardano.Api.Eon.ByronEraOnly
import Cardano.Api.Eon.ByronToAllegraEra
import Cardano.Api.Eon.ConwayEraOnwards
import Cardano.Api.Eon.MaryEraOnwards
import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.Eon.ShelleyEraOnly
import Cardano.Api.Eon.ShelleyToBabbageEra
import Cardano.Api.EraCast
import Cardano.Api.Eras.Case
Expand Down Expand Up @@ -909,75 +907,12 @@ collateralSupportedInEra AlonzoEra = Just CollateralInAlonzoEra
collateralSupportedInEra BabbageEra = Just CollateralInBabbageEra
collateralSupportedInEra ConwayEra = Just CollateralInConwayEra

-- | A representation of whether the era supports transactions with an upper
-- bound on the range of slots in which they are valid.
--
-- The Shelley and subsequent eras support an upper bound on the validity
-- range. In the Shelley era specifically it is actually required. It is
-- optional in later eras.
--
data ValidityUpperBoundSupportedInEra era where

ValidityUpperBoundInShelleyEra :: ValidityUpperBoundSupportedInEra ShelleyEra
ValidityUpperBoundInAllegraEra :: ValidityUpperBoundSupportedInEra AllegraEra
ValidityUpperBoundInMaryEra :: ValidityUpperBoundSupportedInEra MaryEra
ValidityUpperBoundInAlonzoEra :: ValidityUpperBoundSupportedInEra AlonzoEra
ValidityUpperBoundInBabbageEra :: ValidityUpperBoundSupportedInEra BabbageEra
ValidityUpperBoundInConwayEra :: ValidityUpperBoundSupportedInEra ConwayEra

deriving instance Eq (ValidityUpperBoundSupportedInEra era)
deriving instance Show (ValidityUpperBoundSupportedInEra era)

validityUpperBoundSupportedInEra :: CardanoEra era
-> Maybe (ValidityUpperBoundSupportedInEra era)
validityUpperBoundSupportedInEra ByronEra = Nothing
validityUpperBoundSupportedInEra ShelleyEra = Just ValidityUpperBoundInShelleyEra
validityUpperBoundSupportedInEra AllegraEra = Just ValidityUpperBoundInAllegraEra
validityUpperBoundSupportedInEra MaryEra = Just ValidityUpperBoundInMaryEra
validityUpperBoundSupportedInEra AlonzoEra = Just ValidityUpperBoundInAlonzoEra
validityUpperBoundSupportedInEra BabbageEra = Just ValidityUpperBoundInBabbageEra
validityUpperBoundSupportedInEra ConwayEra = Just ValidityUpperBoundInConwayEra


-- | A representation of whether the era supports transactions having /no/
-- upper bound on the range of slots in which they are valid.
--
-- Note that the 'ShelleyEra' /does not support/ omitting a validity upper
-- bound. It was introduced as a /required/ field in Shelley and then made
-- optional in Allegra and subsequent eras.
--
-- The Byron era supports this by virtue of the fact that it does not support
-- validity ranges at all.
--
data ValidityNoUpperBoundSupportedInEra era where

ValidityNoUpperBoundInByronEra :: ValidityNoUpperBoundSupportedInEra ByronEra
ValidityNoUpperBoundInAllegraEra :: ValidityNoUpperBoundSupportedInEra AllegraEra
ValidityNoUpperBoundInMaryEra :: ValidityNoUpperBoundSupportedInEra MaryEra
ValidityNoUpperBoundInAlonzoEra :: ValidityNoUpperBoundSupportedInEra AlonzoEra
ValidityNoUpperBoundInBabbageEra :: ValidityNoUpperBoundSupportedInEra BabbageEra
ValidityNoUpperBoundInConwayEra :: ValidityNoUpperBoundSupportedInEra ConwayEra

deriving instance Eq (ValidityNoUpperBoundSupportedInEra era)
deriving instance Show (ValidityNoUpperBoundSupportedInEra era)

validityNoUpperBoundSupportedInEra :: CardanoEra era
-> Maybe (ValidityNoUpperBoundSupportedInEra era)
validityNoUpperBoundSupportedInEra ByronEra = Just ValidityNoUpperBoundInByronEra
validityNoUpperBoundSupportedInEra ShelleyEra = Nothing
validityNoUpperBoundSupportedInEra AllegraEra = Just ValidityNoUpperBoundInAllegraEra
validityNoUpperBoundSupportedInEra MaryEra = Just ValidityNoUpperBoundInMaryEra
validityNoUpperBoundSupportedInEra AlonzoEra = Just ValidityNoUpperBoundInAlonzoEra
validityNoUpperBoundSupportedInEra BabbageEra = Just ValidityNoUpperBoundInBabbageEra
validityNoUpperBoundSupportedInEra ConwayEra = Just ValidityNoUpperBoundInConwayEra


-- | A representation of whether the era supports transactions with a lower
-- bound on the range of slots in which they are valid.
--
-- The Allegra and subsequent eras support an optional lower bound on the
-- validity range. No equivalent of 'ValidityNoUpperBoundSupportedInEra' is
-- needed since all eras support having no lower bound.
-- validity range.
--
data ValidityLowerBoundSupportedInEra era where

Expand Down Expand Up @@ -1338,26 +1273,24 @@ defaultTxFee =
-- | This was formerly known as the TTL.
--
data TxValidityUpperBound era where
TxValidityNoUpperBound
:: ByronAndAllegraEraOnwards era
-> TxValidityUpperBound era

TxValidityNoUpperBound :: ValidityNoUpperBoundSupportedInEra era
-> TxValidityUpperBound era

TxValidityUpperBound :: ValidityUpperBoundSupportedInEra era
-> SlotNo
-> TxValidityUpperBound era
TxValidityUpperBound
:: ShelleyBasedEra era
-> SlotNo
-> TxValidityUpperBound era

deriving instance Eq (TxValidityUpperBound era)
deriving instance Show (TxValidityUpperBound era)

defaultTxValidityUpperBound :: forall era. IsCardanoEra era => TxValidityUpperBound era
defaultTxValidityUpperBound = case cardanoEra @era of
ByronEra -> TxValidityNoUpperBound ValidityNoUpperBoundInByronEra
ShelleyEra -> TxValidityUpperBound ValidityUpperBoundInShelleyEra maxBound
AllegraEra -> TxValidityNoUpperBound ValidityNoUpperBoundInAllegraEra
MaryEra -> TxValidityNoUpperBound ValidityNoUpperBoundInMaryEra
AlonzoEra -> TxValidityNoUpperBound ValidityNoUpperBoundInAlonzoEra
BabbageEra -> TxValidityNoUpperBound ValidityNoUpperBoundInBabbageEra
ConwayEra -> TxValidityNoUpperBound ValidityNoUpperBoundInConwayEra
defaultTxValidityUpperBound =
caseByronAndAllegraEraOnwardsOrShelleyEraOnly
TxValidityNoUpperBound
(\w -> TxValidityUpperBound (shelleyEraOnlyToShelleyBasedEra w) maxBound)
(cardanoEra @era)

data TxValidityLowerBound era where

Expand Down Expand Up @@ -2710,16 +2643,16 @@ fromLedgerTxValidityRange sbe body =
case sbe of
ShelleyBasedEraShelley ->
( TxValidityNoLowerBound
, TxValidityUpperBound ValidityUpperBoundInShelleyEra $ body ^. L.ttlTxBodyL
, TxValidityUpperBound sbe $ body ^. L.ttlTxBodyL
)

ShelleyBasedEraAllegra ->
( case invalidBefore of
SNothing -> TxValidityNoLowerBound
SJust s -> TxValidityLowerBound ValidityLowerBoundInAllegraEra s
, case invalidHereafter of
SNothing -> TxValidityNoUpperBound ValidityNoUpperBoundInAllegraEra
SJust s -> TxValidityUpperBound ValidityUpperBoundInAllegraEra s
SNothing -> TxValidityNoUpperBound ByronAndAllegraEraOnwardsAllegra
SJust s -> TxValidityUpperBound sbe s
)
where
L.ValidityInterval{invalidBefore, invalidHereafter} = body ^. L.vldtTxBodyL
Expand All @@ -2729,8 +2662,8 @@ fromLedgerTxValidityRange sbe body =
SNothing -> TxValidityNoLowerBound
SJust s -> TxValidityLowerBound ValidityLowerBoundInMaryEra s
, case invalidHereafter of
SNothing -> TxValidityNoUpperBound ValidityNoUpperBoundInMaryEra
SJust s -> TxValidityUpperBound ValidityUpperBoundInMaryEra s
SNothing -> TxValidityNoUpperBound ByronAndAllegraEraOnwardsMary
SJust s -> TxValidityUpperBound sbe s
)
where
L.ValidityInterval{invalidBefore, invalidHereafter} = body ^. L.vldtTxBodyL
Expand All @@ -2740,8 +2673,8 @@ fromLedgerTxValidityRange sbe body =
SNothing -> TxValidityNoLowerBound
SJust s -> TxValidityLowerBound ValidityLowerBoundInAlonzoEra s
, case invalidHereafter of
SNothing -> TxValidityNoUpperBound ValidityNoUpperBoundInAlonzoEra
SJust s -> TxValidityUpperBound ValidityUpperBoundInAlonzoEra s
SNothing -> TxValidityNoUpperBound ByronAndAllegraEraOnwardsAlonzo
SJust s -> TxValidityUpperBound sbe s
)
where
L.ValidityInterval{invalidBefore, invalidHereafter} = body ^. L.vldtTxBodyL
Expand All @@ -2751,8 +2684,8 @@ fromLedgerTxValidityRange sbe body =
SNothing -> TxValidityNoLowerBound
SJust s -> TxValidityLowerBound ValidityLowerBoundInBabbageEra s
, case invalidHereafter of
SNothing -> TxValidityNoUpperBound ValidityNoUpperBoundInBabbageEra
SJust s -> TxValidityUpperBound ValidityUpperBoundInBabbageEra s
SNothing -> TxValidityNoUpperBound ByronAndAllegraEraOnwardsBabbage
SJust s -> TxValidityUpperBound sbe s
)
where
L.ValidityInterval{invalidBefore, invalidHereafter} = body ^. L.vldtTxBodyL
Expand All @@ -2762,8 +2695,8 @@ fromLedgerTxValidityRange sbe body =
SNothing -> TxValidityNoLowerBound
SJust s -> TxValidityLowerBound ValidityLowerBoundInConwayEra s
, case invalidHereafter of
SNothing -> TxValidityNoUpperBound ValidityNoUpperBoundInConwayEra
SJust s -> TxValidityUpperBound ValidityUpperBoundInConwayEra s
SNothing -> TxValidityNoUpperBound ByronAndAllegraEraOnwardsConway
SJust s -> TxValidityUpperBound sbe s
)
where
L.ValidityInterval{invalidBefore, invalidHereafter} = body ^. L.vldtTxBodyL
Expand Down Expand Up @@ -2976,7 +2909,7 @@ getByronTxBodyContent (Annotated Byron.UnsafeTx{txInputs, txOutputs} _) =
, txReturnCollateral = TxReturnCollateralNone
, txTotalCollateral = TxTotalCollateralNone
, txFee = TxFeeImplicit ByronEraOnlyByron
, txValidityRange = (TxValidityNoLowerBound, TxValidityNoUpperBound ValidityNoUpperBoundInByronEra)
, txValidityRange = (TxValidityNoLowerBound, TxValidityNoUpperBound ByronAndAllegraEraOnwardsByron)
, txMetadata = TxMetadataNone
, txAuxScripts = TxAuxScriptsNone
, txExtraKeyWits = TxExtraKeyWitnessesNone
Expand Down
4 changes: 0 additions & 4 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,13 @@ module Cardano.Api (

-- ** Era-dependent transaction body features
CollateralSupportedInEra(..),
ValidityUpperBoundSupportedInEra(..),
ValidityNoUpperBoundSupportedInEra(..),
ValidityLowerBoundSupportedInEra(..),
AuxScriptsSupportedInEra(..),
TxExtraKeyWitnessesSupportedInEra(..),
TxTotalAndReturnCollateralSupportedInEra(..),

-- ** Feature availability functions
collateralSupportedInEra,
validityUpperBoundSupportedInEra,
validityNoUpperBoundSupportedInEra,
validityLowerBoundSupportedInEra,
auxScriptsSupportedInEra,
extraKeyWitnessesSupportedInEra,
Expand Down

0 comments on commit 08ba0fe

Please sign in to comment.