Skip to content

Commit ca928da

Browse files
fix(descriptor): simplify ref handling in ext_check helper functions
Remove redundant references and string conversions in ext_check implementations for Descriptor types. Issue: opdrop.add_ext_check
1 parent 04956a4 commit ca928da

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

src/descriptor/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,17 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
321321
/// Helper function for Wsh descriptor
322322
fn ext_check_wsh(wsh: &Wsh<Pk>, params: &ExtParams) -> Result<(), AnalysisError> {
323323
match wsh.as_inner() {
324-
WshInner::SortedMulti(ref smv) => Ok(()),
324+
WshInner::SortedMulti(_) => Ok(()),
325325
WshInner::Ms(ref ms) => ms.ext_check(params),
326326
}
327327
}
328328

329329
/// Helper function for Sh descriptor
330330
fn ext_check_sh(sh: &Sh<Pk>, params: &ExtParams) -> Result<(), AnalysisError> {
331331
match sh.as_inner() {
332-
ShInner::Wsh(ref wsh) => Self::ext_check_wsh(&wsh, params),
332+
ShInner::Wsh(ref wsh) => Self::ext_check_wsh(wsh, params),
333333
ShInner::Wpkh(_) => Ok(()),
334-
ShInner::SortedMulti(ref smv) => Ok(()),
334+
ShInner::SortedMulti(_) => Ok(()),
335335
ShInner::Ms(ref ms) => ms.ext_check(params),
336336
}
337337
}
@@ -341,9 +341,9 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
341341
match *self {
342342
Descriptor::Bare(ref bare) => bare.as_inner().ext_check(params),
343343
Descriptor::Pkh(_) => Ok(()),
344-
Descriptor::Wpkh(ref wpkh) => Ok(()),
345-
Descriptor::Wsh(ref wsh) => Self::ext_check_wsh(&wsh, params),
346-
Descriptor::Sh(ref sh) => Self::ext_check_sh(&sh, params),
344+
Descriptor::Wpkh(_) => Ok(()),
345+
Descriptor::Wsh(ref wsh) => Self::ext_check_wsh(wsh, params),
346+
Descriptor::Sh(ref sh) => Self::ext_check_sh(sh, params),
347347
Descriptor::Tr(ref tr) => tr.ext_check(params),
348348
}
349349
}

src/miniscript/analyzable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ impl ExtParams {
124124
self
125125
}
126126

127+
/// Builder that allows miniscripts with drop fragments.
127128
pub fn drop(mut self) -> ExtParams {
128129
self.drop = true;
129130
self
@@ -227,6 +228,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
227228
self.iter().any(|ms| matches!(ms.node, Terminal::RawPkH(_)))
228229
}
229230

231+
/// Whether the given miniscript contains a drop fragment
230232
pub fn contains_drop(&self) -> bool {
231233
self.iter().any(|ms| matches!(ms.node, Terminal::Drop(_)))
232234
}

src/miniscript/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ mod tests {
14991499
fn drop_wrapper() {
15001500
type SwMs = Miniscript<String, Segwitv0>;
15011501
fn assert_error(s: &str, expected_error: Option<&str>) {
1502-
match SwMs::from_str_insane(&s) {
1502+
match SwMs::from_str_insane(s) {
15031503
Ok(_) => match expected_error {
15041504
Some(e) => {
15051505
panic!("Expected error: {}", e);

src/miniscript/ms_tests.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23861,7 +23861,5 @@ mod tests {
2386123861
#[test]
2386223862
pub fn test_opdrop() {
2386323863
Miniscript::<String, Segwitv0>::from_str("and_v(v:after(100000),multi(1,A,B))").unwrap();
23864-
let ms: Miniscript<String, Segwitv0> =
23865-
Miniscript::from_str("and_v(v:after(100000),multi(1,A,B))").unwrap();
2386623864
}
2386723865
}

src/psbt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ mod tests {
17291729
let xpriv = bip32::Xpriv::new_master(bitcoin::Network::Testnet, &[42]).expect("master key");
17301730
let desc = format!(
17311731
"wsh(and_v(r:after(1024),pk({})))",
1732-
xpriv.to_keypair(&secp).public_key().to_string()
1732+
xpriv.to_keypair(&secp).public_key()
17331733
);
17341734
// let desc = format!("wsh(pk({}))", xpriv.to_keypair(&secp).public_key().to_string());
17351735
let desc = Descriptor::<DefiniteDescriptorKey>::from_str(&desc).unwrap();

0 commit comments

Comments
 (0)