diff --git a/src/descriptor/mod.rs b/src/descriptor/mod.rs index 845fd1d2f..2b02dc165 100644 --- a/src/descriptor/mod.rs +++ b/src/descriptor/mod.rs @@ -316,6 +316,27 @@ impl Descriptor { Descriptor::Tr(ref tr) => tr.sanity_check(), } } + + /// Computes an upper bound on the weight of a satisfying witness to the + /// transaction. + /// + /// Assumes all ec-signatures are 73 bytes, including push opcode and + /// sighash suffix. Includes the weight of the VarInts encoding the + /// scriptSig and witness stack length. + /// + /// # Errors + /// When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)). + pub fn max_satisfaction_weight(&self) -> Result { + let weight = match *self { + Descriptor::Bare(ref bare) => bare.max_satisfaction_weight()?, + Descriptor::Pkh(ref pkh) => pkh.max_satisfaction_weight(), + Descriptor::Wpkh(ref wpkh) => wpkh.max_satisfaction_weight(), + Descriptor::Wsh(ref wsh) => wsh.max_satisfaction_weight()?, + Descriptor::Sh(ref sh) => sh.max_satisfaction_weight()?, + Descriptor::Tr(ref tr) => tr.max_satisfaction_weight()?, + }; + Ok(weight) + } } impl Descriptor { @@ -447,27 +468,6 @@ impl Descriptor { txin.script_sig = script_sig; Ok(()) } - - /// Computes an upper bound on the weight of a satisfying witness to the - /// transaction. - /// - /// Assumes all ec-signatures are 73 bytes, including push opcode and - /// sighash suffix. Includes the weight of the VarInts encoding the - /// scriptSig and witness stack length. - /// - /// # Errors - /// When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)). - pub fn max_satisfaction_weight(&self) -> Result { - let weight = match *self { - Descriptor::Bare(ref bare) => bare.max_satisfaction_weight()?, - Descriptor::Pkh(ref pkh) => pkh.max_satisfaction_weight(), - Descriptor::Wpkh(ref wpkh) => wpkh.max_satisfaction_weight(), - Descriptor::Wsh(ref wsh) => wsh.max_satisfaction_weight()?, - Descriptor::Sh(ref sh) => sh.max_satisfaction_weight()?, - Descriptor::Tr(ref tr) => tr.max_satisfaction_weight()?, - }; - Ok(weight) - } } impl TranslatePk for Descriptor