From c94a0946d9767454f4b619210dab72edb29649f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Fri, 6 Oct 2023 10:51:35 +0200 Subject: [PATCH] Add BabbageEraOnly --- cardano-api/cardano-api.cabal | 1 + .../Cardano/Api/Eon/BabbageEraOnly.hs | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 cardano-api/internal/Cardano/Api/Eon/BabbageEraOnly.hs diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index 34bde8ef85..eecff4cabd 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -57,6 +57,7 @@ library internal Cardano.Api.Eon.AllegraEraOnwards Cardano.Api.Eon.AlonzoEraOnly Cardano.Api.Eon.AlonzoEraOnwards + Cardano.Api.Eon.BabbageEraOnly Cardano.Api.Eon.BabbageEraOnwards Cardano.Api.Eon.ByronAndAllegraEraOnwards Cardano.Api.Eon.ByronEraOnly diff --git a/cardano-api/internal/Cardano/Api/Eon/BabbageEraOnly.hs b/cardano-api/internal/Cardano/Api/Eon/BabbageEraOnly.hs new file mode 100644 index 0000000000..e9acf19c6c --- /dev/null +++ b/cardano-api/internal/Cardano/Api/Eon/BabbageEraOnly.hs @@ -0,0 +1,55 @@ +{-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE TypeFamilies #-} + +module Cardano.Api.Eon.BabbageEraOnly + ( BabbageEraOnly(..) + , babbageEraOnlyConstraints + , babbageEraOnlyToCardanoEra + + , BabbageEraOnlyConstraints + ) where + +import Cardano.Api.Eras.Core + +import Data.Typeable (Typeable) + +data BabbageEraOnly era where + BabbageEraOnlyBabbage :: BabbageEraOnly BabbageEra + +deriving instance Show (BabbageEraOnly era) +deriving instance Eq (BabbageEraOnly era) + +instance Eon BabbageEraOnly where + inEonForEra no yes = \case + ByronEra -> no + ShelleyEra -> no + AllegraEra -> no + MaryEra -> no + AlonzoEra -> no + BabbageEra -> yes BabbageEraOnlyBabbage + ConwayEra -> no + +instance ToCardanoEra BabbageEraOnly where + toCardanoEra = \case + BabbageEraOnlyBabbage -> BabbageEra + +type BabbageEraOnlyConstraints era = + ( IsCardanoEra era + , Typeable era + ) + +babbageEraOnlyConstraints :: () + => BabbageEraOnly era + -> (BabbageEraOnlyConstraints era => a) + -> a +babbageEraOnlyConstraints = \case + BabbageEraOnlyBabbage -> id + +babbageEraOnlyToCardanoEra :: BabbageEraOnly era -> CardanoEra era +babbageEraOnlyToCardanoEra = \case + BabbageEraOnlyBabbage -> BabbageEra