var img = document.createElement('img'); img.src = "https://terradocs.matomo.cloud//piwik.php?idsite=3&rec=1&url=https://docs.warp.money" + location.pathname; img.style = "border:0"; img.alt = "tracker"; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(img,s);
Skip to main content

Conditions and expressions

Conditions represent event definitions, and they outline the circumstances under which a job can be completed. A condition is a recursive data type that allows for multiple conditions within it, all of which need to resolve to true for the Job to allow execution. This complex data type includes several underlying types. For more general information on conditions, visit the concepts section. To view an example of a condition message, visit the Example page. For information about conditions in templates, visit the template tutorial.

Conditions can be either a single expression, or they can be nested and chained using regular boolean operators, such as And, Or, or Not.

condition.rs
Copy

_6
pub enum Condition {
_6
And(Vec<Box<Condition>>),
_6
Or(Vec<Box<Condition>>),
_6
Not(Box<Condition>),
_6
Expr(Expr),
_6
}

Expressions

Expressions contain comparisons of popular data types, such as integers, unsigned integers, timestamps, booleans, strings, and more.

condition.rs
Copy

_9
pub enum Expr {
_9
String(GenExpr<Value<String>, StringOp>),
_9
Uint(GenExpr<NumValue<Uint256, NumExprOp, IntFnOp>, NumOp>),
_9
Int(GenExpr<NumValue<i128, NumExprOp, IntFnOp>, NumOp>),
_9
Decimal(GenExpr<NumValue<Decimal256, NumExprOp, DecimalFnOp>, NumOp>),
_9
Timestamp(TimeExpr),
_9
BlockHeight(BlockExpr),
_9
Bool(QueryExpr),
_9
}

Values

A value is the simplest type of input used in an expression. In double-sided general expressions, the value can either be a primitive type or a query that gets a primitive type.

condition.rs
Copy

_22
pub enum Value<T> {
_22
Simple(T),
_22
Query(QueryExpr),
_22
}
_22
_22
pub enum NumValue<T, ExprOp, FnOp> {
_22
Simple(T),
_22
Expr(NumExprValue<T, ExprOp, FnOp>),
_22
Query(QueryExpr),
_22
Fn(NumFnValue<T, ExprOp, FnOp>),
_22
}
_22
_22
pub struct NumExprValue<T, ExprOp, FnOp> {
_22
pub left: Box<NumValue<T, ExprOp, FnOp>>,
_22
pub op: ExprOp,
_22
pub right: Box<NumValue<T, ExprOp, FnOp>>,
_22
}
_22
_22
pub struct NumFnValue<T, ExprOp, FnOp> {
_22
pub op: FnOp,
_22
pub right: Box<NumValue<T, ExprOp, FnOp>>,
_22
}

General expressions

General expressions or GenExpr are used to compare two values using a:

The operators of general expressions vary depending on the value type.

condition.rs
Copy

_5
pub struct GenExpr<Type, Op> {
_5
pub left: Type,
_5
pub op: Op,
_5
pub right: Type,
_5
}

Comparing values

Only values of the same Type can be compared when writing an expression.

String operators

The following operators are used in general expressions when comparing strings.

condition.rs
Copy

_8
#[cw_serde]
_8
pub enum StringOp {
_8
StartsWith,
_8
EndsWith,
_8
Contains,
_8
Eq,
_8
Neq,
_8
}

Number operators

The following operators are used in general expressions when comparing integers or decimals.

condition.rs
Copy

_9
#[cw_serde]
_9
pub enum NumOp {
_9
Eq,
_9
Neq,
_9
Lt,
_9
Gt,
_9
Gte,
_9
Lte,
_9
}

Time expressions

Time expressions are like regular unsigned integer expressions, except they only contain a left value and an operator. The right value is filled by a BlockHeight or Timestamp, depending on the value type.

condition.rs
Copy

_4
pub struct TimeExpr {
_4
pub comparator: Uint64,
_4
pub op: TimeOp,
_4
}

Time operators

Time operators can be greater than or less than a specified time.

condition.rs
Copy

_4
pub enum TimeOp {
_4
Lt,
_4
Gt,
_4
}

Blockheight

Blockheights can be specified as a Unit64 and a number operator.

condition.rs
Copy

_4
pub struct BlockExpr {
_4
pub comparator: Uint64,
_4
pub op: NumOp,
_4
}

Queries

Queries can be used in expressions as variables. For more information on queries, visit the Query page.

Bool

Queries can also be written as boolean expressions, in which a [query selector] is evaluated as a boolean.