@@ -82,15 +82,45 @@ impl<Pk: MiniscriptKey> Wsh<Pk> {
82
82
Ok ( ( ) )
83
83
}
84
84
85
+ /// Computes an upper bound on the difference in weight between a
86
+ /// non-satisfied `TxIn` (with empty `scriptSig` and `witness` fields) and a
87
+ /// satisfied `TxIn`.
88
+ ///
89
+ /// Assumes all ECDSA signatures are 73 bytes, including push opcode and
90
+ /// sighash suffix.
91
+ ///
92
+ /// # Errors
93
+ /// When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)).
94
+ pub fn max_weight_to_satisfy ( & self ) -> Result < usize , Error > {
95
+ let ( redeem_script_size, max_sat_elems, max_sat_size) = match self . inner {
96
+ WshInner :: SortedMulti ( ref smv) => (
97
+ smv. script_size ( ) ,
98
+ smv. max_satisfaction_witness_elements ( ) ,
99
+ smv. max_satisfaction_size ( ) ,
100
+ ) ,
101
+ WshInner :: Ms ( ref ms) => (
102
+ ms. script_size ( ) ,
103
+ ms. max_satisfaction_witness_elements ( ) ?,
104
+ ms. max_satisfaction_size ( ) ?,
105
+ ) ,
106
+ } ;
107
+ // stack size varint difference between non-satisfied (0) and satisfied
108
+ // `max_sat_elems` is inclusive of the "witness script" (redeem script)
109
+ let stack_varint_diff = varint_len ( max_sat_elems) - varint_len ( 0 ) ;
110
+
111
+ Ok ( stack_varint_diff + varint_len ( redeem_script_size) + redeem_script_size + max_sat_size)
112
+ }
113
+
85
114
/// Computes an upper bound on the weight of a satisfying witness to the
86
115
/// transaction.
87
116
///
88
- /// Assumes all ec- signatures are 73 bytes, including push opcode and
117
+ /// Assumes all ECDSA signatures are 73 bytes, including push opcode and
89
118
/// sighash suffix. Includes the weight of the VarInts encoding the
90
119
/// scriptSig and witness stack length.
91
120
///
92
121
/// # Errors
93
122
/// When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)).
123
+ #[ deprecated( note = "use max_weight_to_satisfy instead" ) ]
94
124
pub fn max_satisfaction_weight ( & self ) -> Result < usize , Error > {
95
125
let ( script_size, max_sat_elems, max_sat_size) = match self . inner {
96
126
WshInner :: SortedMulti ( ref smv) => (
@@ -325,10 +355,24 @@ impl<Pk: MiniscriptKey> Wpkh<Pk> {
325
355
}
326
356
}
327
357
358
+ /// Computes an upper bound on the difference in weight between a
359
+ /// non-satisfied `TxIn` (with empty `scriptSig` and `witness` fields) and a
360
+ /// satisfied `TxIn`.
361
+ ///
362
+ /// Assumes all ECDSA signatures are 73 bytes, including push opcode and
363
+ /// sighash suffix.
364
+ pub fn max_weight_to_satisfy ( & self ) -> usize {
365
+ // stack items: <varint(sig+sigHash)> <sig(71)+sigHash(1)> <varint(pubkey)> <pubkey>
366
+ let stack_items_size = 73 + Segwitv0 :: pk_len ( & self . pk ) ;
367
+ // stackLen varint difference between non-satisfied (0) and satisfied
368
+ let stack_varint_diff = varint_len ( 2 ) - varint_len ( 0 ) ;
369
+ stack_varint_diff + stack_items_size
370
+ }
371
+
328
372
/// Computes an upper bound on the weight of a satisfying witness to the
329
373
/// transaction.
330
374
///
331
- /// Assumes all ec- signatures are 73 bytes, including push opcode and
375
+ /// Assumes all ECDSA signatures are 73 bytes, including push opcode and
332
376
/// sighash suffix. Includes the weight of the VarInts encoding the
333
377
/// scriptSig and witness stack length.
334
378
pub fn max_satisfaction_weight ( & self ) -> usize {
0 commit comments