Skip to content

Commit 2c9c2fb

Browse files
committed
Add some inspector methods to dynafed::Params
1 parent ddb9277 commit 2c9c2fb

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

src/dynafed.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,80 @@ pub enum Params {
5353
},
5454
}
5555

56+
impl Params {
57+
/// Check whether this is [Params::Null].
58+
pub fn is_null(&self) -> bool {
59+
match *self {
60+
Params::Null => true,
61+
Params::Compact { .. } => false,
62+
Params::Full { .. } => false,
63+
}
64+
}
65+
66+
/// Check whether this is [Params::Compact].
67+
pub fn is_compact(&self) -> bool {
68+
match *self {
69+
Params::Null => false,
70+
Params::Compact { .. } => true,
71+
Params::Full { .. } => false,
72+
}
73+
}
74+
75+
/// Check whether this is [Params::Full].
76+
pub fn is_full(&self) -> bool {
77+
match *self {
78+
Params::Null => false,
79+
Params::Compact { .. } => false,
80+
Params::Full { .. } => true,
81+
}
82+
}
83+
84+
/// Get the signblockscript. Is [None] for [Null] params.
85+
pub fn signblockscript(&self) -> Option<&bitcoin::Script> {
86+
match *self {
87+
Params::Null => None,
88+
Params::Compact { ref signblockscript, ..} => Some(signblockscript),
89+
Params::Full { ref signblockscript, ..} => Some(signblockscript),
90+
}
91+
}
92+
93+
/// Get the signblock_witness_limit. Is [None] for [Null] params.
94+
pub fn signblock_witness_limit(&self) -> Option<u32> {
95+
match *self {
96+
Params::Null => None,
97+
Params::Compact { signblock_witness_limit, ..} => Some(signblock_witness_limit),
98+
Params::Full { signblock_witness_limit, ..} => Some(signblock_witness_limit),
99+
}
100+
}
101+
102+
/// Get the fedpeg_program. Is [None] for non-[Full] params.
103+
pub fn fedpeg_program(&self) -> Option<&bitcoin::Script> {
104+
match *self {
105+
Params::Null => None,
106+
Params::Compact { .. } => None,
107+
Params::Full { ref fedpeg_program, ..} => Some(fedpeg_program),
108+
}
109+
}
110+
111+
/// Get the fedpegscript. Is [None] for non-[Full] params.
112+
pub fn fedpegscript(&self) -> Option<&Vec<u8>> {
113+
match *self {
114+
Params::Null => None,
115+
Params::Compact { .. } => None,
116+
Params::Full { ref fedpegscript, ..} => Some(fedpegscript),
117+
}
118+
}
119+
120+
/// Get the extension_space. Is [None] for non-[Full] params.
121+
pub fn extension_space(&self) -> Option<&Vec<Vec<u8>>> {
122+
match *self {
123+
Params::Null => None,
124+
Params::Compact { .. } => None,
125+
Params::Full { ref extension_space, ..} => Some(extension_space),
126+
}
127+
}
128+
}
129+
56130
#[cfg(feature = "serde")]
57131
impl<'de> Deserialize<'de> for Params {
58132
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {

0 commit comments

Comments
 (0)