Skip to content

Commit c087122

Browse files
committed
fix: handle output-only type scripts in native-simulator
When a type script only appears on outputs (e.g., genesis transactions), input_indices is empty. This caused an index-out-of-bounds panic when trying to access input_indices[0]. This fix checks if input_indices is empty and falls back to using output_indices[0] with is_output set to true, which correctly handles genesis/creation scenarios for type scripts.
1 parent 4e986b9 commit c087122

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/context.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,21 @@ impl Context {
604604

605605
let native_binaries = format!("{{ {} }}", native_binaries);
606606

607+
// For type scripts that only appear on outputs (e.g., genesis transactions),
608+
// input_indices is empty. In that case, use output_indices[0] and set is_output to true.
609+
let (is_output, script_index) = if !group.input_indices.is_empty() {
610+
(false, group.input_indices[0])
611+
} else if !group.output_indices.is_empty() {
612+
(true, group.output_indices[0])
613+
} else {
614+
panic!("script group has no inputs or outputs");
615+
};
616+
607617
let setup = format!(
608-
"{{\"is_lock_script\": {}, \"is_output\": false, \"script_index\": {}, \"vm_version\": {}, \"native_binaries\": {}, \"run_type\": \"DynamicLib\" }}",
618+
"{{\"is_lock_script\": {}, \"is_output\": {}, \"script_index\": {}, \"vm_version\": {}, \"native_binaries\": {}, \"run_type\": \"DynamicLib\" }}",
609619
group.group_type == ckb_script::ScriptGroupType::Lock,
610-
group.input_indices[0],
620+
is_output,
621+
script_index,
611622
2,
612623
native_binaries
613624
);

0 commit comments

Comments
 (0)