Skip to content

Commit

Permalink
support no input witness (#19)
Browse files Browse the repository at this point in the history
* support no input witness
* add more test cases
  • Loading branch information
XuJiandong authored Apr 28, 2021
1 parent b759582 commit 4e1e983
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 50 deletions.
12 changes: 9 additions & 3 deletions c/rce.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,22 @@ static uint32_t rce_read_from_cell_data(uintptr_t* arg, uint8_t* ptr,
}
}

int make_cursor_from_witness(WitnessArgsType* witness);
int make_cursor_from_witness(WitnessArgsType* witness, bool* use_input_type);

static int rce_get_proofs(uint32_t index, SmtProofEntryVecType* res) {
int err = 0;
bool use_input_type = true;
WitnessArgsType witness;

err = make_cursor_from_witness(&witness);
err = make_cursor_from_witness(&witness, &use_input_type);
CHECK(err);

BytesOptType input = witness.t->input_type(&witness);
BytesOptType input;
if (use_input_type) {
input = witness.t->input_type(&witness);
} else {
input = witness.t->output_type(&witness);
}
CHECK2(!input.t->is_none(&input), ERROR_INVALID_MOL_FORMAT);

mol2_cursor_t bytes = input.t->unwrap(&input);
Expand Down
28 changes: 21 additions & 7 deletions c/xudt_rce.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ uint8_t g_witness_data_source[DEFAULT_DATA_SOURCE_LENGTH];
// due to the "static" data (s_witness_data_source), the "WitnessArgsType" is a
// singleton. note: mol2_data_source_t consumes a lot of memory due to the
// "cache" field (default 2K)
int make_cursor_from_witness(WitnessArgsType* witness) {
int make_cursor_from_witness(WitnessArgsType* witness, bool* use_input_type) {
int err = 0;
uint64_t witness_len = 0;
// at the beginning of the transactions including RCE,
Expand All @@ -148,9 +148,10 @@ int make_cursor_from_witness(WitnessArgsType* witness) {
if (err == CKB_INDEX_OUT_OF_BOUND) {
source = CKB_SOURCE_GROUP_OUTPUT;
err = ckb_load_witness(NULL, &witness_len, 0, 0, source);
CHECK(err);
*use_input_type = false;
} else {
*use_input_type = true;
}

CHECK(err);
CHECK2(witness_len > 0, ERROR_INVALID_MOL_FORMAT);

Expand Down Expand Up @@ -182,10 +183,16 @@ int make_cursor_from_witness(WitnessArgsType* witness) {
int get_extension_data(uint32_t index, uint8_t* buff, uint32_t buff_len,
uint32_t* out_len) {
int err = 0;
err = make_cursor_from_witness(&g_witness_args);
bool use_input_type = true;
err = make_cursor_from_witness(&g_witness_args, &use_input_type);
CHECK(err);

BytesOptType input = g_witness_args.t->input_type(&g_witness_args);
BytesOptType input;
if (use_input_type)
input = g_witness_args.t->input_type(&g_witness_args);
else
input = g_witness_args.t->output_type(&g_witness_args);

CHECK2(!input.t->is_none(&input), ERROR_INVALID_MOL_FORMAT);

mol2_cursor_t bytes = input.t->unwrap(&input);
Expand All @@ -210,10 +217,17 @@ int get_extension_data(uint32_t index, uint8_t* buff, uint32_t buff_len,
// the *var_len may be bigger than real length of raw extension data
int load_raw_extension_data(uint8_t** var_data, uint32_t* var_len) {
int err = 0;
err = make_cursor_from_witness(&g_witness_args);
bool use_input_type = true;
err = make_cursor_from_witness(&g_witness_args, &use_input_type);
CHECK(err);

BytesOptType input = g_witness_args.t->input_type(&g_witness_args);
BytesOptType input;
if (use_input_type) {
input = g_witness_args.t->input_type(&g_witness_args);
} else {
input = g_witness_args.t->output_type(&g_witness_args);
}

CHECK2(!input.t->is_none(&input), ERROR_INVALID_MOL_FORMAT);

struct mol2_cursor_t bytes = input.t->unwrap(&input);
Expand Down
Loading

0 comments on commit 4e1e983

Please sign in to comment.