@@ -11,7 +11,7 @@ use core::convert::TryFrom;
11
11
use core:: fmt;
12
12
13
13
use bitcoin:: script:: PushBytes ;
14
- use bitcoin:: { script, Address , Network , ScriptBuf } ;
14
+ use bitcoin:: { script, Address , Network , ScriptBuf , Weight } ;
15
15
16
16
use super :: checksum:: verify_checksum;
17
17
use super :: { SortedMultiVec , Wpkh , Wsh } ;
@@ -185,7 +185,7 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
185
185
///
186
186
/// # Errors
187
187
/// When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)).
188
- pub fn max_weight_to_satisfy ( & self ) -> Result < usize , Error > {
188
+ pub fn max_weight_to_satisfy ( & self ) -> Result < Weight , Error > {
189
189
let ( scriptsig_size, witness_size) = match self . inner {
190
190
// add weighted script sig, len byte stays the same
191
191
ShInner :: Wsh ( ref wsh) => {
@@ -198,7 +198,7 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
198
198
let ss = smv. script_size ( ) ;
199
199
let ps = push_opcode_size ( ss) ;
200
200
let scriptsig_size = ps + ss + smv. max_satisfaction_size ( ) ;
201
- ( scriptsig_size, 0 )
201
+ ( scriptsig_size, Weight :: ZERO )
202
202
}
203
203
// add weighted script sig, len byte stays the same
204
204
ShInner :: Wpkh ( ref wpkh) => {
@@ -211,14 +211,18 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
211
211
let ss = ms. script_size ( ) ;
212
212
let ps = push_opcode_size ( ss) ;
213
213
let scriptsig_size = ps + ss + ms. max_satisfaction_size ( ) ?;
214
- ( scriptsig_size, 0 )
214
+ ( scriptsig_size, Weight :: ZERO )
215
215
}
216
216
} ;
217
217
218
218
// scriptSigLen varint difference between non-satisfied (0) and satisfied
219
219
let scriptsig_varint_diff = varint_len ( scriptsig_size) - varint_len ( 0 ) ;
220
220
221
- Ok ( 4 * ( scriptsig_varint_diff + scriptsig_size) + witness_size)
221
+ let wu = Weight :: from_vb ( ( scriptsig_varint_diff + scriptsig_size) as u64 ) ;
222
+ match wu {
223
+ Some ( w) => Ok ( w + witness_size) ,
224
+ None => Err ( Error :: CouldNotSatisfy ) ,
225
+ }
222
226
}
223
227
224
228
/// Computes an upper bound on the weight of a satisfying witness to the
0 commit comments