Safe Haskell | None |
---|---|
Language | Haskell2010 |
Cardano.Ledger.Era
Description
Support for multiple (Shelley-based) eras in the ledger.
Synopsis
-
class
(
Crypto
(
Crypto
e),
Typeable
e,
WellFormed
e) =>
Era
e
where
- type Crypto e :: Type
- getTxOutEitherAddr :: TxOut e -> Either ( Addr ( Crypto e)) ( CompactAddr ( Crypto e))
- getTxOutAddr :: TxOut e -> Addr ( Crypto e)
- getTxOutCompactAddr :: TxOut e -> CompactAddr ( Crypto e)
- getAllTxInputs :: TxBody e -> Set ( TxIn ( Crypto e))
- getTxOutBootstrapAddress :: forall era. Era era => TxOut era -> Maybe ( BootstrapAddress ( Crypto era))
- type family PreviousEra era :: Type
- type family TranslationContext era :: Type
-
class
(
Era
era,
Era
(
PreviousEra
era)) =>
TranslateEra
era f
where
- type TranslationError era f :: Type
- translateEra :: TranslationContext era -> f ( PreviousEra era) -> Except ( TranslationError era f) (f era)
- translateEra' :: ( TranslateEra era f, TranslationError era f ~ Void ) => TranslationContext era -> f ( PreviousEra era) -> f era
- translateEraMaybe :: ( TranslateEra era f, TranslationError era f ~ ()) => TranslationContext era -> f ( PreviousEra era) -> Maybe (f era)
- type WellFormed era = ( HasField "outputs" ( TxBody era) ( StrictSeq ( TxOut era)), HasField "txfee" ( TxBody era) Coin , HasField "minted" ( TxBody era) ( Set ( ScriptHash ( Crypto era))), HasField "adHash" ( TxBody era) ( StrictMaybe ( AuxiliaryDataHash ( Crypto era))), HasField "body" ( Tx era) ( TxBody era), HasField "wits" ( Tx era) ( Witnesses era), HasField "auxiliaryData" ( Tx era) ( StrictMaybe ( AuxiliaryData era)), HasField "txsize" ( Tx era) Integer , HasField "scriptWits" ( Tx era) ( Map ( ScriptHash ( Crypto era)) ( Script era)), HasField "value" ( TxOut era) ( Value era), HashAnnotated ( AuxiliaryData era) EraIndependentAuxiliaryData ( Crypto era), HashAnnotated ( TxBody era) EraIndependentTxBody ( Crypto era), SupportsSegWit era, Val ( Value era), Compactible ( Value era))
-
class
(
Era
era,
SafeToHash
(
Script
era),
HasField
"body" (
Tx
era) (
TxBody
era)) =>
ValidateScript
era
where
- scriptPrefixTag :: Script era -> ByteString
- validateScript :: Script era -> Tx era -> Bool
- hashScript :: Script era -> ScriptHash ( Crypto era)
- isNativeScript :: Script era -> Bool
- class SupportsSegWit era where
Documentation
class ( Crypto ( Crypto e), Typeable e, WellFormed e) => Era e where Source #
Minimal complete definition
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.
type TranslationError era f = Void
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
.
default translateEra :: Coercible (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
.
type WellFormed era = ( HasField "outputs" ( TxBody era) ( StrictSeq ( TxOut era)), HasField "txfee" ( TxBody era) Coin , HasField "minted" ( TxBody era) ( Set ( ScriptHash ( Crypto era))), HasField "adHash" ( TxBody era) ( StrictMaybe ( AuxiliaryDataHash ( Crypto era))), HasField "body" ( Tx era) ( TxBody era), HasField "wits" ( Tx era) ( Witnesses era), HasField "auxiliaryData" ( Tx era) ( StrictMaybe ( AuxiliaryData era)), HasField "txsize" ( Tx era) Integer , HasField "scriptWits" ( Tx era) ( Map ( ScriptHash ( Crypto era)) ( Script era)), HasField "value" ( TxOut era) ( Value era), HashAnnotated ( AuxiliaryData era) EraIndependentAuxiliaryData ( Crypto era), HashAnnotated ( TxBody era) EraIndependentTxBody ( Crypto era), SupportsSegWit era, Val ( Value era), Compactible ( Value era)) Source #
All Well Formed Eras have this minimal structure.
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
Methods
scriptPrefixTag :: Script era -> ByteString Source #
validateScript :: Script era -> Tx era -> Bool Source #
hashScript :: Script era -> ScriptHash ( Crypto era) Source #
isNativeScript :: Script era -> Bool Source #
- 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
.
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