@@ -657,6 +657,12 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
657
657
where
658
658
Pk : ' a ,
659
659
{
660
+ self . real_for_each_key ( & mut pred)
661
+ }
662
+ }
663
+
664
+ impl < Pk : MiniscriptKey > Policy < Pk > {
665
+ fn real_for_each_key < ' a , F : FnMut ( & ' a Pk ) -> bool > ( & ' a self , pred : & mut F ) -> bool {
660
666
match * self {
661
667
Policy :: Unsatisfiable | Policy :: Trivial => true ,
662
668
Policy :: Key ( ref pk) => pred ( pk) ,
@@ -667,14 +673,12 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
667
673
| Policy :: After ( ..)
668
674
| Policy :: Older ( ..) => true ,
669
675
Policy :: Threshold ( _, ref subs) | Policy :: And ( ref subs) => {
670
- subs. iter ( ) . all ( |sub| sub. for_each_key ( & mut pred) )
676
+ subs. iter ( ) . all ( |sub| sub. real_for_each_key ( & mut * pred) )
671
677
}
672
- Policy :: Or ( ref subs) => subs. iter ( ) . all ( |( _, sub) | sub. for_each_key ( & mut pred) ) ,
678
+ Policy :: Or ( ref subs) => subs. iter ( ) . all ( |( _, sub) | sub. real_for_each_key ( & mut * pred) ) ,
673
679
}
674
680
}
675
- }
676
681
677
- impl < Pk : MiniscriptKey > Policy < Pk > {
678
682
/// Convert a policy using one kind of public key to another
679
683
/// type of public key
680
684
///
@@ -1282,7 +1286,7 @@ fn generate_combination<Pk: MiniscriptKey>(
1282
1286
}
1283
1287
1284
1288
#[ cfg( all( test, feature = "compiler" ) ) ]
1285
- mod tests {
1289
+ mod compiler_tests {
1286
1290
use core:: str:: FromStr ;
1287
1291
1288
1292
use sync:: Arc ;
@@ -1343,3 +1347,18 @@ mod tests {
1343
1347
assert_eq ! ( combinations, expected_comb) ;
1344
1348
}
1345
1349
}
1350
+
1351
+ #[ cfg( test) ]
1352
+ mod tests {
1353
+ use super :: * ;
1354
+ use std:: str:: FromStr ;
1355
+
1356
+ #[ test]
1357
+ fn for_each_key ( ) {
1358
+ let liquid_pol = Policy :: < String > :: from_str (
1359
+ "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 ( ) ;
1360
+ let mut count = 0 ;
1361
+ assert ! ( liquid_pol. for_each_key( |_| { count +=1 ; true } ) ) ;
1362
+ assert_eq ! ( count, 17 ) ;
1363
+ }
1364
+ }
0 commit comments