Skip to content

Commit

Permalink
Add a method to psbt to compute find sighash type
Browse files Browse the repository at this point in the history
Fixes #838: Add a utility method to psbt to compute find sighash
type of a given input.
  • Loading branch information
Rishabh Singhal committed Feb 25, 2022
1 parent 2c1077e commit fb04cab
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/util/psbt/map/input.rs
Original file line number Diff line number Diff line change
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 fb04cab

Please sign in to comment.