@@ -22,6 +22,7 @@ use std::convert::From;
22
22
use std:: marker:: PhantomData ;
23
23
use std:: { cmp, error, f64, fmt, mem} ;
24
24
25
+ use miniscript:: context:: SigType ;
25
26
use miniscript:: limits:: MAX_PUBKEYS_PER_MULTISIG ;
26
27
use miniscript:: types:: { self , ErrorKind , ExtData , Property , Type } ;
27
28
use miniscript:: ScriptContext ;
@@ -994,18 +995,25 @@ where
994
995
} )
995
996
. collect ( ) ;
996
997
997
- if key_vec. len ( ) == subs. len ( ) && subs. len ( ) <= MAX_PUBKEYS_PER_MULTISIG {
998
- insert_wrap ! ( AstElemExt :: terminal( Terminal :: Multi ( k, key_vec) ) ) ;
999
- }
1000
- // Not a threshold, it's always more optimal to translate it to and()s as we save the
1001
- // resulting threshold check (N EQUAL) in any case.
1002
- else if k == subs. len ( ) {
1003
- let mut policy = subs. first ( ) . expect ( "No sub policy in thresh() ?" ) . clone ( ) ;
1004
- for sub in & subs[ 1 ..] {
1005
- policy = Concrete :: And ( vec ! [ sub. clone( ) , policy] ) ;
998
+ match Ctx :: sig_type ( ) {
999
+ SigType :: Schnorr => {
1000
+ insert_wrap ! ( AstElemExt :: terminal( Terminal :: MultiA ( k, key_vec) ) )
1001
+ }
1002
+ _ => {
1003
+ if key_vec. len ( ) == subs. len ( ) && subs. len ( ) <= MAX_PUBKEYS_PER_MULTISIG {
1004
+ insert_wrap ! ( AstElemExt :: terminal( Terminal :: Multi ( k, key_vec) ) ) ;
1005
+ }
1006
+ // Not a threshold, it's always more optimal to translate it to and()s as we save the
1007
+ // resulting threshold check (N EQUAL) in any case.
1008
+ else if k == subs. len ( ) {
1009
+ let mut policy = subs. first ( ) . expect ( "No sub policy in thresh() ?" ) . clone ( ) ;
1010
+ for sub in & subs[ 1 ..] {
1011
+ policy = Concrete :: And ( vec ! [ sub. clone( ) , policy] ) ;
1012
+ }
1013
+
1014
+ ret = best_compilations ( policy_cache, & policy, sat_prob, dissat_prob) ?;
1015
+ }
1006
1016
}
1007
-
1008
- ret = best_compilations ( policy_cache, & policy, sat_prob, dissat_prob) ?;
1009
1017
}
1010
1018
1011
1019
// FIXME: Should we also optimize thresh(1, subs) ?
@@ -1168,7 +1176,7 @@ mod tests {
1168
1176
1169
1177
use miniscript:: { satisfy, Legacy , Segwitv0 } ;
1170
1178
use policy:: Liftable ;
1171
- use script_num_size;
1179
+ use { script_num_size, Tap } ;
1172
1180
1173
1181
type SPolicy = Concrete < String > ;
1174
1182
type BPolicy = Concrete < bitcoin:: PublicKey > ;
@@ -1554,6 +1562,17 @@ mod tests {
1554
1562
) )
1555
1563
) ;
1556
1564
}
1565
+
1566
+ #[ test]
1567
+ fn compile_tr_thresh ( ) {
1568
+ for k in 1 ..4 {
1569
+ let small_thresh: Concrete < String > =
1570
+ policy_str ! ( "{}" , & format!( "thresh({},pk(B),pk(C),pk(D))" , k) ) ;
1571
+ let small_thresh_ms: Miniscript < String , Tap > = small_thresh. compile ( ) . unwrap ( ) ;
1572
+ let small_thresh_ms_expected: Miniscript < String , Tap > = ms_str ! ( "multi_a({},B,C,D)" , k) ;
1573
+ assert_eq ! ( small_thresh_ms, small_thresh_ms_expected) ;
1574
+ }
1575
+ }
1557
1576
}
1558
1577
1559
1578
#[ cfg( all( test, feature = "unstable" ) ) ]
0 commit comments