@@ -11,7 +11,7 @@ use core::convert::TryFrom;
1111use core:: fmt;
1212
1313use bitcoin:: script:: PushBytes ;
14- use bitcoin:: { script, Address , Network , ScriptBuf } ;
14+ use bitcoin:: { script, Address , Network , ScriptBuf , Weight } ;
1515
1616use super :: checksum:: verify_checksum;
1717use super :: { SortedMultiVec , Wpkh , Wsh } ;
@@ -185,7 +185,7 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
185185 ///
186186 /// # Errors
187187 /// 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 > {
189189 let ( scriptsig_size, witness_size) = match self . inner {
190190 // add weighted script sig, len byte stays the same
191191 ShInner :: Wsh ( ref wsh) => {
@@ -198,7 +198,7 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
198198 let ss = smv. script_size ( ) ;
199199 let ps = push_opcode_size ( ss) ;
200200 let scriptsig_size = ps + ss + smv. max_satisfaction_size ( ) ;
201- ( scriptsig_size, 0 )
201+ ( scriptsig_size, Weight :: ZERO )
202202 }
203203 // add weighted script sig, len byte stays the same
204204 ShInner :: Wpkh ( ref wpkh) => {
@@ -211,14 +211,18 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
211211 let ss = ms. script_size ( ) ;
212212 let ps = push_opcode_size ( ss) ;
213213 let scriptsig_size = ps + ss + ms. max_satisfaction_size ( ) ?;
214- ( scriptsig_size, 0 )
214+ ( scriptsig_size, Weight :: ZERO )
215215 }
216216 } ;
217217
218218 // scriptSigLen varint difference between non-satisfied (0) and satisfied
219219 let scriptsig_varint_diff = varint_len ( scriptsig_size) - varint_len ( 0 ) ;
220220
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+ }
222226 }
223227
224228 /// Computes an upper bound on the weight of a satisfying witness to the
0 commit comments