-
Notifications
You must be signed in to change notification settings - Fork 831
Fixed a bunch of clippy lints, added clippy.toml #686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
msrv = "1.29" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,8 +56,8 @@ impl OutPoint { | |
#[inline] | ||
pub fn new(txid: Txid, vout: u32) -> OutPoint { | ||
OutPoint { | ||
txid: txid, | ||
vout: vout, | ||
txid, | ||
vout, | ||
} | ||
} | ||
|
||
|
@@ -153,7 +153,7 @@ fn parse_vout(s: &str) -> Result<u32, ParseOutPointError> { | |
return Err(ParseOutPointError::VoutNotCanonical); | ||
} | ||
} | ||
Ok(s.parse().map_err(ParseOutPointError::Vout)?) | ||
s.parse().map_err(ParseOutPointError::Vout) | ||
} | ||
|
||
impl ::core::str::FromStr for OutPoint { | ||
|
@@ -634,9 +634,9 @@ impl Decodable for Transaction { | |
Err(encode::Error::ParseFailed("witness flag set but no witnesses present")) | ||
} else { | ||
Ok(Transaction { | ||
version: version, | ||
input: input, | ||
output: output, | ||
version, | ||
input, | ||
output, | ||
lock_time: Decodable::consensus_decode(d)?, | ||
}) | ||
} | ||
|
@@ -649,8 +649,8 @@ impl Decodable for Transaction { | |
// non-segwit | ||
} else { | ||
Ok(Transaction { | ||
version |
||
input: input, | ||
version, | ||
input, | ||
output: Decodable::consensus_decode(&mut d)?, | ||
lock_time: Decodable::consensus_decode(d)?, | ||
}) | ||
|
@@ -715,17 +715,17 @@ impl fmt::Display for EcdsaSigHashType { | |
} | ||
|
||
impl str::FromStr for EcdsaSigHashType { | ||
type Err = String; | ||
type Err = SigHashTypeParseError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s.as_ref() { | ||
match s { | ||
"SIGHASH_ALL" => Ok(EcdsaSigHashType::All), | ||
"SIGHASH_NONE" => Ok(EcdsaSigHashType::None), | ||
"SIGHASH_SINGLE" => Ok(EcdsaSigHashType::Single), | ||
"SIGHASH_ALL|SIGHASH_ANYONECANPAY" => Ok(EcdsaSigHashType::AllPlusAnyoneCanPay), | ||
"SIGHASH_NONE|SIGHASH_ANYONECANPAY" => Ok(EcdsaSigHashType::NonePlusAnyoneCanPay), | ||
"SIGHASH_SINGLE|SIGHASH_ANYONECANPAY" => Ok(EcdsaSigHashType::SinglePlusAnyoneCanPay), | ||
_ => Err("can't recognize SIGHASH string".to_string()) | ||
_ => Err(SigHashTypeParseError { string: s.to_owned() }), | ||
} | ||
} | ||
} | ||
|
@@ -798,6 +798,24 @@ impl From<EcdsaSigHashType> for u32 { | |
} | ||
} | ||
|
||
/// Error returned when parsing `SigHashType` fails. | ||
/// | ||
/// This is currently returned for unrecognized sighash strings. | ||
#[derive(Debug, Clone)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH, I'm not really convinced errors should commit to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there's In this specific case I'm not even sure about |
||
pub struct SigHashTypeParseError { | ||
string: String, | ||
} | ||
|
||
impl fmt::Display for SigHashTypeParseError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "can't recognize SIGHASH string '{}'", self.string) | ||
} | ||
} | ||
|
||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
#[cfg(feature = "std")] | ||
impl ::std::error::Error for SigHashTypeParseError {} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::{OutPoint, ParseOutPointError, Transaction, TxIn, NonStandardSigHashType}; | ||
|
@@ -1116,7 +1134,7 @@ mod tests { | |
"SigHash_NONE", | ||
]; | ||
for s in sht_mistakes { | ||
assert_eq!(EcdsaSigHashType::from_str(s).unwrap_err(), "can't recognize SIGHASH string"); | ||
assert_eq!(EcdsaSigHashType::from_str(s).unwrap_err().to_string(), format!("can't recognize SIGHASH string '{}'", s)); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,12 +49,12 @@ impl CommandString { | |
/// - `&'static str` | ||
/// - `String` | ||
/// | ||
/// Returns an empty error if and only if the string is | ||
/// Returns an error if and only if the string is | ||
/// larger than 12 characters in length. | ||
pub fn try_from<S: Into<Cow<'static, str>>>(s: S) -> Result<CommandString, ()> { | ||
pub fn try_from<S: Into<Cow<'static, str>>>(s: S) -> Result<CommandString, CommandStringError> { | ||
let cow = s.into(); | ||
if cow.as_ref().len() > 12 { | ||
Err(()) | ||
if cow.len() > 12 { | ||
Err(CommandStringError { cow }) | ||
} else { | ||
Ok(CommandString(cow)) | ||
} | ||
|
@@ -82,7 +82,7 @@ impl Encodable for CommandString { | |
let mut rawbytes = [0u8; 12]; | ||
let strbytes = self.0.as_bytes(); | ||
debug_assert!(strbytes.len() <= 12); | ||
rawbytes[..strbytes.len()].clone_from_slice(&strbytes[..]); | ||
rawbytes[..strbytes.len()].copy_from_slice(strbytes); | ||
rawbytes.consensus_encode(s) | ||
} | ||
} | ||
|
@@ -100,6 +100,24 @@ impl Decodable for CommandString { | |
} | ||
} | ||
|
||
/// Error returned when a command string is invalid. | ||
/// | ||
/// This is currently returned for command strings longer than 12. | ||
#[derive(Clone, Debug)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ibid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I still think |
||
pub struct CommandStringError { | ||
cow: Cow<'static, str>, | ||
} | ||
|
||
impl fmt::Display for CommandStringError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "the command string '{}' has length {} which is larger than 12", self.cow, self.cow.len()) | ||
} | ||
} | ||
|
||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
#[cfg(feature = "std")] | ||
impl ::std::error::Error for CommandStringError { } | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
/// A Network message | ||
pub struct RawNetworkMessage { | ||
|
@@ -395,8 +413,8 @@ impl Decodable for RawNetworkMessage { | |
} | ||
}; | ||
Ok(RawNetworkMessage { | ||
magic: magic, | ||
payload: payload | ||
magic, | ||
payload, | ||
}) | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.