@@ -69,7 +69,7 @@ pub enum Policy<Pk: MiniscriptKey> {
69
69
/// relative probabilities for each one.
70
70
Or ( Vec < ( usize , Arc < Policy < Pk > > ) > ) ,
71
71
/// A set of descriptors, satisfactions must be provided for `k` of them.
72
- Threshold ( usize , Vec < Arc < Policy < Pk > > > ) ,
72
+ Thresh ( usize , Vec < Arc < Policy < Pk > > > ) ,
73
73
}
74
74
75
75
/// Detailed error type for concrete policies.
@@ -187,7 +187,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
187
187
} )
188
188
. collect :: < Vec < _ > > ( )
189
189
}
190
- Policy :: Threshold ( k, ref subs) if * k == 1 => {
190
+ Policy :: Thresh ( k, ref subs) if * k == 1 => {
191
191
let total_odds = subs. len ( ) ;
192
192
subs. iter ( )
193
193
. flat_map ( |policy| policy. to_tapleaf_prob_vec ( prob / total_odds as f64 ) )
@@ -242,7 +242,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
242
242
/// ### TapTree compilation
243
243
///
244
244
/// The policy tree constructed by root-level disjunctions over [`Policy::Or`] and
245
- /// [`Policy::Threshold `](1, ..) which is flattened into a vector (with respective
245
+ /// [`Policy::Thresh `](1, ..) which is flattened into a vector (with respective
246
246
/// probabilities derived from odds) of policies.
247
247
///
248
248
/// For example, the policy `thresh(1,or(pk(A),pk(B)),and(or(pk(C),pk(D)),pk(E)))` gives the
@@ -294,7 +294,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
294
294
/// ### TapTree compilation
295
295
///
296
296
/// The policy tree constructed by root-level disjunctions over [`Policy::Or`] and
297
- /// [`Policy::Threshold `](k, ..n..) which is flattened into a vector (with respective
297
+ /// [`Policy::Thresh `](k, ..n..) which is flattened into a vector (with respective
298
298
/// probabilities derived from odds) of policies. For example, the policy
299
299
/// `thresh(1,or(pk(A),pk(B)),and(or(pk(C),pk(D)),pk(E)))` gives the vector
300
300
/// `[pk(A),pk(B),and(or(pk(C),pk(D)),pk(E)))]`.
@@ -407,13 +407,13 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
407
407
. map ( |( odds, pol) | ( prob * * odds as f64 / total_odds as f64 , pol. clone ( ) ) )
408
408
. collect :: < Vec < _ > > ( )
409
409
}
410
- Policy :: Threshold ( k, subs) if * k == 1 => {
410
+ Policy :: Thresh ( k, subs) if * k == 1 => {
411
411
let total_odds = subs. len ( ) ;
412
412
subs. iter ( )
413
413
. map ( |pol| ( prob / total_odds as f64 , pol. clone ( ) ) )
414
414
. collect :: < Vec < _ > > ( )
415
415
}
416
- Policy :: Threshold ( k, subs) if * k != subs. len ( ) => generate_combination ( subs, prob, * k) ,
416
+ Policy :: Thresh ( k, subs) if * k != subs. len ( ) => generate_combination ( subs, prob, * k) ,
417
417
pol => vec ! [ ( prob, Arc :: new( pol. clone( ) ) ) ] ,
418
418
}
419
419
}
@@ -562,7 +562,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
562
562
. enumerate ( )
563
563
. map ( |( i, ( prob, _) ) | ( * prob, child_n ( i) ) )
564
564
. collect ( ) ) ,
565
- Threshold ( ref k, ref subs) => Threshold ( * k, ( 0 ..subs. len ( ) ) . map ( child_n) . collect ( ) ) ,
565
+ Thresh ( ref k, ref subs) => Thresh ( * k, ( 0 ..subs. len ( ) ) . map ( child_n) . collect ( ) ) ,
566
566
} ;
567
567
translated. push ( Arc :: new ( new_policy) ) ;
568
568
}
@@ -588,9 +588,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
588
588
. enumerate ( )
589
589
. map ( |( i, ( prob, _) ) | ( * prob, child_n ( i) ) )
590
590
. collect ( ) ) ) ,
591
- Threshold ( k, ref subs) => {
592
- Some ( Threshold ( * k, ( 0 ..subs. len ( ) ) . map ( child_n) . collect ( ) ) )
593
- }
591
+ Thresh ( k, ref subs) => Some ( Thresh ( * k, ( 0 ..subs. len ( ) ) . map ( child_n) . collect ( ) ) ) ,
594
592
_ => None ,
595
593
} ;
596
594
match new_policy {
@@ -615,7 +613,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
615
613
}
616
614
617
615
/// Gets the number of [TapLeaf](`TapTree::Leaf`)s considering exhaustive root-level [`Policy::Or`]
618
- /// and [`Policy::Threshold `] disjunctions for the `TapTree`.
616
+ /// and [`Policy::Thresh `] disjunctions for the `TapTree`.
619
617
#[ cfg( feature = "compiler" ) ]
620
618
fn num_tap_leaves ( & self ) -> usize {
621
619
use Policy :: * ;
@@ -626,7 +624,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
626
624
627
625
let num = match data. node {
628
626
Or ( subs) => ( 0 ..subs. len ( ) ) . map ( num_for_child_n) . sum ( ) ,
629
- Threshold ( k, subs) if * k == 1 => ( 0 ..subs. len ( ) ) . map ( num_for_child_n) . sum ( ) ,
627
+ Thresh ( k, subs) if * k == 1 => ( 0 ..subs. len ( ) ) . map ( num_for_child_n) . sum ( ) ,
630
628
_ => 1 ,
631
629
} ;
632
630
nums. push ( num) ;
@@ -709,7 +707,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
709
707
let iter = ( 0 ..subs. len ( ) ) . map ( info_for_child_n) ;
710
708
TimelockInfo :: combine_threshold ( 1 , iter)
711
709
}
712
- Threshold ( ref k, subs) => {
710
+ Thresh ( ref k, subs) => {
713
711
let iter = ( 0 ..subs. len ( ) ) . map ( info_for_child_n) ;
714
712
TimelockInfo :: combine_threshold ( * k, iter)
715
713
}
@@ -745,7 +743,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
745
743
return Err ( PolicyError :: NonBinaryArgOr ) ;
746
744
}
747
745
}
748
- Threshold ( k, ref subs) => {
746
+ Thresh ( k, ref subs) => {
749
747
if k == 0 || k > subs. len ( ) {
750
748
return Err ( PolicyError :: IncorrectThresh ) ;
751
749
}
@@ -789,7 +787,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
789
787
} ) ;
790
788
( all_safe, atleast_one_safe && all_non_mall)
791
789
}
792
- Threshold ( k, ref subs) => {
790
+ Thresh ( k, ref subs) => {
793
791
let ( safe_count, non_mall_count) = ( 0 ..subs. len ( ) ) . map ( acc_for_child_n) . fold (
794
792
( 0 , 0 ) ,
795
793
|( safe_count, non_mall_count) , ( safe, non_mall) | {
@@ -841,7 +839,7 @@ impl<Pk: MiniscriptKey> fmt::Debug for Policy<Pk> {
841
839
}
842
840
f. write_str ( ")" )
843
841
}
844
- Policy :: Threshold ( k, ref subs) => {
842
+ Policy :: Thresh ( k, ref subs) => {
845
843
write ! ( f, "thresh({}" , k) ?;
846
844
for sub in subs {
847
845
write ! ( f, ",{:?}" , sub) ?;
@@ -884,7 +882,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Policy<Pk> {
884
882
}
885
883
f. write_str ( ")" )
886
884
}
887
- Policy :: Threshold ( k, ref subs) => {
885
+ Policy :: Thresh ( k, ref subs) => {
888
886
write ! ( f, "thresh({}" , k) ?;
889
887
for sub in subs {
890
888
write ! ( f, ",{}" , sub) ?;
@@ -999,7 +997,7 @@ impl<Pk: FromStrKey> Policy<Pk> {
999
997
for arg in & top. args [ 1 ..] {
1000
998
subs. push ( Policy :: from_tree ( arg) ?) ;
1001
999
}
1002
- Ok ( Policy :: Threshold ( thresh as usize , subs. into_iter ( ) . map ( Arc :: new) . collect ( ) ) )
1000
+ Ok ( Policy :: Thresh ( thresh as usize , subs. into_iter ( ) . map ( Arc :: new) . collect ( ) ) )
1003
1001
}
1004
1002
_ => Err ( errstr ( top. name ) ) ,
1005
1003
}
@@ -1041,7 +1039,7 @@ fn with_huffman_tree<Pk: MiniscriptKey>(
1041
1039
Ok ( node)
1042
1040
}
1043
1041
1044
- /// Enumerates a [`Policy::Threshold (k, ..n..)`] into `n` different thresh's.
1042
+ /// Enumerates a [`Policy::Thresh (k, ..n..)`] into `n` different thresh's.
1045
1043
///
1046
1044
/// ## Strategy
1047
1045
///
@@ -1063,7 +1061,7 @@ fn generate_combination<Pk: MiniscriptKey>(
1063
1061
. enumerate ( )
1064
1062
. filter_map ( |( j, sub) | if j != i { Some ( Arc :: clone ( sub) ) } else { None } )
1065
1063
. collect ( ) ;
1066
- ret. push ( ( prob / policy_vec. len ( ) as f64 , Arc :: new ( Policy :: Threshold ( k, policies) ) ) ) ;
1064
+ ret. push ( ( prob / policy_vec. len ( ) as f64 , Arc :: new ( Policy :: Thresh ( k, policies) ) ) ) ;
1067
1065
}
1068
1066
ret
1069
1067
}
@@ -1077,7 +1075,7 @@ impl<'a, Pk: MiniscriptKey> TreeLike for &'a Policy<Pk> {
1077
1075
| Ripemd160 ( _) | Hash160 ( _) => Tree :: Nullary ,
1078
1076
And ( ref subs) => Tree :: Nary ( subs. iter ( ) . map ( Arc :: as_ref) . collect ( ) ) ,
1079
1077
Or ( ref v) => Tree :: Nary ( v. iter ( ) . map ( |( _, p) | p. as_ref ( ) ) . collect ( ) ) ,
1080
- Threshold ( _, ref subs) => Tree :: Nary ( subs. iter ( ) . map ( Arc :: as_ref) . collect ( ) ) ,
1078
+ Thresh ( _, ref subs) => Tree :: Nary ( subs. iter ( ) . map ( Arc :: as_ref) . collect ( ) ) ,
1081
1079
}
1082
1080
}
1083
1081
}
@@ -1091,7 +1089,7 @@ impl<Pk: MiniscriptKey> TreeLike for Arc<Policy<Pk>> {
1091
1089
| Ripemd160 ( _) | Hash160 ( _) => Tree :: Nullary ,
1092
1090
And ( ref subs) => Tree :: Nary ( subs. iter ( ) . map ( Arc :: clone) . collect ( ) ) ,
1093
1091
Or ( ref v) => Tree :: Nary ( v. iter ( ) . map ( |( _, p) | Arc :: clone ( p) ) . collect ( ) ) ,
1094
- Threshold ( _, ref subs) => Tree :: Nary ( subs. iter ( ) . map ( Arc :: clone) . collect ( ) ) ,
1092
+ Thresh ( _, ref subs) => Tree :: Nary ( subs. iter ( ) . map ( Arc :: clone) . collect ( ) ) ,
1095
1093
}
1096
1094
}
1097
1095
}
@@ -1137,10 +1135,7 @@ mod compiler_tests {
1137
1135
. map ( |sub_pol| {
1138
1136
(
1139
1137
0.25 ,
1140
- Arc :: new ( Policy :: Threshold (
1141
- 2 ,
1142
- sub_pol. into_iter ( ) . map ( |p| Arc :: new ( p) ) . collect ( ) ,
1143
- ) ) ,
1138
+ Arc :: new ( Policy :: Thresh ( 2 , sub_pol. into_iter ( ) . map ( |p| Arc :: new ( p) ) . collect ( ) ) ) ,
1144
1139
)
1145
1140
} )
1146
1141
. collect :: < Vec < _ > > ( ) ;
0 commit comments