Skip to content

Commit

Permalink
Merge pull request #281 from input-output-hk/newhoggy/rename-eon-func…
Browse files Browse the repository at this point in the history
…tions

Rename eon functions
  • Loading branch information
newhoggy committed Sep 29, 2023
2 parents 8f61c8c + 4b6ecd8 commit 4bf96a1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 35 deletions.
37 changes: 23 additions & 14 deletions cardano-api/internal/Cardano/Api/Eon/ShelleyBasedEra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ module Cardano.Api.Eon.ShelleyBasedEra
, AnyShelleyBasedEra(..)
, InAnyShelleyBasedEra(..)
, shelleyBasedToCardanoEra
, eonInShelleyBasedEra
, inShelleyBasedEraEon
, inShelleyBasedEraEonMaybe
, maybeEonInShelleyBasedEra
, inEonForShelleyBasedEra
, inEonForShelleyBasedEraMaybe
, forShelleyBasedEraInEon
, forShelleyBasedEraInEonMaybe
, forShelleyBasedEraMaybeEon

-- * Cardano eras, as Byron vs Shelley-based
, CardanoEraStyle(..)
Expand All @@ -45,38 +46,46 @@ import qualified Data.Text as Text
import Data.Type.Equality (TestEquality (..), (:~:) (Refl))

-- | Determine the value to use for a feature in a given 'ShelleyBasedEra'.
eonInShelleyBasedEra :: ()
inEonForShelleyBasedEra :: ()
=> Eon eon
=> a
-> (eon era -> a)
-> ShelleyBasedEra era
-> a
eonInShelleyBasedEra no yes =
inEonForShelleyBasedEra no yes =
inEonForEra no yes . shelleyBasedToCardanoEra

maybeEonInShelleyBasedEra :: ()
inEonForShelleyBasedEraMaybe :: ()
=> Eon eon
=> (eon era -> a)
-> ShelleyBasedEra era
-> Maybe a
inEonForShelleyBasedEraMaybe yes =
inEonForShelleyBasedEra Nothing (Just . yes)

forShelleyBasedEraMaybeEon :: ()
=> Eon eon
=> ShelleyBasedEra era
-> Maybe (eon era)
maybeEonInShelleyBasedEra =
forShelleyBasedEraMaybeEon =
inEonForEra Nothing Just . shelleyBasedToCardanoEra

inShelleyBasedEraEon :: ()
forShelleyBasedEraInEon :: ()
=> Eon eon
=> ShelleyBasedEra era
-> a
-> (eon era -> a)
-> a
inShelleyBasedEraEon era no yes =
eonInShelleyBasedEra no yes era
forShelleyBasedEraInEon era no yes =
inEonForShelleyBasedEra no yes era

inShelleyBasedEraEonMaybe :: ()
forShelleyBasedEraInEonMaybe :: ()
=> Eon eon
=> ShelleyBasedEra era
-> (eon era -> a)
-> Maybe a
inShelleyBasedEraEonMaybe era yes =
inShelleyBasedEraEon era Nothing (Just . yes)
forShelleyBasedEraInEonMaybe era yes =
forShelleyBasedEraInEon era Nothing (Just . yes)

-- ----------------------------------------------------------------------------
-- Shelley-based eras
Expand Down
6 changes: 4 additions & 2 deletions cardano-api/internal/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ module Cardano.Api.Eras
-- * IsEon
, Eon(..)
, AnyEraInEon(..)

, inEonForEraMaybe
, forEraInEon
, inEraEonMaybe
, maybeEonInEra
, forEraInEonMaybe
, forEraMaybeEon

-- * Data family instances
, AsType(AsByronEra, AsShelleyEra, AsAllegraEra, AsMaryEra, AsAlonzoEra, AsBabbageEra, AsConwayEra)
Expand Down
21 changes: 15 additions & 6 deletions cardano-api/internal/Cardano/Api/Eras/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ module Cardano.Api.Eras.Core
-- * IsEon
, Eon(..)
, AnyEraInEon(..)
, inEonForEraMaybe
, forEraInEon
, inEraEonMaybe
, maybeEonInEra
, forEraInEonMaybe
, forEraMaybeEon

-- * Data family instances
, AsType(AsByronEra, AsShelleyEra, AsAllegraEra, AsMaryEra, AsAlonzoEra, AsBabbageEra, AsConwayEra)
Expand Down Expand Up @@ -116,6 +117,14 @@ class Eon (eon :: Type -> Type) where
-> CardanoEra era -- ^ Era to check
-> a -- ^ The value to use

