You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: darc-docs/docs/DARC Protocol/Condition Nodes.md
+34-2Lines changed: 34 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -23,12 +23,12 @@ struct NodeParam {
23
23
24
24
There are three logical operators in the DARC protocol: `AND`, `OR`, and `NOT`. The `AND` operator returns true if all of its children are true. The `OR` operator returns true if any of its children are true. The `NOT` operator returns true if its child is false. There must be at least one child for the `AND` and `OR` operators, and only one child for the `NOT` operator.
25
25
26
-
In both By-law Script and darc.js SDK, you can use the `and()`, `or()`, and `not()` functions to create the logical operators, for example:
26
+
In both By-law Script and darc.js SDK, you can use the `and()`, `or()`, and `not()`wrapper functions to create the logical operators, for example:
27
27
28
28
In darc.js SDK:
29
29
30
30
```ts
31
-
import {and, or, not} from'darcjs';
31
+
import {and, or, not, AND, OR, NOT} from'darcjs';
32
32
33
33
const conditionTree =and(
34
34
or(
@@ -42,6 +42,20 @@ const conditionTree = and(
42
42
expression4()
43
43
)
44
44
);
45
+
46
+
// or using the class constructor
47
+
const conditionTree =newAnd(
48
+
newOR(
49
+
expression1(),
50
+
expression2()
51
+
),
52
+
53
+
expression3(),
54
+
55
+
newNOT(
56
+
expression4()
57
+
)
58
+
);
45
59
```
46
60
47
61
In By-law Script:
@@ -59,6 +73,20 @@ const conditionTree = and(
59
73
expression4()
60
74
)
61
75
);
76
+
77
+
// or using the class constructor
78
+
const conditionTree =newAND(
79
+
newOR(
80
+
expression1(),
81
+
expression2()
82
+
),
83
+
84
+
expression3(),
85
+
86
+
newNOT(
87
+
expression4()
88
+
)
89
+
);
62
90
```
63
91
64
92
Also you can use `|` for `OR`, `&` for `AND`, and `!` for `NOT` in By-law Script, and these operators will be parsed into the corresponding condition nodes. For example, the above By-law Script can be written as:
@@ -70,6 +98,10 @@ const conditionTree =
70
98
( !expression4() );
71
99
```
72
100
101
+
### Boolean Values
102
+
103
+
There are two boolean values in the DARC protocol: class `TRUE` and clss `FALSE`, or wrapper function `boolean_true()` and `boolean_false()`. They are used to represent a boolean node in the condition tree.
104
+
73
105
### Condition Expression
74
106
75
107
1. There are multiple batch-operations, including:
0 commit comments