Safe HaskellNone



Support for multiple (Shelley-based) eras in the ledger.



class (Crypto (Crypto e), Typeable e) ⇒ Era e Source #


Instances details
Crypto c ⇒ Era (ShelleyEra c) Source # 
Instance details

Defined in Cardano.Ledger.Shelley

Associated Types

type Crypto (ShelleyEra c) Source #

type family Crypto e ∷ Type Source #


Instances details
type Crypto (ShelleyEra c) Source # 
Instance details

Defined in Cardano.Ledger.Shelley

type Crypto (ShelleyEra c) = c

type family PreviousEra era ∷ Type Source #

Map an era to its predecessor.

For example:

type instance PreviousEra (AllegraEra c) = ShelleyEra c

type family TranslationContext era ∷ Type Source #

Per-era context used for TranslateEra.

This context will be passed to the translation instances of all types of that particular era. In practice, most instances won't need the context, but this approach makes the translation composable (as opposed to having a separate context per type).

class (Era era, Era (PreviousEra era)) ⇒ TranslateEra era f where Source #

Translation of types between eras, e.g., from Shelley to Allegra.

When era is just a phantom type parameter, an empty standalone deriving can be used:

newtype Foo era = Foo Int

instance TranslateEra (Allegra c) Foo

Note that one could use DerivingAnyClass (deriving (TranslateEra (Allegra c))), but this would introduce an undesired coupling between the era-parametric type and (a) particular era(s). The intention is to have a module with orphan instances per era.

In most cases, the era parameter won't be phantom, and a manual instance will have to be written:

newtype Bar era = Bar (Addr era)

instance CryptoClass.Crypto c => TranslateEra (Allegra c) Bar where
    translateEra ctxt = Bar <$> translateEra ctxt

-- With the following instance being in scope:
instance CryptoClass.Crypto c => TranslatEra (Allegra c) Addr

Note: we use PreviousEra instead of NextEra as an era definitely knows its predecessor, but not necessarily its successor. Moreover, one could argue that it makes more sense to define the translation from era A to era B where era B is defined, than where era A is defined.

Minimal complete definition


Associated Types

type TranslationError era f ∷ Type Source #

Most translations should be infallible (default instance), but we leave the door open for partial translations.

For a partial translation, override the default type to be () or a concrete error type.

type TranslationError era f = Void


translateEraTranslationContext era → f (PreviousEra era) → Except (TranslationError era f) (f era) Source #

Translate a type f parameterised by the era from an era to the era after it.

The translation is a given the translation context of era.

A default instance is provided for when the two types are Coercible.

default translateEraCoercible (f (PreviousEra era)) (f era) ⇒ TranslationContext era → f (PreviousEra era) → Except (TranslationError era f) (f era) Source #

translateEra' ∷ (TranslateEra era f, TranslationError era f ~ Void) ⇒ TranslationContext era → f (PreviousEra era) → f era Source #

Variant of translateEra for when TranslationError is Void and the translation thus cannot fail.

translateEraMaybe ∷ (TranslateEra era f, TranslationError era f ~ ()) ⇒ TranslationContext era → f (PreviousEra era) → Maybe (f era) Source #

Variant of translateEra for when TranslationError is (), converting the result to a Maybe.