Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Cardano.Ledger.Api.Era
Synopsis
- class (Typeable era, KnownNat (ProtVerLow era), KnownNat (ProtVerHigh era), ProtVerLow era <= ProtVerHigh era, MinVersion <= ProtVerLow era, MinVersion <= ProtVerHigh era, CmpNat (ProtVerLow era) MaxVersion ~ 'LT, CmpNat (ProtVerHigh era) MaxVersion ~ 'LT, ProtVerLow era <= MaxVersion, ProtVerHigh era <= MaxVersion) ⇒ Era era where
- type PreviousEra era = (r ∷ Type) | r → era
- type ProtVerLow era ∷ Nat
- type ProtVerHigh era ∷ Nat
- class (EraTx era, EraTxOut era, EraTxBody era, EraTxAuxData era, EraTxWits era, EraScript era, EraPParams era, EraSegWits era, EraTxCert era) ⇒ EraApi era where
- type TxUpgradeError era ∷ Type
- type TxBodyUpgradeError era ∷ Type
- upgradeTx ∷ EraTx (PreviousEra era) ⇒ Tx (PreviousEra era) → Either (TxUpgradeError era) (Tx era)
- upgradeTxBody ∷ EraTxBody (PreviousEra era) ⇒ TxBody (PreviousEra era) → Either (TxBodyUpgradeError era) (TxBody era)
- upgradeTxAuxData ∷ EraTxAuxData (PreviousEra era) ⇒ TxAuxData (PreviousEra era) → TxAuxData era
- upgradeTxWits ∷ EraTxWits (PreviousEra era) ⇒ TxWits (PreviousEra era) → TxWits era
- eraName ∷ Era era ⇒ String
- data ByronEra
- data ShelleyEra
- data AllegraEra
- data MaryEra
- data AlonzoEra
- data BabbageEra
- data ConwayEra
- data DijkstraEra
- type LatestKnownEra = DijkstraEra
- eraProtVerHigh ∷ Era era ⇒ Version
- eraProtVerLow ∷ Era era ⇒ Version
- type AtLeastEra atLeastEra era = ProtVerAtLeast era (ProtVerLow atLeastEra)
- type AtMostEra eraMostEra era = ProtVerAtMost era (ProtVerHigh eraMostEra)
- type ExactEra inEra era = ProtVerInBounds era (ProtVerLow inEra) (ProtVerHigh inEra)
- type family ProtVerAtLeast era (l ∷ Nat) where ...
- type family ProtVerAtMost era (h ∷ Nat) where ...
- type ProtVerInBounds era (l ∷ Nat) (h ∷ Nat) = (ProtVerAtLeast era l, ProtVerAtMost era h)
- atLeastEra ∷ AtLeastEra eraName era ⇒ ()
- atMostEra ∷ AtMostEra eraName era ⇒ ()
Eras
class (Typeable era, KnownNat (ProtVerLow era), KnownNat (ProtVerHigh era), ProtVerLow era <= ProtVerHigh era, MinVersion <= ProtVerLow era, MinVersion <= ProtVerHigh era, CmpNat (ProtVerLow era) MaxVersion ~ 'LT, CmpNat (ProtVerHigh era) MaxVersion ~ 'LT, ProtVerLow era <= MaxVersion, ProtVerHigh era <= MaxVersion) ⇒ Era era Source #
Minimal complete definition
Associated Types
type PreviousEra era = (r ∷ Type) | r → era Source #
Map an era to its predecessor.
For example:
type instance PreviousEra (AllegraEra c) = ShelleyEra c
type ProtVerLow era ∷ Nat Source #
Lowest major protocol version for this era
type ProtVerHigh era ∷ Nat Source #
Highest major protocol version for this era. By default se to ProtVerLow
type ProtVerHigh era = ProtVerLow era
class (EraTx era, EraTxOut era, EraTxBody era, EraTxAuxData era, EraTxWits era, EraScript era, EraPParams era, EraSegWits era, EraTxCert era) ⇒ EraApi era where Source #
Associated Types
type TxUpgradeError era ∷ Type Source #
Upgrade transactions from the previous era.
This will preseve the values in corresponding Haskell structures where possible,
however it will not preserve the binary representation for memoized types.
If binary representation and validity of signatures, scriptIntegrityHash and
auxDataHash must be retained, then the corresponding
binaryUpgradeTx
, binaryUpgradeTxBody
, binaryUpgradeTxAuxData
and binaryUpgradeTxWits
functions
should be used instead.
Compare the two types of upgrade:
- `upgrade[Tx, TxBody, TxAuxData, TxWits]` will use the Haskell representation, but will not
preserve the serialised form. However, they will be suitable for iterated
translation through eras.
- `binaryUpgrade[Tx, TxBody, TxAuxData, TxWits]` will preserve the binary representation, but are
not guaranteed to work through multiple eras - that is, the serialised
representation from era n is guaranteed valid in era n + 1, but not
necessarily in era n + 2.
See below an example of how the upgrade function can change the underlying serialization:
>>>
import Cardano.Ledger.Api.Era (BabbageEra, ConwayEra)
>>>
import Test.QuickCheck
>>>
import Test.Cardano.Ledger.Babbage.Arbitrary ()
>>>
import Cardano.Ledger.Plutus.Data
>>>
import Cardano.Ledger.Alonzo.TxWits (unTxDats)
>>>
import Cardano.Ledger.MemoBytes (getMemoRawBytes)
>>>
import Cardano.Ledger.Binary (serialize)
Let's generate an arbitrary Babbage TxWits: >>> witsBabbage <- generate $ arbitrary @(TxWits BabbageEra)
Now we upgrade it to Conway using the upgrade functionality in this module: >>> witsUpgraded = upgradeTxWits witsBabbage
We can check that the values in the data structures have been preserved. For simplicity, let's check the txDats: let dats = Map.map unData . unTxDats . txdats in dats witsBabbage == dats witsUpgraded True
However, the upgraded value will have a different serialized binary representation than the original,
because the serialization of TxWits changed from Babbage to Conway
>>> getMemoRawBytes witsBabbage == getMemoRawBytes witsUpgraded
False
>>> serialize (eraProtVerHigh BabbageEra) witsBabbage == serialize (eraProtVerHigh
BabbageEra) witsUpgraded
False
type TxUpgradeError era = Void
type TxBodyUpgradeError era ∷ Type Source #
type TxBodyUpgradeError era = Void
Methods
upgradeTx ∷ EraTx (PreviousEra era) ⇒ Tx (PreviousEra era) → Either (TxUpgradeError era) (Tx era) Source #
Upgrade a transaction from the previous era.
Warning - This may not preserve the underlying binary representation.
Use binaryUpgradeTx
instead, if you need to preserve the serialised form.
upgradeTxBody ∷ EraTxBody (PreviousEra era) ⇒ TxBody (PreviousEra era) → Either (TxBodyUpgradeError era) (TxBody era) Source #
Upgrade a transaction body from the previous era.
Warning - This may not preserve the underlying binary representation.
Use binaryUpgradeTxBody
instead, if you need to preserve the serialised form.
upgradeTxAuxData ∷ EraTxAuxData (PreviousEra era) ⇒ TxAuxData (PreviousEra era) → TxAuxData era Source #
Upgrade txAuxData from the previous era.
Warning - This may not preserve the underlying binary representation.
Use binaryUpgradeTxAuxData
instead, if you need to preserve the serialised form.
upgradeTxWits ∷ EraTxWits (PreviousEra era) ⇒ TxWits (PreviousEra era) → TxWits era Source #
Upgrade txWits from the previous era.
Warning - This may not preserve the underlying binary representation.
Use binaryUpgradeTxWits
instead, if you need to preserve the serialised form.
Instances
eraName ∷ Era era ⇒ String Source #
Textual name of the current era.
Designed to be used with TypeApplications
:
>>>
eraName @ByronEra
"Byron"
Byron
This is the era that preceded Shelley era. It cannot have any other class instances,
except for Era
type class.
Instances
Era ByronEra | |
Defined in Cardano.Ledger.Core.Era Associated Types type PreviousEra ByronEra = (r ∷ Type) Source # type ProtVerLow ByronEra ∷ Nat Source # type ProtVerHigh ByronEra ∷ Nat Source # | |
type PreviousEra ByronEra | |
Defined in Cardano.Ledger.Core.Era | |
type ProtVerHigh ByronEra | |
Defined in Cardano.Ledger.Core.Era | |
type ProtVerLow ByronEra | |
Defined in Cardano.Ledger.Core.Era |
Shelley
data ShelleyEra Source #
Instances
Allegra
data AllegraEra Source #
Instances
Mary
Instances
Alonzo
Instances
Babbage
data BabbageEra Source #
Instances
Conway
Instances
Dijkstra
data DijkstraEra Source #
Instances
Latest Known
type LatestKnownEra = DijkstraEra Source #
Sometimes it is useful to specify that a type corresponds to a latest era that is currently implemented
Protocol version
Value level
eraProtVerHigh ∷ Era era ⇒ Version Source #
Get the value level Version
of the highest major protocol version for the supplied era
.
eraProtVerLow ∷ Era era ⇒ Version Source #
Get the value level Version
of the lowest major protocol version for the supplied era
.
Type level constraints
type AtLeastEra atLeastEra era = ProtVerAtLeast era (ProtVerLow atLeastEra) Source #
Restrict the era
to equal to atLeastEra
or come after it
type AtMostEra eraMostEra era = ProtVerAtMost era (ProtVerHigh eraMostEra) Source #
Restrict the era
to equal to eraName
or come before it.
type ExactEra inEra era = ProtVerInBounds era (ProtVerLow inEra) (ProtVerHigh inEra) Source #
Restrict an era to the specific era through the protocol version. This is
equivalent to (inEra (Crypto era) ~ era)
type family ProtVerAtLeast era (l ∷ Nat) where ... Source #
Requirement for the era's highest protocol version to be higher or equal to the supplied value
Equations
ProtVerAtLeast era l = ProtVerIsInBounds "at least" era l (l <=? ProtVerHigh era) |
type family ProtVerAtMost era (h ∷ Nat) where ... Source #
Requirement for the era's lowest protocol version to be lower or equal to the supplied value
Equations
ProtVerAtMost era h = ProtVerIsInBounds "at most" era h (ProtVerLow era <=? h) |
type ProtVerInBounds era (l ∷ Nat) (h ∷ Nat) = (ProtVerAtLeast era l, ProtVerAtMost era h) Source #
Restrict a lower and upper bounds of the protocol version for the particular era
atLeastEra ∷ AtLeastEra eraName era ⇒ () Source #
Enforce era to be at least the specified era at the type level. In other words compiler will produce type error when applied to eras prior to the specified era. This function should be used in order to avoid redundant constraints warning.
For example these will type check
atLeastEra @BabbageEra @ConwayEra atLeastEra @BabbageEra @BabbageEra
However this will result in a type error
atLeastEra @BabbageEra @AlonzoEra
atMostEra ∷ AtMostEra eraName era ⇒ () Source #
Enforce era to be at most the specified era at the type level. In other words compiler will produce type error when applied to eras prior to the specified era. This function should be used in order to avoid redundant constraints warning.
For example these will type check
atMostEra @BabbageEra @ShelleyEra atMostEra @AlonzoEra @MaryEra
However this will result in a type error
atMostEra @BabbageEra @ConwayEra