Skip to content

Commit

Permalink
Rename the Byron, Shelley etc types to be clearly eras
Browse files Browse the repository at this point in the history
So rename ByronEra -> ByronEra, Shelley to ShelleyEra etc

This first step adds the new names, and keeps deprecated aliases for the
previous names.

The purpose of this renaming is because we want to clarify that these
type tags are really used to indicate an era.

Where we are tempted to use them for something other than eras then we
need new names. For example we have Byron and Shelley address types,
which are not quite the same as the Byron and Shelley era, since both
address types are available in the Shelley and all subsequent eras. So
we will want to introduce new names such as ByronAddr/ShelleyAddr and
use those rather than ByronEra/ShelleyEra for types of addresses.
  • Loading branch information
dcoutts committed Nov 19, 2020
1 parent eed2505 commit da29342
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 35 deletions.
11 changes: 11 additions & 0 deletions cardano-api/src/Cardano/API.hs
Expand Up @@ -11,6 +11,17 @@
--

module Cardano.API (
-- * Eras
ByronEra,
ShelleyEra,
AllegraEra,
MaryEra,
-- ** Deprecated
Byron,
Shelley,
Allegra,
Mary,
-- * Type tags
HasTypeProxy(..),
AsType(..),
-- * Cryptographic key interface
Expand Down
10 changes: 0 additions & 10 deletions cardano-api/src/Cardano/Api/Byron.hs
Expand Up @@ -5,16 +5,6 @@

module Cardano.Api.Byron
( module Cardano.API,
-- * Era
Byron,
HasTypeProxy(..),
AsType
( AsByronAddress
, AsByronKey
, AsByronTx
, AsByronTxBody
, AsByronWitness
),

-- * Cryptographic key interface
-- $keys
Expand Down
78 changes: 60 additions & 18 deletions cardano-api/src/Cardano/Api/Eras.hs
@@ -1,47 +1,89 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PatternSynonyms #-}


-- | Cardano eras, sometimes we have to distinguish them.
--
module Cardano.Api.Eras
( -- * Eras
Byron
ByronEra
, ShelleyEra
, AllegraEra
, MaryEra

-- * Deprecated aliases
, Byron
, Shelley
, Allegra
, Mary
, AsType(..)

-- * Data family instances
, AsType(AsByronEra, AsShelleyEra, AsAllegraEra, AsMaryEra,
AsByron, AsShelley, AsAllegra, AsMary)
) where

import Cardano.Api.HasTypeProxy


-- | A type used as a tag to distinguish the Byron era.
data Byron
data ByronEra

-- | A type used as a tag to distinguish the Shelley era.
data Shelley
data ShelleyEra

-- | A type used as a tag to distinguish the Allegra era.
data Allegra
data AllegraEra

-- | A type used as a tag to distinguish the Mary era.
data Mary
data MaryEra


instance HasTypeProxy ByronEra where
data AsType ByronEra = AsByronEra
proxyToAsType _ = AsByronEra

instance HasTypeProxy ShelleyEra where
data AsType ShelleyEra = AsShelleyEra
proxyToAsType _ = AsShelleyEra

instance HasTypeProxy AllegraEra where
data AsType AllegraEra = AsAllegraEra
proxyToAsType _ = AsAllegraEra

instance HasTypeProxy MaryEra where
data AsType MaryEra = AsMaryEra
proxyToAsType _ = AsMaryEra


-- ----------------------------------------------------------------------------
-- Deprecated aliases
--

type Byron = ByronEra
type Shelley = ShelleyEra
type Allegra = AllegraEra
type Mary = MaryEra

{-# DEPRECATED Byron "Use 'ByronEra' or 'ByronAddr' as appropriate" #-}
{-# DEPRECATED Shelley "Use 'ShelleyEra' or 'ShelleyAddr' as appropriate" #-}
{-# DEPRECATED Allegra "Use 'AllegraEra' instead" #-}
{-# DEPRECATED Mary "Use 'MaryEra' instead" #-}

pattern AsByron :: AsType ByronEra
pattern AsByron = AsByronEra

instance HasTypeProxy Byron where
data AsType Byron = AsByron
proxyToAsType _ = AsByron
pattern AsShelley :: AsType ShelleyEra
pattern AsShelley = AsShelleyEra

instance HasTypeProxy Shelley where
data AsType Shelley = AsShelley
proxyToAsType _ = AsShelley
pattern AsAllegra :: AsType AllegraEra
pattern AsAllegra = AsAllegraEra

instance HasTypeProxy Allegra where
data AsType Allegra = AsAllegra
proxyToAsType _ = AsAllegra
pattern AsMary :: AsType MaryEra
pattern AsMary = AsMaryEra

instance HasTypeProxy Mary where
data AsType Mary = AsMary
proxyToAsType _ = AsMary
{-# DEPRECATED AsByron "Use 'AsByronEra' instead" #-}
{-# DEPRECATED AsShelley "Use 'AsShelleyEra' instead" #-}
{-# DEPRECATED AsAllegra "Use 'AsAllegraEra' instead" #-}
{-# DEPRECATED AsMary "Use 'AsMaryEra' instead" #-}

7 changes: 0 additions & 7 deletions cardano-api/src/Cardano/Api/Shelley.hs
Expand Up @@ -5,13 +5,6 @@

module Cardano.Api.Shelley
( module Cardano.API,
-- * Era
Shelley,
HasTypeProxy(..),
AsType(AsShelleyAddress,
AsShelleyTxBody,
AsShelleyTx,
AsShelleyWitness),

-- * Cryptographic key interface
-- $keys
Expand Down
6 changes: 6 additions & 0 deletions cardano-api/src/Cardano/Api/Typed.hs
Expand Up @@ -26,10 +26,16 @@
--
module Cardano.Api.Typed (
-- * Eras
ByronEra,
ShelleyEra,
AllegraEra,
MaryEra,
-- ** Deprecated
Byron,
Shelley,
Allegra,
Mary,
-- * Type tags
HasTypeProxy(..),
AsType(..),
-- * Cryptographic key interface
Expand Down

0 comments on commit da29342

Please sign in to comment.