From 46c4164d67c81e28faffba822220ca29d79a0fbf Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Tue, 22 Feb 2022 18:49:17 +0000 Subject: [PATCH] Improve SigHashTypeParseError field In preparation for constructing an error outside of this module improve the `SigHashTypeParseError` by doing: - Make the field public - Rename the field to `unrecognized` to better describe its usage --- src/blockdata/transaction.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 62d15e63..f625d7e1 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -758,7 +758,7 @@ impl str::FromStr for EcdsaSigHashType { "SIGHASH_ALL|SIGHASH_ANYONECANPAY" => Ok(EcdsaSigHashType::AllPlusAnyoneCanPay), "SIGHASH_NONE|SIGHASH_ANYONECANPAY" => Ok(EcdsaSigHashType::NonePlusAnyoneCanPay), "SIGHASH_SINGLE|SIGHASH_ANYONECANPAY" => Ok(EcdsaSigHashType::SinglePlusAnyoneCanPay), - _ => Err(SigHashTypeParseError { string: s.to_owned() }), + _ => Err(SigHashTypeParseError{ unrecognized: s.to_owned() }), } } } @@ -840,12 +840,13 @@ impl From for u32 { /// This is currently returned for unrecognized sighash strings. #[derive(Debug, Clone)] pub struct SigHashTypeParseError { - string: String, + /// The unrecognized string we attempted to parse. + pub unrecognized: String, } impl fmt::Display for SigHashTypeParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "can't recognize SIGHASH string '{}'", self.string) + write!(f, "Unrecognized SIGHASH string '{}'", self.unrecognized) } } @@ -1154,7 +1155,7 @@ mod tests { "SigHash_NONE", ]; for s in sht_mistakes { - assert_eq!(EcdsaSigHashType::from_str(s).unwrap_err().to_string(), format!("can't recognize SIGHASH string '{}'", s)); + assert_eq!(EcdsaSigHashType::from_str(s).unwrap_err().to_string(), format!("Unrecognized SIGHASH string '{}'", s)); } }