Skip to content

Commit

Permalink
Merge #847: Add a method to psbt to compute find sighash type
Browse files Browse the repository at this point in the history
fb04cab Add a method to psbt to compute find sighash type (Rishabh Singhal)

Pull request description:

  Fixes #838: Add a utility method to psbt to compute find sighash
  type of a given input.

  For now, I have changed my previous implementation as discussed in #838 to functional style code as suggested by @Kixunil.

ACKs for top commit:
  apoelstra:
    ACK fb04cab
  Kixunil:
    ACK fb04cab

Tree-SHA512: 86184649e7a309348cb217347b82bf39c9997ae259fe7881322038a88bd04deab927bede1dd71d17496bac420353a3fd07e7d191ff4671a07754c02a38dd1319
  • Loading branch information
apoelstra committed Feb 27, 2022
2 parents 45fe276 + fb04cab commit c7ff483
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/util/psbt/map/input.rs
Expand Up @@ -191,6 +191,28 @@ impl PsbtSigHashType {
}

impl Input {
/// Obtains the [`EcdsaSigHashType`] for this input if one is specified.
/// If no sighash type is specified, returns ['EcdsaSigHashType::All']
///
/// Errors:
/// If the sighash type is not a standard ecdsa sighash type
pub fn ecdsa_hash_ty(&self) -> Result<EcdsaSigHashType, NonStandardSigHashType> {
self.sighash_type
.map(|sighash_type| sighash_type.ecdsa_hash_ty())
.unwrap_or(Ok(EcdsaSigHashType::All))
}

/// Obtains the [`SchnorrSigHashType`] for this input if one is specified.
/// If no sighash type is specified, returns ['SchnorrSigHashType::Default']
///
/// Errors:
/// If the sighash type is an invalid schnorr sighash type
pub fn schnorr_hash_ty(&self) -> Result<SchnorrSigHashType, sighash::Error> {
self.sighash_type
.map(|sighash_type| sighash_type.schnorr_hash_ty())
.unwrap_or(Ok(SchnorrSigHashType::Default))
}

pub(super) fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
let raw::Pair {
key: raw_key,
Expand Down

0 comments on commit c7ff483

Please sign in to comment.