haskledger
LicenseApache-2.0
Stabilityprovisional
Safe HaskellNone
LanguageHaskell2010

HaskLedger.Contract

Description

Core types and control flow for defining Cardano validators.

Synopsis

Types

data Validator #

A named validator carrying the Covenant ASG builder for its on-chain code.

type Contract a = ASGBuilder a #

Monadic computation type for building contracts. Alias for Covenant's ASGBuilder.

type Expr = Ref #

Expression reference within a contract. Alias for Covenant's Ref.

type Condition = Expr #

Boolean expression used in require and requireAll. Same type as Expr.

Validator construction

validator :: String -> Contract Expr -> Validator #

Construct a Validator from a name and a contract body.

Control flow

pass :: Contract Expr #

Succeed unconditionally by returning unit ().

require :: String -> Contract Condition -> Contract Expr #

Require a condition to be true; crash via division-by-zero if false.

Compiles to (\_ -> ()) (DivideInteger 1 (IfThenElse cond 1 0)). Both IfThenElse branches are safe integer literals. The result becomes the denominator - 1 when true (harmless), 0 when false (crash). The wrapper discards the integer and returns Unit.

requireAll :: [(String, Contract Condition)] -> Contract Expr #

Require all conditions to be true, checked left to right. First failure aborts. Conditions are sequenced with ChooseUnit for left-to-right short-circuit evaluation.

Orphan instances

Num (Contract Expr) #

Integer literals and arithmetic in contract expressions.

42 desugars to fromInteger 42, building an on-chain integer constant. Supports (+), (-), (*), negate. Not supported: abs, signum.

Instance details