cardano-ledger-core-1.12.0.0: Core components of Cardano ledgers from the Shelley release on.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Ledger.Core.Translation

Synopsis

Documentation

type family PreviousEra era = (r ∷ Type) | r → era Source #

Map an era to its predecessor.

For example:

type instance PreviousEra (AllegraEra c) = ShelleyEra c

Instances

Instances details
type PreviousEra (ByronEra c) Source # 
Instance details

Defined in Cardano.Ledger.Core.Era

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).

type family 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.

class (Era era, Era (PreviousEra era)) ⇒ TranslateEra era f 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 (TxBody era)

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

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

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.

translateEraTranslateEra era f ⇒ TranslationContext 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.

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.

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.

translateEraThroughCBOR Source #

Arguments

∷ ∀ era ti to. (Era era, ToCBOR (ti (PreviousEra era)), DecCBOR (Annotator (to era))) 
Text

Label for error reporting

→ ti (PreviousEra era) 
Except DecoderError (to era) 

Translate a type through its binary representation from previous era to the current one.