From daf0eacf3df3e9da609da704eee592156cb593b5 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Thu, 6 Jan 2022 11:58:08 +0100 Subject: [PATCH] Improve NonStandardSigHashType --- src/blockdata/transaction.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index e7eafabe..5e92eea6 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -666,11 +666,11 @@ impl Decodable for Transaction { /// This type is consensus valid but an input including it would prevent the transaction from /// being relayed on today's Bitcoin network. #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct NonStandardSigHashType; +pub struct NonStandardSigHashType(pub u32); impl fmt::Display for NonStandardSigHashType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Non standard sighash type") + write!(f, "Non standard sighash type {}", self.0) } } @@ -789,7 +789,7 @@ impl EcdsaSigHashType { 0x81 => Ok(EcdsaSigHashType::AllPlusAnyoneCanPay), 0x82 => Ok(EcdsaSigHashType::NonePlusAnyoneCanPay), 0x83 => Ok(EcdsaSigHashType::SinglePlusAnyoneCanPay), - _ => Err(NonStandardSigHashType) + non_standard => Err(NonStandardSigHashType(non_standard)) } } @@ -1151,7 +1151,7 @@ mod tests { assert_eq!(EcdsaSigHashType::from_u32(nonstandard_hashtype), EcdsaSigHashType::All); assert_eq!(EcdsaSigHashType::from_u32_consensus(nonstandard_hashtype), EcdsaSigHashType::All); // But it's policy-invalid to use it! - assert_eq!(EcdsaSigHashType::from_u32_standard(nonstandard_hashtype), Err(NonStandardSigHashType)); + assert_eq!(EcdsaSigHashType::from_u32_standard(nonstandard_hashtype), Err(NonStandardSigHashType(0x04))); } // These test vectors were stolen from libbtc, which is Copyright 2014 Jonas Schnelli MIT