Skip to content

Commit 5d158a4

Browse files
tnullValuedMammal
authored andcommitted
fix(descriptor): correct variable binding names in l: and u: fragment modifiers
The `l:` arm bound `a_networks_kinds` but referenced `a_network_kinds`, and the `u:` arm bound `a_networks` but referenced `a_network_kinds`. Both closures silently captured the wrong variable from an outer scope, which could produce incorrect network kind filtering results. Co-Authored-By: HAL 9000 Signed-off-by: Elias Rohrer <dev@tnull.de>
1 parent 35a87f3 commit 5d158a4

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/descriptor/dsl.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ macro_rules! apply_modifier {
395395
})
396396
}};
397397
( l: $inner:expr ) => {{
398-
$inner.and_then(|(a_minisc, a_keymap, a_networks_kinds)| {
398+
$inner.and_then(|(a_minisc, a_keymap, a_network_kinds)| {
399399
$crate::impl_leaf_opcode_value_two!(
400400
OrI,
401401
$crate::alloc::sync::Arc::new($crate::fragment!(false).unwrap().0),
@@ -405,7 +405,7 @@ macro_rules! apply_modifier {
405405
})
406406
}};
407407
( u: $inner:expr ) => {{
408-
$inner.and_then(|(a_minisc, a_keymap, a_networks)| {
408+
$inner.and_then(|(a_minisc, a_keymap, a_network_kinds)| {
409409
$crate::impl_leaf_opcode_value_two!(
410410
OrI,
411411
$crate::alloc::sync::Arc::new(a_minisc),
@@ -1250,4 +1250,18 @@ mod test {
12501250

12511251
assert_eq!(descriptor.to_string(), "tr(02e96fe52ef0e22d2f131dd425ce1893073a3c6ad20e8cac36726393dfb4856a4c,pk(02e96fe52ef0e22d2f131dd425ce1893073a3c6ad20e8cac36726393dfb4856a4c))#lzl2vmc7")
12521252
}
1253+
1254+
#[test]
1255+
fn test_dsl_l_and_u_modifiers() {
1256+
let private_key =
1257+
PrivateKey::from_wif("cSQPHDBwXGjVzWRqAHm6zfvQhaTuj1f2bFH58h55ghbjtFwvmeXR").unwrap();
1258+
1259+
// Test l: modifier - or_i(false, X)
1260+
let (l_desc, _, _) = descriptor!(wsh(l: pk(private_key))).unwrap();
1261+
assert!(l_desc.to_string().contains("l:pk("));
1262+
1263+
// Test u: modifier - or_i(X, false)
1264+
let (u_desc, _, _) = descriptor!(wsh(u: pk(private_key))).unwrap();
1265+
assert!(u_desc.to_string().contains("u:pk("));
1266+
}
12531267
}

0 commit comments

Comments
 (0)