inEonForEraMaybe :: ()
=> Eon eon
=> (eon era -> a) -- ^ Function to get the value to use if the eon includes the era
-> CardanoEra era -- ^ Era to check
-> Maybe a -- ^ The value to use
inEonForEraMaybe yes =
inEonForEra Nothing (Just . yes)

forEraInEon :: ()
=> Eon eon
=> CardanoEra era -- ^ Era to check
Expand All @@ -125,19 +134,19 @@ forEraInEon :: ()
forEraInEon era no yes =
inEonForEra no yes era

inEraEonMaybe :: ()
forEraInEonMaybe :: ()
=> Eon eon
=> CardanoEra era -- ^ Era to check
-> (eon era -> a) -- ^ Function to get the value to use if the eon includes the era
-> Maybe a -- ^ The value to use
inEraEonMaybe era yes =
forEraInEonMaybe era yes =
forEraInEon era Nothing (Just . yes)

maybeEonInEra :: ()
forEraMaybeEon :: ()
=> Eon eon
=> CardanoEra era -- ^ Era to check
-> Maybe (eon era) -- ^ The eon if supported in the era
maybeEonInEra =
forEraMaybeEon =
inEonForEra Nothing Just

-- ----------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ txScriptValidityToScriptValidity (TxScriptValidity _ scriptValidity) = scriptVal

scriptValidityToTxScriptValidity :: ShelleyBasedEra era -> ScriptValidity -> TxScriptValidity era
scriptValidityToTxScriptValidity sbe scriptValidity =
inShelleyBasedEraEon sbe TxScriptValidityNone $ \w -> TxScriptValidity w scriptValidity
forShelleyBasedEraInEon sbe TxScriptValidityNone $ \w -> TxScriptValidity w scriptValidity

txScriptValidityToIsValid :: TxScriptValidity era -> L.IsValid
txScriptValidityToIsValid = scriptValidityToIsValid . txScriptValidityToScriptValidity
Expand Down Expand Up @@ -1751,7 +1751,7 @@ deserialiseShelleyBasedTxBody sbe bs =
(flip CBOR.runAnnotator fbs (return TxScriptValidityNone))
4 -> do
sValiditySupported <-
inShelleyBasedEraEon sbe
forShelleyBasedEraInEon sbe
( fail $ mconcat
[ "deserialiseShelleyBasedTxBody: Expected an era that supports the "
, "script validity flag but got: "
Expand Down Expand Up @@ -1783,7 +1783,7 @@ deserialiseShelleyBasedTxBody sbe bs =
pure

sValiditySupported <-
inShelleyBasedEraEon sbe
forShelleyBasedEraInEon sbe
( fail $ mconcat
[ "deserialiseShelleyBasedTxBody: Expected an era that supports the "
, "script validity flag but got: "
Expand Down Expand Up @@ -2278,7 +2278,7 @@ fromLedgerProposalProcedures
-> Ledger.TxBody (ShelleyLedgerEra era)
-> Maybe (Featured ConwayEraOnwards era [Proposal era])
fromLedgerProposalProcedures sbe body =
inShelleyBasedEraEonMaybe sbe $ \w ->
forShelleyBasedEraInEonMaybe sbe $ \w ->
conwayEraOnwardsConstraints w
$ Featured w
$ fmap Proposal
Expand All @@ -2290,7 +2290,7 @@ fromLedgerVotingProcedures :: ()
-> Ledger.TxBody (ShelleyLedgerEra era)
-> Maybe (Featured ConwayEraOnwards era (VotingProcedures era))
fromLedgerVotingProcedures sbe body =
inShelleyBasedEraEonMaybe sbe $ \w ->
forShelleyBasedEraInEonMaybe sbe $ \w ->
conwayEraOnwardsConstraints w
$ Featured w
$ VotingProcedures
Expand Down
19 changes: 11 additions & 8 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ module Cardano.Api (
InAnyCardanoEra(..),
ToCardanoEra(..),

-- * Feature support
-- * Eon support
Eon(..),
AnyEraInEon(..),
forEraInEon,
inEraEonMaybe,
maybeEonInEra,

eonInShelleyBasedEra,
inShelleyBasedEraEon,
inShelleyBasedEraEonMaybe,
maybeEonInShelleyBasedEra,
inEonForEraMaybe,
forEraInEon,
forEraInEonMaybe,
forEraMaybeEon,

inEonForShelleyBasedEra,
inEonForShelleyBasedEraMaybe,
forShelleyBasedEraInEon,
forShelleyBasedEraInEonMaybe,
forShelleyBasedEraMaybeEon,

Featured(..),
asFeaturedInEra,
Expand Down

0 comments on commit 4bf96a1

Please sign in to comment.