Skip to content

Commit 4fe2f36

Browse files
committed
debug sudt ffi API
1 parent 034dc60 commit 4fe2f36

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

tests/examples/sudt.cell

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ import "cell"
44

55
function main() {
66
// tx.scriptVerify()
7+
// isOwnerMode return a bool value:
8+
// true - Indicate that the verification was successful and the device owner mode has been successfully set.
9+
// false - Means that either the verification process failed or the device owner mode has not been set.
10+
// In the case where verification fails, the program should terminate immediately.
11+
// For the time being, simply returning 'false' does not adequately convey the distinction between two states.
712
if tx.isOwnerMode() {
8-
return 0
13+
return 0
914
}
1015

1116
in_sum, out_sum := 0, 0
12-
17+
ins := tx.inputs()
18+
if len(ins) == int32(0) {
19+
return 1
20+
}
1321
for input := range tx.inputs() {
1422
in_sum += input
1523
}

third-party/wrapper.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,19 @@ bool is_owner_mode() {
6161
unsigned char script[SCRIPT_SIZE];
6262
uint64_t len = SCRIPT_SIZE;
6363
int ret = ckb_load_script(script, &len, 0);
64+
if (ret != CKB_SUCCESS) {
65+
return false;
66+
}
67+
if (len > SCRIPT_SIZE) {
68+
return false;
69+
}
6470

6571
mol_seg_t script_seg;
6672
script_seg.ptr = (uint8_t *)script;
6773
script_seg.size = len;
74+
if (MolReader_Script_verify(&script_seg, false) != MOL_OK) {
75+
return false;
76+
}
6877

6978
mol_seg_t args_seg = MolReader_Script_get_args(&script_seg);
7079
mol_seg_t args_bytes_seg = MolReader_Bytes_raw_bytes(&args_seg);
@@ -146,6 +155,9 @@ cell_data_t get_utxo_inputs() {
146155
int i = 0;
147156
while (1) {
148157
uint64_t len = get_input_cell_data_len(i);
158+
if (len < 16) {
159+
return EMPTY_CELL_DATA;
160+
}
149161
// uint8_t* data = (uint8_t*)malloc(len * sizeof(uint8_t));
150162
uint64_t cur_data = 0;
151163
int ret = ckb_load_cell_data(&cur_data, &len, 0, i,

0 commit comments

Comments
 (0)