@@ -6,33 +6,40 @@ Cell Script is a newly designed language for smart-contract programming on the U
6
6
7
7
Here is an example of a simple cell script.
8
8
```
9
+ //package main
10
+ import "debug"
9
11
import "tx"
10
12
import "cell"
11
- import "debug"
12
13
14
+ // main is the entry point of every cell script
13
15
function main() {
16
+ var inputs := tx.inputs()
17
+ var outputs := tx.outputs()
14
18
15
- vector<cell> inputs = tx.inputs();
16
- vector<cell> outputs = tx.outputs();
17
- if(inputs.size() < outputs.size()) {
18
- return false;
19
- }
19
+ var in_sum, out_sum uint128
20
20
21
- for(cell input: inputs) {
22
- if(input.capacity < 100) {
23
- return true;
21
+ for _, input := range inputs {
22
+ in_sum += input.data.as(uint128)
23
+ if in_sum < input.data.as(uint128) {
24
+ debug.Printf("input overflow")
25
+ return 1
26
+ }
24
27
}
25
- }
26
28
27
- uint8 idx = tx.scriptIndex("script hash");
28
- debug.log("find the script hash at cell idx");
29
+ for _, output := range outputs {
30
+ out_sum += output.data.as(uint128)
31
+ if out_sum < input.data.as(uint128) {
32
+ debug.Printf("output overflow")
33
+ return 1
34
+ }
35
+ }
29
36
30
- vector<vector<byte>> witness = tx.witness();
31
- for(vector<byte> w: witness) {
32
- debug.log("the witness data is", w);
33
- }
34
-
35
- return true;
37
+ if in_sum < out_sum {
38
+ debug.Printf("Invalid Amount")
39
+ return 1
40
+ }
41
+
42
+ return 0
36
43
}
37
44
```
38
45
0 commit comments