Copyright | (c) 2023 GYELD GMBH |
---|---|
License | Apache 2.0 |
Maintainer | [email protected] |
Stability | develop |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Synopsis
- data GYSlotConfig
- data GYEraSlotConfig
- makeSlotConfig ∷ SystemStart → EraHistory → Either String GYSlotConfig
- simpleSlotConfig ∷ UTCTime → NominalDiffTime → GYSlotConfig
- mainnetSlotConfig ∷ UTCTime → GYSlotConfig
- slotToBeginTimePure ∷ GYSlotConfig → GYSlot → GYTime
- slotToEndTimePure ∷ GYSlotConfig → GYSlot → GYTime
- enclosingSlotFromTimePure ∷ GYSlotConfig → GYTime → Maybe GYSlot
- unsafeEnclosingSlotFromTimePure ∷ GYSlotConfig → GYTime → GYSlot
- slotToEpochPure ∷ GYSlotConfig → GYSlot → GYEpochNo
- slotToEpochPure' ∷ GYSlotConfig → GYSlot → (GYEpochNo, GYEpochSize)
- epochToBeginSlotPure ∷ GYSlotConfig → GYEpochNo → GYSlot
Documentation
data GYSlotConfig #
Slot config for each era, alongside the absolute system start time.
Invariants ==
- List must be ordered on era, with earliest era first, and current era last.
- Each era element must be continuous.
i.e for [x, y], the slot start of y must be the end slot of x (see EraHistory
).
- The final era element must be the current era, and it is _assumed_ that its end is unbounded (realistic).
Instances
Show GYSlotConfig # | |
Defined in GeniusYield.Types.SlotConfig showsPrec ∷ Int → GYSlotConfig → ShowS # show ∷ GYSlotConfig → String # showList ∷ [GYSlotConfig] → ShowS # | |
Eq GYSlotConfig # | |
Defined in GeniusYield.Types.SlotConfig (==) ∷ GYSlotConfig → GYSlotConfig → Bool # (/=) ∷ GYSlotConfig → GYSlotConfig → Bool # |
data GYEraSlotConfig #
Information about slot config for a particular ledger era.
Instances
Show GYEraSlotConfig # | |
Defined in GeniusYield.Types.SlotConfig showsPrec ∷ Int → GYEraSlotConfig → ShowS # show ∷ GYEraSlotConfig → String # showList ∷ [GYEraSlotConfig] → ShowS # | |
Eq GYEraSlotConfig # | |
Defined in GeniusYield.Types.SlotConfig (==) ∷ GYEraSlotConfig → GYEraSlotConfig → Bool # (/=) ∷ GYEraSlotConfig → GYEraSlotConfig → Bool # |
makeSlotConfig ∷ SystemStart → EraHistory → Either String GYSlotConfig #
Create a GYSlotConfig
from the system start and the cardano era history.
This is the recommended, robust, way to create slot config.
simpleSlotConfig ∷ UTCTime → NominalDiffTime → GYSlotConfig #
Create a single era slot config (useful for emulator traces).
DO NOT USE for testnets/mainnet. Please use makeSlotConfig
instead.
mainnetSlotConfig ∷ UTCTime → GYSlotConfig #
Slot config corresponding to mainnet but with parameterized zero time.
slotToBeginTimePure ∷ GYSlotConfig → GYSlot → GYTime #
Get the starting GYTime
of a GYSlot
given a GYSlotConfig
.
>>>
slotToBeginTimePure (simpleSlotConfig (Time.posixSecondsToUTCTime 10) 2) (unsafeSlotFromInteger 1)
GYTime 12s
slotToEndTimePure ∷ GYSlotConfig → GYSlot → GYTime #
Get the ending GYTime
of a GYSlot
(inclusive) given a GYSlotConfig
.
>>>
slotToEndTimePure (simpleSlotConfig (Time.posixSecondsToUTCTime 10) 2) (unsafeSlotFromInteger 1)
GYTime 13.999s
enclosingSlotFromTimePure ∷ GYSlotConfig → GYTime → Maybe GYSlot #
Get the GYSlot
of a GYTime
given a GYSlotConfig
.
Returns Nothing
if given time is before known system start.
>>>
enclosingSlotFromTimePure (simpleSlotConfig (Time.posixSecondsToUTCTime 10) 2) (timeFromPOSIX 12)
Just (GYSlot 1)
>>>
enclosingSlotFromTimePure (simpleSlotConfig (Time.posixSecondsToUTCTime 10) 2) (timeFromPOSIX 14)
Just (GYSlot 2)
unsafeEnclosingSlotFromTimePure ∷ GYSlotConfig → GYTime → GYSlot #
Partial version of enclosingSlotFromTimePure
.
slotToEpochPure ∷ GYSlotConfig → GYSlot → GYEpochNo #
Get epoch number in which the given slot belongs to.
>>>
let slotToEpochPureForMainnet = slotToEpochPure (mainnetSlotConfig $ Time.posixSecondsToUTCTime 0)
>>>
slotToEpochPureForMainnet (unsafeSlotFromInteger 72316800)
GYEpochNo 365>>>
slotToEpochPureForMainnet (unsafeSlotFromInteger 72316799)
GYEpochNo 364>>>
slotToEpochPureForMainnet (unsafeSlotFromInteger 72316801)
GYEpochNo 365>>>
slotToEpochPureForMainnet (unsafeSlotFromInteger 72748799)
GYEpochNo 365>>>
slotToEpochPureForMainnet (unsafeSlotFromInteger 72748800)
GYEpochNo 366
slotToEpochPure' ∷ GYSlotConfig → GYSlot → (GYEpochNo, GYEpochSize) #
Get epoch number and epoch size in which the given slot belongs to.
epochToBeginSlotPure ∷ GYSlotConfig → GYEpochNo → GYSlot #
Get the first slot in the given epoch. >>> let epochToBeginSlotPureForMainnet = epochToBeginSlotPure (mainnetSlotConfig $ Time.posixSecondsToUTCTime 0) >>> epochToBeginSlotPureForMainnet (GYEpochNo 508) GYSlot 134092800 >>> epochToBeginSlotPureForMainnet (GYEpochNo 507) GYSlot 133660800 >>> epochToBeginSlotPureForMainnet (GYEpochNo 506) GYSlot 133228800