ckb_sdk/types/
script_group.rs1use std::fmt;
2
3use ckb_types::packed::Script;
4use serde_derive::{Deserialize, Serialize};
5
6#[derive(Clone, Eq, PartialEq, Debug)]
12pub struct ScriptGroup {
13 pub script: Script,
17 pub group_type: ScriptGroupType,
19 pub input_indices: Vec<usize>,
21 pub output_indices: Vec<usize>,
23}
24
25impl ScriptGroup {
26 pub fn new(script: &Script, group_type: ScriptGroupType) -> Self {
28 Self {
29 group_type,
30 script: script.to_owned(),
31 input_indices: vec![],
32 output_indices: vec![],
33 }
34 }
35
36 pub fn from_lock_script(script: &Script) -> Self {
38 Self::new(script, ScriptGroupType::Lock)
39 }
40
41 pub fn from_type_script(script: &Script) -> Self {
43 Self::new(script, ScriptGroupType::Type)
44 }
45}
46
47#[derive(Copy, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)]
52#[serde(rename_all = "snake_case")]
53pub enum ScriptGroupType {
54 Lock,
56 Type,
58}
59
60impl fmt::Display for ScriptGroupType {
61 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
62 match self {
63 ScriptGroupType::Lock => write!(f, "Lock"),
64 ScriptGroupType::Type => write!(f, "Type"),
65 }
66 }
67}