Skip to content

Commit 315444d

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#847: Add a method to psbt to compute find sighash type
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
2 parents d74012c + a93f5ea commit 315444d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/util/psbt/map/input.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,28 @@ impl PsbtSigHashType {
191191
}
192192

193193
impl Input {
194+
/// Obtains the [`EcdsaSigHashType`] for this input if one is specified.
195+
/// If no sighash type is specified, returns ['EcdsaSigHashType::All']
196+
///
197+
/// Errors:
198+
/// If the sighash type is not a standard ecdsa sighash type
199+
pub fn ecdsa_hash_ty(&self) -> Result<EcdsaSigHashType, NonStandardSigHashType> {
200+
self.sighash_type
201+
.map(|sighash_type| sighash_type.ecdsa_hash_ty())
202+
.unwrap_or(Ok(EcdsaSigHashType::All))
203+
}
204+
205+
/// Obtains the [`SchnorrSigHashType`] for this input if one is specified.
206+
/// If no sighash type is specified, returns ['SchnorrSigHashType::Default']
207+
///
208+
/// Errors:
209+
/// If the sighash type is an invalid schnorr sighash type
210+
pub fn schnorr_hash_ty(&self) -> Result<SchnorrSigHashType, sighash::Error> {
211+
self.sighash_type
212+
.map(|sighash_type| sighash_type.schnorr_hash_ty())
213+
.unwrap_or(Ok(SchnorrSigHashType::Default))
214+
}
215+
194216
pub(super) fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
195217
let raw::Pair {
196218
key: raw_key,

0 commit comments

Comments
 (0)