Summary
This document is based on the specification of SASEUL JS. The SASEUL main network is currently using version 0.2.0, and we plan to support additional operators through patches.
- A method is a collection of operators.
- A method is executed only when the “condition” statement is true.
- Execution methods can modify status data through the “update” statement.
- Query methods can define the value to be returned through the “response” statement.
BasicOperator
SASEUL.SmartContract.Operator.condition
If all the conditions specified in this function are true, the method is executed, and if any condition is false, an error message is displayed.
- function (condition, err_msg)
1
2
3
4
5
6
7
8
9
10
11
const SASEUL = require('saseul');
let op = SASEUL.SmartContract.Operator;
let condition, err_msg;
let method = new SASEUL.SmartContract.Method();
condition = op.gte(3, 1);
err_msg = 'err_msg ';
method.addExecution(op.condition(condition, err_msg));
...
SASEUL.SmartContract.Operator.response
The result of this function becomes the return value of the method.
- function (response)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const SASEUL = require('saseul');
let op = SASEUL.SmartContract.Operator;
let response;
let method = new SASEUL.SmartContract.Method();
let token_id = op.load_param('token_id');
let address = op.load_param('address');
let balance = op.read_universal(token_id, address, '0');
response = op.response({"balance": balance});
method.addExecution(response);
...
SASEUL.SmartContract.Operator.weight
Returns the weight of the executed transaction.
- function ()
1
2
3
...
let weight = op.weight();
...
SASEUL.SmartContract.Operator.if
If “condition” is true, return if_true, otherwise return if_false.
- function (condition, if_true, if_false)
1
2
3
4
5
6
...
result = op.if(true, '0.1', '0.3');
...
// result = '0.1'
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.and
It is the ‘and’ functionality in most programming languages.
- function ([value1, value2, …])
1
2
3
4
5
6
...
result = op.and([true, false]);
...
// result = false
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.or
It is the ‘or’ functionality in most programming languages.
- function ([value1, value2, …])
1
2
3
4
5
6
...
result = op.or([false, op.and([true, true])]);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.get
If the obj value is an array, it returns the value of obj[key].
- function (obj, key)
1
2
3
4
5
6
...
result = op.get({"a":"b"}, "a");
...
// result = 'b'
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
ArithmeticOperator
SASEUL.SmartContract.Operator.add
It returns the result of adding up all the values.
- function ([value1, value2, …])
1
2
3
4
5
6
...
result = op.add([1, 2, 3]);
...
// result = 6
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.sub
It returns the value obtained by subtracting all the remaining values from the first value.
- function ([value1, value2, …])
1
2
3
4
5
6
...
result = op.sub([5, 2, op.add([1,1])]);
...
// result = 1
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.mul
It returns the result of multiplying all the values.
- function ([value1, value2, …])
1
2
3
4
5
6
...
result = op.mul([3, 5, 6]);
...
// result = 120
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.div
It returns the value obtained by dividing all the remaining values from the first value.
- function ([value1, value2, …])
1
2
3
4
5
6
...
result = op.div([10, 2, 5]);
...
// result = 1
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.precise_add
It returns the value obtained by adding two numbers with consideration of precision based on the scale.
- function (left, right, scale)
1
2
3
4
5
6
...
result = op.precise_add(1.15, 2.567, 3);
...
// result = 3.717
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.precise_sub
It returns the value obtained by subtracting two numbers with consideration of precision based on the scale.
- function (left, right, scale)
1
2
3
4
5
6
...
result = op.precise_sub(6.15, 2.567, 3);
...
// result = 3.583
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.precise_mul
It returns the value obtained by multiplying two numbers with consideration of precision based on the scale.
- function (left, right, scale)
1
2
3
4
5
6
...
result = op.precise_mul(6.15, 2.567, 5);
...
// result = 15.78705
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.precise_div
It returns the value obtained by dividing two numbers with consideration of precision based on the scale.
- function (left, right, scale)
1
2
3
4
5
6
...
result = op.precise_div(2.15, 2.567, 3);
...
// result = 0.838
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.scale
It returns the scale of the value.
- function (value)
1
2
3
4
5
6
...
result = op.scale(2.15);
...
// result = 2
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
CastOperator
SASEUL.SmartContract.Operator.get_type
It returns the data type of the value.
- function (obj)
1
2
3
4
5
6
...
result = op.get_type("a");
...
// result = "string"
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.is_numeric
It returns true if the data type of the value can be represented as a number.
- function (vars)
1
2
3
4
5
6
...
result = op.is_numeric([1.5]);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.is_int
It returns true if the data type of the value is ‘int’.
- function (vars)
1
2
3
4
5
6
...
result = op.is_int([2]);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.is_string
It returns true if the data type of the value is ‘string’.
- function (vars)
1
2
3
4
5
6
...
result = op.is_string(["string"]);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.is_null
It returns true if the value is null.
- function (vars)
1
2
3
4
5
6
...
result = op.is_null([null]);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.is_bool
It returns true if the data type of the value is ‘bool’.
- function (vars)
1
2
3
4
5
6
...
result = op.is_bool([false]);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.is_array
It returns true if the data type of the value is ‘array’ or ‘object’.
- function (vars)
1
2
3
4
5
6
...
result = op.is_array([[1,2,3]]);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.is_double
It returns true if the data type of the value is ‘double’.
- function (vars)
1
2
3
4
5
6
...
result = op.is_double([1.2]);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
ComparisonOperator
SASEUL.SmartContract.Operator.eq
It returns true if the two values are equal.
- function (left, right)
1
2
3
4
5
6
...
result = op.eq(1, 1);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.ne
It returns true if the two values are different.
- function (left, right)
1
2
3
4
5
6
...
result = op.ne(1, 2);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.gt
It returns true if the value on the left is greater than the value on the right.
- function (left, right)
1
2
3
4
5
6
...
result = op.gt(3, 2);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.lt
It returns true if the value on the right is greater than the value on the left.
- function (left, right)
1
2
3
4
5
6
...
result = op.lt(2, 4);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.gte
It returns true if the value on the left is greater than or equal to the value on the right.
- function (left, right)
1
2
3
4
5
6
...
result = op.gte(3, 3);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.lte
It returns true if the value on the right is greater than or equal to the value on the left.
- function (left, right)
1
2
3
4
5
6
...
result = op.lte(3, 3);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.in
It returns true if the target is an element in the cases array.
- function (target, cases)
1
2
3
4
5
6
...
result = op.in(a, [a, b]);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
ReadWriteOperator
SASEUL.SmartContract.Operator.load_param
It returns a specific value of a signed transaction.
- function (target)
1
2
3
4
5
{
"type": "Send",
"to": "<ADDRESS>",
"amount": "5000"
}
1
2
3
4
5
6
...
result = op.load_param("amount");
...
// result = "5000"
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.read_universal
It returns the value stored in the “Universal Status” data.
- function (attr, key, default)
1
2
3
4
5
6
7
8
9
...
result = op.read_universal("balance", "<ADDRESS>", "0");
response = op.response(result);
method.addExecution(response);
...
// result = (The balance data of an address.)
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.read_local
It returns the value stored in the “Local Status” data.
- function (attr, key, default)
1
2
3
4
5
6
7
8
9
...
result = op.read_local("genesis", "00");
response = op.response(result);
method.addExecution(response);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.write_universal
(Only in the Update statement within the method) It stores a value in the “Universal Status” data space during the processing of the contract.
- function (attr, key, value)
1
2
3
4
...
update = op.write_universal("balance", "<ADDRESS>", "5000");
method.addUpdate(update);
...
SASEUL.SmartContract.Operator.write_local
(Only in the Update statement within the method) It stores a value in the “Local Status” data space during the processing of the contract.
- function (attr, key, value)
1
2
3
4
...
update = op.write_local("genesis", "00", true);
method.addUpdate(update);
...
UtilOperator
SASEUL.SmartContract.Operator.concat
It returns a concatenated string of the given strings.
- function ([string1, string2, …])
1
2
3
4
5
6
...
result = op.concat(['Lo', 'rem Ipsum']);
...
// result = 'Lorem Ipsum'
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.strlen
It returns the length of the given string.
- function (string)
1
2
3
4
5
6
...
result = op.strlen('Lorem Ipsum');
...
// result = 11
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.reg_match
It checks the string with the given regular expression and returns the result.
- function (regexp, string)
- ```javascript … result = op.reg_match(‘/^[A-Za-z_0-9]+$/’, ‘Lorem Ipsum’); …
// result = true // Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
## SASEUL.SmartContract.Operator.encode_json
It returns the JSON string converted from the given value.
- function (obj)
```javascript
...
result = op.encode_json({});
...
// result = '{}'
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.decode_json
It returns the decoded value from the given JSON
- function (json)
1
2
3
4
5
6
...
result = op.decode_json('{}');
...
// result = {}
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.hash
It returns the result of hashing the given value with SHA-256.
- function ([value1, value2, …])
1
2
3
4
5
6
...
result = op.hash(['Lorem Ipsum']);
...
// result = (hash of ['Lorem Ipsum'])
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.short_hash
It returns the result of hashing the given value with SHA-256 and then RIPEMD-160.
- function ([value1, value2, …])
1
2
3
4
5
6
...
result = op.short_hash(['Lorem Ipsum']);
...
// result = (short_hash of ['Lorem Ipsum'])
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
SASEUL.SmartContract.Operator.id_hash
It calculates the address hash from the given value and returns the result.
- function ([value1, value2, …])
1
2
3
4
5
6
...
result = op.id_hash(['Lorem Ipsum']);
...
// result = (id_hash of ['Lorem Ipsum'])
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.
It returns true if the target is an element in the cases array.
- function (target, cases)
1
2
3
4
5
6
...
result = op.in(a, [a, b]);
...
// result = true
// Results are not directly expressed in JavaScript, but are computed only within the SASEUL Engine.