@@ -19,7 +19,8 @@ use crate::plan::AssetProvider;
19
19
use crate :: prelude:: * ;
20
20
use crate :: util:: witness_size;
21
21
use crate :: {
22
- AbsLockTime , Miniscript , MiniscriptKey , RelLockTime , ScriptContext , Terminal , ToPublicKey ,
22
+ AbsLockTime , Miniscript , MiniscriptKey , RelLockTime , ScriptContext , Terminal , Threshold ,
23
+ ToPublicKey ,
23
24
} ;
24
25
25
26
/// Type alias for 32 byte Preimage.
@@ -930,8 +931,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
930
931
931
932
// produce a non-malleable satisafaction for thesh frag
932
933
fn thresh < Ctx , Sat , F > (
933
- k : usize ,
934
- subs : & [ Arc < Miniscript < Pk , Ctx > > ] ,
934
+ thresh : & Threshold < Arc < Miniscript < Pk , Ctx > > , 0 > ,
935
935
stfr : & Sat ,
936
936
root_has_sig : bool ,
937
937
leaf_hash : & TapLeafHash ,
@@ -945,7 +945,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
945
945
Satisfaction < Placeholder < Pk > > ,
946
946
) -> Satisfaction < Placeholder < Pk > > ,
947
947
{
948
- let mut sats = subs
948
+ let mut sats = thresh
949
949
. iter ( )
950
950
. map ( |s| {
951
951
Self :: satisfy_helper (
@@ -959,7 +959,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
959
959
} )
960
960
. collect :: < Vec < _ > > ( ) ;
961
961
// Start with the to-return stack set to all dissatisfactions
962
- let mut ret_stack = subs
962
+ let mut ret_stack = thresh
963
963
. iter ( )
964
964
. map ( |s| {
965
965
Self :: dissatisfy_helper (
@@ -976,7 +976,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
976
976
// Sort everything by (sat cost - dissat cost), except that
977
977
// satisfactions without signatures beat satisfactions with
978
978
// signatures
979
- let mut sat_indices = ( 0 ..subs . len ( ) ) . collect :: < Vec < _ > > ( ) ;
979
+ let mut sat_indices = ( 0 ..thresh . n ( ) ) . collect :: < Vec < _ > > ( ) ;
980
980
sat_indices. sort_by_key ( |& i| {
981
981
let stack_weight = match ( & sats[ i] . stack , & ret_stack[ i] . stack ) {
982
982
( & Witness :: Unavailable , _) | ( & Witness :: Impossible , _) => i64:: MAX ,
@@ -995,7 +995,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
995
995
( is_impossible, sats[ i] . has_sig , stack_weight)
996
996
} ) ;
997
997
998
- for i in 0 ..k {
998
+ for i in 0 ..thresh . k ( ) {
999
999
mem:: swap ( & mut ret_stack[ sat_indices[ i] ] , & mut sats[ sat_indices[ i] ] ) ;
1000
1000
}
1001
1001
@@ -1004,8 +1004,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
1004
1004
// then the threshold branch is impossible to satisfy
1005
1005
// For example, the fragment thresh(2, hash, 0, 0, 0)
1006
1006
// is has an impossible witness
1007
- assert ! ( k > 0 ) ;
1008
- if sats[ sat_indices[ k - 1 ] ] . stack == Witness :: Impossible {
1007
+ if sats[ sat_indices[ thresh. k ( ) - 1 ] ] . stack == Witness :: Impossible {
1009
1008
Satisfaction {
1010
1009
stack : Witness :: Impossible ,
1011
1010
// If the witness is impossible, we don't care about the
@@ -1024,9 +1023,8 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
1024
1023
// For example, the fragment thresh(2, hash, hash, 0, 0)
1025
1024
// is uniquely satisfyiable because there is no satisfaction
1026
1025
// for the 0 fragment
1027
- else if k < sat_indices. len ( )
1028
- && !sats[ sat_indices[ k] ] . has_sig
1029
- && sats[ sat_indices[ k] ] . stack != Witness :: Impossible
1026
+ else if !sats[ sat_indices[ thresh. k ( ) ] ] . has_sig
1027
+ && sats[ sat_indices[ thresh. k ( ) ] ] . stack != Witness :: Impossible
1030
1028
{
1031
1029
// All arguments should be `d`, so dissatisfactions have no
1032
1030
// signatures; and in this branch we assume too many weak
@@ -1062,8 +1060,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
1062
1060
1063
1061
// produce a possily malleable satisafaction for thesh frag
1064
1062
fn thresh_mall < Ctx , Sat , F > (
1065
- k : usize ,
1066
- subs : & [ Arc < Miniscript < Pk , Ctx > > ] ,
1063
+ thresh : & Threshold < Arc < Miniscript < Pk , Ctx > > , 0 > ,
1067
1064
stfr : & Sat ,
1068
1065
root_has_sig : bool ,
1069
1066
leaf_hash : & TapLeafHash ,
@@ -1077,7 +1074,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
1077
1074
Satisfaction < Placeholder < Pk > > ,
1078
1075
) -> Satisfaction < Placeholder < Pk > > ,
1079
1076
{
1080
- let mut sats = subs
1077
+ let mut sats = thresh
1081
1078
. iter ( )
1082
1079
. map ( |s| {
1083
1080
Self :: satisfy_helper (
@@ -1091,7 +1088,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
1091
1088
} )
1092
1089
. collect :: < Vec < _ > > ( ) ;
1093
1090
// Start with the to-return stack set to all dissatisfactions
1094
- let mut ret_stack = subs
1091
+ let mut ret_stack = thresh
1095
1092
. iter ( )
1096
1093
. map ( |s| {
1097
1094
Self :: dissatisfy_helper (
@@ -1108,7 +1105,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
1108
1105
// Sort everything by (sat cost - dissat cost), except that
1109
1106
// satisfactions without signatures beat satisfactions with
1110
1107
// signatures
1111
- let mut sat_indices = ( 0 ..subs . len ( ) ) . collect :: < Vec < _ > > ( ) ;
1108
+ let mut sat_indices = ( 0 ..thresh . n ( ) ) . collect :: < Vec < _ > > ( ) ;
1112
1109
sat_indices. sort_by_key ( |& i| {
1113
1110
// For malleable satifactions, directly choose smallest weights
1114
1111
match ( & sats[ i] . stack , & ret_stack[ i] . stack ) {
@@ -1122,7 +1119,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
1122
1119
} ) ;
1123
1120
1124
1121
// swap the satisfactions
1125
- for i in 0 ..k {
1122
+ for i in 0 ..thresh . k ( ) {
1126
1123
mem:: swap ( & mut ret_stack[ sat_indices[ i] ] , & mut sats[ sat_indices[ i] ] ) ;
1127
1124
}
1128
1125
@@ -1236,8 +1233,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
1236
1233
Satisfaction < Placeholder < Pk > > ,
1237
1234
) -> Satisfaction < Placeholder < Pk > > ,
1238
1235
G : FnMut (
1239
- usize ,
1240
- & [ Arc < Miniscript < Pk , Ctx > > ] ,
1236
+ & Threshold < Arc < Miniscript < Pk , Ctx > > , 0 > ,
1241
1237
& Sat ,
1242
1238
bool ,
1243
1239
& TapLeafHash ,
@@ -1496,7 +1492,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
1496
1492
)
1497
1493
}
1498
1494
Terminal :: Thresh ( ref thresh) => {
1499
- thresh_fn ( thresh. k ( ) , thresh . data ( ) , stfr, root_has_sig, leaf_hash, min_fn)
1495
+ thresh_fn ( thresh, stfr, root_has_sig, leaf_hash, min_fn)
1500
1496
}
1501
1497
Terminal :: Multi ( ref thresh) => {
1502
1498
// Collect all available signatures
@@ -1606,8 +1602,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfaction<Placeholder<Pk>> {
1606
1602
Satisfaction < Placeholder < Pk > > ,
1607
1603
) -> Satisfaction < Placeholder < Pk > > ,
1608
1604
G : FnMut (
1609
- usize ,
1610
- & [ Arc < Miniscript < Pk , Ctx > > ] ,
1605
+ & Threshold < Arc < Miniscript < Pk , Ctx > > , 0 > ,
1611
1606
& Sat ,
1612
1607
bool ,
1613
1608
& TapLeafHash ,
0 commit comments