From fb04cabe1dcc4ecbe5a1f712e1081d372de0d311 Mon Sep 17 00:00:00 2001 From: Rishabh Singhal Date: Tue, 22 Feb 2022 23:10:24 +0530 Subject: [PATCH] Add a method to psbt to compute find sighash type Fixes #838: Add a utility method to psbt to compute find sighash type of a given input. --- src/util/psbt/map/input.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/util/psbt/map/input.rs b/src/util/psbt/map/input.rs index 34fd18dd7c..64e731d49b 100644 --- a/src/util/psbt/map/input.rs +++ b/src/util/psbt/map/input.rs @@ -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 { + 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 { + 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,