Skip to content

Commit

Permalink
Merge #436: Remove ToPublicKey bound for max_satisfaction_weight
Browse files Browse the repository at this point in the history
edf7587 Remove ToPublicKey bound for max_satisfaction_weight (eunoia_1729)

Pull request description:

  Resolves: #432

ACKs for top commit:
  SarcasticNastik:
    ACK edf7587
  apoelstra:
    ACK edf7587
  sanket1729:
    ACK edf7587

Tree-SHA512: 57ca26abf31d5022ded5f7ca82f652605794a1c9f0d6b483158018865f4815d8298621ecd0e90af59bfebb70095a039f83b2873b0d245864b2fece480c648c65
  • Loading branch information
sanket1729 committed Jun 28, 2022
2 parents f6dc945 + edf7587 commit d589fe9
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,27 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
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<usize, Error> {
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<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
Expand Down Expand Up @@ -447,27 +468,6 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
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<usize, Error> {
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<P, Q> TranslatePk<P, Q> for Descriptor<P>
Expand Down

0 comments on commit d589fe9

Please sign in to comment.