haskledger
LicenseApache-2.0
Stabilityprovisional
Safe HaskellNone
LanguageHaskell2010

HaskLedger.Combinators

Description

Combinators and operators for accessing ledger data and expressing conditions within a HaskLedger contract.

All combinators take monadic Contract Expr arguments so let-bindings work naturally in do blocks.

Synopsis

Convenience combinators

theRedeemer :: Contract Expr #

The redeemer from the script context, as raw Data.

theTxInfo :: Contract Expr #

The TxInfo record from the script context, as raw Data.

txValidRange :: Contract Expr #

The transaction validity range (Interval POSIXTime), as raw Data.

Operators

(.==) :: Contract Expr -> Contract Expr -> Contract Condition infix 4 #

Integer equality (EqualsInteger).

(./=) :: Contract Expr -> Contract Expr -> Contract Condition infix 4 #

Integer inequality. notBool (a .== b).

(.<) :: Contract Expr -> Contract Expr -> Contract Condition infix 4 #

Integer strict less-than (LessThanInteger).

(.<=) :: Contract Expr -> Contract Expr -> Contract Condition infix 4 #

Integer less-than-or-equal (LessThanEqualsInteger).

(.>) :: Contract Expr -> Contract Expr -> Contract Condition infix 4 #

Integer strict greater-than. flip (.<).

(.>=) :: Contract Expr -> Contract Expr -> Contract Condition infix 4 #

Integer greater-than-or-equal. flip (.<=).

(.&&) :: Contract Condition -> Contract Condition -> Contract Condition infixr 3 #

Logical AND. Compiles to IfThenElse a b False. Both operands evaluated eagerly.

(.||) :: Contract Condition -> Contract Condition -> Contract Condition infixr 2 #

Logical OR. Compiles to IfThenElse a True b. Both operands evaluated eagerly.

Script context access

scriptContext :: Contract Expr #

The raw script context Data - the single argument to every PlutusV3 validator.

txInfo :: Contract Expr -> Contract Expr #

Extract TxInfo from a script context (field 0).

redeemer :: Contract Expr -> Contract Expr #

Extract the redeemer from a script context (field 1).

TxInfo field access

validRange :: Contract Expr -> Contract Expr #

Extract the validity range from TxInfo (field 7).

Data conversion

asInt :: Contract Expr -> Contract Expr #

Interpret a Data value as an integer (UnIData).

mkInt :: Integer -> Contract Expr #

Construct an on-chain integer literal. Usually unnecessary - the Num instance lets you write 42 directly.

Integer comparisons

equalsInt :: Contract Expr -> Contract Expr -> Contract Condition #

EqualsInteger. Prefer .==.

lessThanInt :: Contract Expr -> Contract Expr -> Contract Condition #

LessThanInteger. Prefer .<.

lessThanEqInt :: Contract Expr -> Contract Expr -> Contract Condition #

LessThanEqualsInteger. Prefer .<=.

Time range operations

after :: Contract Expr -> Contract Expr -> Contract Condition #

Check that a validity range starts at or after a deadline.

The deadline is a POSIX timestamp in milliseconds (Cardano's on-chain unit).

Walks the Interval POSIXTime encoding to extract the lower bound, reads the closure flag, and compares against the deadline. Closed (inclusive) bounds check deadline <= time; open (exclusive) bounds check deadline <= time + 1. Non-finite bounds (NegInf, PosInf) crash at runtime, which is the correct rejection for a deadline validator.

Boolean combinators

andBool :: Contract Condition -> Contract Condition -> Contract Condition #

Logical AND. IfThenElse a b False. Both operands evaluated eagerly. For short-circuit semantics, use requireAll instead.

orBool :: Contract Condition -> Contract Condition -> Contract Condition #

Logical OR. IfThenElse a True b. Both operands evaluated eagerly.

notBool :: Contract Condition -> Contract Condition #

Logical NOT. IfThenElse cond False True.