Module

Contract.Time

A module containing time-related datatypes and helpers.

#getCurrentEpoch

getCurrentEpoch :: Contract Epoch

Get the current Epoch.

#getEraSummaries

getEraSummaries :: Contract EraSummaries

Get EraSummaries as used for Slot arithemetic.

More info can be found in Ogmios or Blockfrost docs (see links below). Currently we use the same data type definition. https://ogmios.dev/api/ under "eraSummaries" query https://docs.blockfrost.io/#tag/Cardano-Network/paths/~1network~1eras/get

#getSystemStart

getSystemStart :: Contract SystemStart

Get the current system start time.

#getCurrentEra

getCurrentEra :: Contract EraSummary

Get a summary of the current era.

#normalizeTimeInterval

normalizeTimeInterval :: Interval POSIXTime -> Contract (Interval POSIXTime)

Given a desired range, tighten it to fit onchain.

Re-exports from Cardano.Types

Re-exports from Contract.Chain

#getTip

Re-exports from Ctl.Internal.QueryM.Ogmios

Re-exports from Ctl.Internal.Types.Chain

#Tip

data Tip

Constructors

Instances

#ChainTip

newtype ChainTip

Constructors

Instances

Re-exports from Ctl.Internal.Types.EraSummaries

#SafeZone

newtype SafeZone

Number of slots from the tip of the ledger in which it is guaranteed that no hard fork can take place. This should be (at least) the number of slots in which we are guaranteed to have k blocks.

Constructors

Instances

#RelativeTime

newtype RelativeTime

A time in seconds relative to another one (typically, system start or era start).

Constructors

Instances

#EraSummaryParameters

newtype EraSummaryParameters

epochLength: Epoch length in number of slots.

slotLength: Slot length in milliseconds.

safe_zone: Zone in which it is guaranteed that no hard fork can take place.

Constructors

Instances

#EraSummary

newtype EraSummary

start: Era bound which captures the time, slot and epoch at which the era starts, relative to the start of the network.

end: Era bound which captures the time, slot and epoch at which the era ends, relative to the start of the network.

parameters: Era parameters that can vary across hard forks.

Constructors

Instances

Re-exports from Ctl.Internal.Types.Interval

#UpperBound

data UpperBound a

The upper bound of an interval.

Constructors

Instances

#SlotRange

#RelTime

newtype RelTime

Relative time to the start of an EraSummary. Contract this to Ogmios.QueryM.RelativeTime which is usually relative to system start. Treat as Milliseconds

Constructors

Instances

#POSIXTimeRange

type POSIXTimeRange = Interval POSIXTime

An Interval of POSIXTimes.

#OnchainPOSIXTimeRange

newtype OnchainPOSIXTimeRange

A newtype wrapper over POSIXTimeRange to represent the on-chain version of an off-chain POSIXTimeRange. In particular, there are a few steps in conversion:

  1. POSIXTimeRange -> SlotRange
  2. SlotRange -> TransactionValidity
  3. TransactionValidity -> OnchainPOSIXTimeRange OnchainPOSIXTimeRange is intended to equal the validity range found in the on-chain ScriptContext

Constructors

Instances

#ModTime

newtype ModTime

Any leftover time from using mod when dividing my slot length. Treat as Milliseconds

Constructors

Instances

#LowerBound

data LowerBound a

The lower bound of an interval.

Constructors

Instances

#Interval

data Interval a

An abstraction for Interval, it restricts the creation of intervals to the only ones that we can use in practice: [a,b+1) , [-infinity,b+1), [a,infinity], [-infinity,infinity], empty.

Constructors

Instances

#Extended

data Extended a

A set extended with a positive and negative infinity.

Constructors

Instances

#Closure

type Closure = Boolean

Whether a bound is inclusive or not.

#AbsTime

newtype AbsTime

Absolute time relative to System Start, not UNIX epoch. Treat as Milliseconds

Constructors

Instances

#upperBound

upperBound :: forall (a :: Type). a -> UpperBound a

#toOnchainPosixTimeRange

toOnchainPosixTimeRange :: EraSummaries -> SystemStart -> POSIXTimeRange -> Either ToOnChainPosixTimeRangeError OnchainPOSIXTimeRange

Create an OnchainPOSIXTimeRange to do a round trip from an off-chain POSIXTimeRange as follows:

  1. POSIXTimeRange -> SlotRange
  2. SlotRange -> TransactionValidity
  3. TransactionValidity -> OnchainPOSIXTimeRange OnchainPOSIXTimeRange is intended to equal the validity range found in the on-chain ScriptContext

