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, 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

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

Expressions

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

condition.rs

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

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

_10
pub enum Value<T> {
_10
Simple(T),
_10
Ref(String),
_10
}

NumValue

NumValue represents a numeric value that can be used in an expression with several variants:

condition.rs

_12
pub enum NumValue<T, ExprOp, FnOp> {
_12
Simple(T),
_12
Expr(NumExprValue<T, ExprOp, FnOp>),
_12
Ref(String),
_12
Fn(NumFnValue<T, ExprOp, FnOp>),
_12
Env(NumEnvValue),
_12
}
_12
_12
pub enum NumEnvValue {
_12
Time,
_12
BlockHeight,
_12
}

  • Simple(T): a simple numeric value.
  • Expr(NumExprValue<T, ExprOp, FnOp>): a numeric expression that can be evaluated to a numeric value. It contains a NumExprValue struct that has a left operand, an operator, and a right operand.
  • Ref(String): represents a reference to a numeric value stored elsewhere.
  • Fn(NumFnValue<T, ExprOp, FnOp>): represents a function that takes a numeric value as input and returns a numeric value as output. It contains a NumFnValue struct that has an operator and a right operand.
  • Env(NumEnvValue): represents a special numeric value that is derived from the environment, such as the current block height or timestamp. It contains a NumEnvValue enum that specifies the type of environment value.

General expressions

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

  • left: value,
  • an operator op:,
  • and a right: value.

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

condition.rs

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

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

  • left: value,
  • an operator op:,
  • and a right: value.

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

condition.rs

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

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

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

Number operators

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

condition.rs

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

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

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

Time operators

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

condition.rs

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

Block expressions

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

condition.rs

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

Queries

In addition to being used directly in expressions, queries can also be used as variables in the Condition and Expr. This allows for more complex expressions that can dynamically reference and compare different types of data. 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.