hydra-tx
Safe HaskellSafe-Inferred
LanguageGHC2021

Hydra.Tx.ContestationPeriod

Synopsis

Documentation

newtype ContestationPeriod Source #

A positive, non-zero number of seconds. Use fromInteger on positive literals, fromEnum via [1..] syntax or fromNominalDiffTime to create values of unknown sign. NOTE: FromJSON is deliberately newtype-derived and therefore total: it also decodes the persisted event log, where a value an older node legitimately wrote has to stay decodable or the node could never start again. A configured period is validated at the configuration boundary instead, see parseCardanoChainConfig.

Instances

Instances details
FromJSON ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

ToJSON ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

Enum ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

Generic ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

Associated Types

type Rep ContestationPeriod :: Type -> Type Source #

Num ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

Integral ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

Real ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

Show ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

FromCBOR ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

ToCBOR ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

Methods

toCBOR :: ContestationPeriod -> Encoding

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy ContestationPeriod -> Size

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [ContestationPeriod] -> Size

Eq ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

Ord ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

type Rep ContestationPeriod Source # 
Instance details

Defined in Hydra.Tx.ContestationPeriod

type Rep ContestationPeriod = D1 ('MetaData "ContestationPeriod" "Hydra.Tx.ContestationPeriod" "hydra-tx-2.4.1-6u9wd83eS2xF3WS9TuJN93" 'True) (C1 ('MetaCons "UnsafeContestationPeriod" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Natural)))

fromNominalDiffTime :: MonadFail m => NominalDiffTime -> m ContestationPeriod Source #

Create a ContestationPeriod from a NominalDiffTime. This will fail if a negative NominalDiffTime is provided and truncates to 1s if values < 1s are given.

toChain :: ContestationPeriod -> ContestationPeriod Source #

Convert an off-chain contestation period to its on-chain representation.

fromChain :: ContestationPeriod -> Either Text ContestationPeriod Source #

Convert an on-chain contestation period to its off-chain representation, accepting exactly the values toChain can produce: a positive whole number of seconds.

The on-chain representation is a signed number of milliseconds and nothing constrains it, so an observed datum can carry a value this type cannot hold. Rejecting rather than rounding matters beyond the obvious underflow: the node decides whether to join a head by comparing this value against its own configuration, and then writes toChain of it back into the closing datum, which the head validator requires to equal what the opening datum held. A period that only survives the trip approximately would pass the comparison and then fail that equality forever, leaving a head that can never be closed.