cardano-ledger-core-0.1.0.0: Core components of Cardano ledgers from the Shelley release on.
Safe Haskell None
Language Haskell2010

Cardano.Ledger.Era

Description

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

Synopsis

Documentation

class ( Crypto ( Crypto e), Typeable e, WellFormed e) => Era e where Source #

Minimal complete definition

getTxOutEitherAddr , getAllTxInputs

Associated Types

type Crypto e :: Type Source #

Methods

getTxOutEitherAddr :: TxOut e -> Either ( Addr ( Crypto e)) ( CompactAddr ( Crypto e)) Source #

Extract from TxOut either an address or its compact version by doing the least amount of work.

The utility of this function comes from the fact that TxOut usually stores the address in either one of two forms: compacted or unpacked. In order to avoid extroneous conversions in getTxOutAddr and getTxOutCompactAddr we can define just this functionality. Also sometimes it crutial to know at the callsite which form of address we have readily available without any conversions (eg. searching millions of TxOuts for a particular address)

getTxOutAddr :: TxOut e -> Addr ( Crypto e) Source #

getTxOutCompactAddr :: TxOut e -> CompactAddr ( Crypto e) Source #

getAllTxInputs :: TxBody e -> Set ( TxIn ( Crypto e)) Source #

The validity of any individual block depends only on a subset of the UTxO stored in the ledger state. The consensus layer makes use of this fact, and uses the function below to to retrieve the needed UTxO from disk and present only those to the ledger. It is therefore neccessary that this function account for all the different types of inputs inside a transaction.

getTxOutBootstrapAddress :: forall era. Era era => TxOut era -> Maybe ( BootstrapAddress ( Crypto era)) Source #

Get the Bootsrap address from the TxOut. Returns Nothing if it is a Shelley address or newer

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

Minimal complete definition

Nothing

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.

Methods

translateEra :: 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 .

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 .

class ( Era era, SafeToHash ( Script era), HasField "body" ( Tx era) ( TxBody era)) => ValidateScript era where Source #

Typeclass for script data types. Allows for script validation and hashing. You must understand the role of SafeToHash and scriptPrefixTag to make new instances. scriptPrefixTag is a magic number representing the tag of the script language. For each new script language defined, a new tag is chosen and the tag is included in the script hash for a script. The safeToHash constraint ensures that Scripts are never reserialised.

Minimal complete definition

scriptPrefixTag , validateScript

  • Segregated Witness

The idea of segretated witnessing is to alter the encoding of transactions in a block such that the witnesses (the information needed to verify the validity of the transactions) can be stored separately from the body (the information needed to update the ledger state). In this way, a node which only cares about replaying transactions need not even decode the witness information.

In order to do this, we introduce two concepts: - A TxSeq , which represents the decoded structure of a sequence of transactions as represented in the encoded block; that is, with witnessing, metadata and other non-body parts split separately.

class SupportsSegWit era where Source #

Indicates that an era supports segregated witnessing.

This class is embodies an isomorphism between 'TxSeq era' and 'StrictSeq (Tx era)', witnessed by fromTxSeq and toTxSeq .

Associated Types

type TxSeq era = (r :: Type ) | r -> era Source #

Methods

fromTxSeq :: TxSeq era -> StrictSeq ( Tx era) Source #

toTxSeq :: StrictSeq ( Tx era) -> TxSeq era Source #

hashTxSeq :: TxSeq era -> Hash ( HASH ( Crypto era)) EraIndependentBlockBody Source #

Get the block body hash from the TxSeq. Note that this is not a regular "hash the stored bytes" function since the block body hash forms a small Merkle tree.

numSegComponents :: Word64 Source #

The number of segregated components