Skip to content

Commit 7042397

Browse files
committed
update readme
1 parent 326b359 commit 7042397

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

README.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,40 @@ Cell Script is a newly designed language for smart-contract programming on the U
66

77
Here is an example of a simple cell script.
88
```
9+
//package main
10+
import "debug"
911
import "tx"
1012
import "cell"
11-
import "debug"
1213
14+
// main is the entry point of every cell script
1315
function main() {
16+
var inputs := tx.inputs()
17+
var outputs := tx.outputs()
1418
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
2020
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+
}
2427
}
25-
}
2628
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+
}
2936
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
3643
}
3744
```
3845

0 commit comments

Comments
 (0)