@@ -668,6 +668,12 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
668
668
where
669
669
Pk : ' a ,
670
670
{
671
+ self . real_for_each_key ( & mut pred)
672
+ }
673
+ }
674
+
675
+ impl < Pk : MiniscriptKey > Policy < Pk > {
676
+ fn real_for_each_key < ' a , F : FnMut ( & ' a Pk ) -> bool > ( & ' a self , pred : & mut F ) -> bool {
671
677
match * self {
672
678
Policy :: Unsatisfiable | Policy :: Trivial => true ,
673
679
Policy :: Key ( ref pk) => pred ( pk) ,
@@ -678,14 +684,12 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
678
684
| Policy :: After ( ..)
679
685
| Policy :: Older ( ..) => true ,
680
686
Policy :: Threshold ( _, ref subs) | Policy :: And ( ref subs) => {
681
- subs. iter ( ) . all ( |sub| sub. for_each_key ( & mut pred) )
687
+ subs. iter ( ) . all ( |sub| sub. real_for_each_key ( & mut * pred) )
682
688
}
683
- Policy :: Or ( ref subs) => subs. iter ( ) . all ( |( _, sub) | sub. for_each_key ( & mut pred) ) ,
689
+ Policy :: Or ( ref subs) => subs. iter ( ) . all ( |( _, sub) | sub. real_for_each_key ( & mut * pred) ) ,
684
690
}
685
691
}
686
- }
687
692
688
- impl < Pk : MiniscriptKey > Policy < Pk > {
689
693
/// Convert a policy using one kind of public key to another
690
694
/// type of public key
691
695
///
@@ -1291,7 +1295,7 @@ fn generate_combination<Pk: MiniscriptKey>(
1291
1295
}
1292
1296
1293
1297
#[ cfg( all( test, feature = "compiler" ) ) ]
1294
- mod tests {
1298
+ mod compiler_tests {
1295
1299
use core:: str:: FromStr ;
1296
1300
1297
1301
use sync:: Arc ;
@@ -1352,3 +1356,18 @@ mod tests {
1352
1356
assert_eq ! ( combinations, expected_comb) ;
1353
1357
}
1354
1358
}
1359
+
1360
+ #[ cfg( test) ]
1361
+ mod tests {
1362
+ use super :: * ;
1363
+ use std:: str:: FromStr ;
1364
+
1365
+ #[ test]
1366
+ fn for_each_key ( ) {
1367
+ let liquid_pol = Policy :: < String > :: from_str (
1368
+ "or(and(older(4096),thresh(2,pk(A),pk(B),pk(C))),thresh(11,pk(F1),pk(F2),pk(F3),pk(F4),pk(F5),pk(F6),pk(F7),pk(F8),pk(F9),pk(F10),pk(F11),pk(F12),pk(F13),pk(F14)))" ) . unwrap ( ) ;
1369
+ let mut count = 0 ;
1370
+ assert ! ( liquid_pol. for_each_key( |_| { count +=1 ; true } ) ) ;
1371
+ assert_eq ! ( count, 17 ) ;
1372
+ }
1373
+ }
0 commit comments