#to

to :: forall (a :: Type). Ord a => a -> Interval a

to a is an Interval that includes all values that are smaller than or equal to a, represented as [-infinity,a+1).

#strictUpperBound

strictUpperBound :: forall (a :: Type). a -> UpperBound a

#strictLowerBound

strictLowerBound :: forall (a :: Type). a -> LowerBound a

#slotToPosixTime

slotToPosixTime :: EraSummaries -> SystemStart -> Slot -> Either SlotToPosixTimeError POSIXTime

Converts a CSL (Absolute) Slot (Unsigned Integer) to POSIXTime which is time elapsed from January 1, 1970 (midnight UTC/GMT). We obtain this By converting Slot to AbsTime which is time relative to some System Start, then add any excess for a UNIX Epoch time. Recall that POSIXTime is in milliseconds for Protocol Version >= 6.

#slotRangeToPosixTimeRange

slotRangeToPosixTimeRange :: EraSummaries -> SystemStart -> SlotRange -> Either SlotToPosixTimeError POSIXTimeRange

Converts a SlotRange to POSIXTimeRange given an EraSummaries and SystemStart queried from Ogmios.

#singleton

singleton :: forall (a :: Type). Ord a => Semiring a => a -> Interval a

singleton a is an Interval that contains just a, represented as [a,a+1).

#posixTimeToSlot

posixTimeToSlot :: EraSummaries -> SystemStart -> POSIXTime -> Either PosixTimeToSlotError Slot

Converts a POSIXTime to Slot given an EraSummaries and SystemStart queried from Ogmios.

#posixTimeRangeToSlotRange

posixTimeRangeToSlotRange :: EraSummaries -> SystemStart -> POSIXTimeRange -> Either PosixTimeToSlotError SlotRange

Converts a POSIXTimeRange to SlotRange given an EraSummaries and SystemStart queried from Ogmios.

#overlaps

overlaps :: forall (a :: Type). Ord a => Interval a -> Interval a -> Boolean

Check whether two intervals overlap, that is, whether there is a value that is a member of both intervals.

#never

never :: forall (a :: Type). Ord a => Interval a

An Interval that is empty, represented as [infinity,-infinity]

#mkFiniteInterval

mkFiniteInterval :: forall (a :: Type). Ord a => a -> a -> Interval a

mkFiniteInterval a b construct the interval [a,b+1)

#member

member :: forall (a :: Type). Ord a => a -> Interval a -> Boolean

Check whether a value is in an interval.

#maxSlot

maxSlot :: Slot

Maximum slot (u64)

#lowerBound

lowerBound :: forall (a :: Type). a -> LowerBound a

#isEmpty

isEmpty :: forall (a :: Type). Ord a => Interval a -> Boolean

Check if an Interval is empty.

#intersection

intersection :: forall (a :: Type). Ord a => Interval a -> Interval a -> Interval a

intersection a b is the largest interval that is contained in a and in b, if it exists.

#hull

hull :: forall (a :: Type). Ord a => Interval a -> Interval a -> Interval a

hull a b is the smallest interval containing a and b between our limited universe of intervals.

#from

from :: forall (a :: Type). Ord a => a -> Interval a

from a is an Interval that includes all values that are greater than or equal to a, represented as [a,infinity].

#findTimeEraSummary

findTimeEraSummary :: EraSummaries -> AbsTime -> Either PosixTimeToSlotError EraSummary

Finds the EraSummary an AbsTime lies inside (if any).

#findSlotEraSummary

findSlotEraSummary :: EraSummaries -> Slot -> Either SlotToPosixTimeError EraSummary

Finds the EraSummary an Slot lies inside (if any).

#contains

contains :: forall (a :: Type). Ord a => Interval a -> Interval a -> Boolean

a contains b is true if the Interval b is entirely contained in a. That is, acontainsbif for every entrys, ifmember s bthenmember s a`.

#before

before :: forall (a :: Type). Ord a => a -> Interval a -> Boolean

Check if a value is earlier than the beginning of an Interval.

#always

always :: forall (a :: Type). Ord a => Interval a

An Interval that covers every slot, represented as [-infinity,infinity]

#after

after :: forall (a :: Type). Ord a => a -> Interval a -> Boolean

Check if a value is later than the end of a Interval.

Re-exports from Ctl.Internal.Types.SystemStart

Modules