cargo-clippy cleanups
This commit is contained in:
parent
1dbd1c28dc
commit
1e47019221
|
@ -264,7 +264,7 @@ pub struct RevBlockIter<'tree> {
|
||||||
///
|
///
|
||||||
/// So to handle reorgs, you create a `RevStaleBlockIter` starting from the last
|
/// So to handle reorgs, you create a `RevStaleBlockIter` starting from the last
|
||||||
/// known block, and play it until it runs out, rewinding every block except for
|
/// known block, and play it until it runs out, rewinding every block except for
|
||||||
/// the last one. Since the UtxoSet `rewind` function sets its `last_hash()` to
|
/// the last one. Since the `UtxoSet` `rewind` function sets its `last_hash()` to
|
||||||
/// the prevblockhash of the rewinded block (which will be on the main chain at
|
/// the prevblockhash of the rewinded block (which will be on the main chain at
|
||||||
/// the end of the iteration), you can then sync it up same as if you were doing
|
/// the end of the iteration), you can then sync it up same as if you were doing
|
||||||
/// a plain old fast-forward.
|
/// a plain old fast-forward.
|
||||||
|
@ -327,7 +327,7 @@ impl<'tree> Iterator for RevStaleBlockIter<'tree> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function emulates the GetCompact(SetCompact(n)) in the satoshi code,
|
/// This function emulates the `GetCompact(SetCompact(n))` in the satoshi code,
|
||||||
/// which drops the precision to something that can be encoded precisely in
|
/// which drops the precision to something that can be encoded precisely in
|
||||||
/// the nBits block header field. Savour the perversity. This is in Bitcoin
|
/// the nBits block header field. Savour the perversity. This is in Bitcoin
|
||||||
/// consensus code. What. Gaah!
|
/// consensus code. What. Gaah!
|
||||||
|
|
|
@ -220,7 +220,7 @@ pub fn read_scriptint(v: &[u8]) -> Result<i64, Error> {
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is like "read_scriptint then map 0 to false and everything
|
/// This is like "`read_scriptint` then map 0 to false and everything
|
||||||
/// else as true", except that the overflow rules don't apply.
|
/// else as true", except that the overflow rules don't apply.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn read_scriptbool(v: &[u8]) -> bool {
|
pub fn read_scriptbool(v: &[u8]) -> bool {
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
//! This module provides the structures and functions needed to support transactions.
|
//! This module provides the structures and functions needed to support transactions.
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
|
use byteorder::{LittleEndian, WriteBytesExt};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use serde;
|
use serde;
|
||||||
|
|
|
@ -137,6 +137,7 @@ macro_rules! impl_array_newtype {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "clippy", allow(expl_impl_clone_on_copy))] // we don't define the `struct`, we have to explicitly impl
|
||||||
impl Clone for $thing {
|
impl Clone for $thing {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone(&self) -> $thing {
|
fn clone(&self) -> $thing {
|
||||||
|
|
|
@ -30,6 +30,10 @@
|
||||||
// Experimental features we need
|
// Experimental features we need
|
||||||
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
|
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
|
||||||
|
|
||||||
|
// Clippy whitelist
|
||||||
|
#![cfg_attr(feature = "clippy", allow(needless_range_loop))] // suggests making a big mess of array newtypes
|
||||||
|
#![cfg_attr(feature = "clippy", allow(extend_from_slice))] // `extend_from_slice` only available since 1.6
|
||||||
|
|
||||||
// Coding conventions
|
// Coding conventions
|
||||||
#![deny(non_upper_case_globals)]
|
#![deny(non_upper_case_globals)]
|
||||||
#![deny(non_camel_case_types)]
|
#![deny(non_camel_case_types)]
|
||||||
|
|
|
@ -79,8 +79,8 @@ pub enum SocketResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
/// A Network message payload. Proper documentation is available on the Bitcoin
|
/// A Network message payload. Proper documentation is available on at
|
||||||
/// wiki https://en.bitcoin.it/wiki/Protocol_specification
|
/// [Bitcoin Wiki: Protocol Specification](https://en.bitcoin.it/wiki/Protocol_specification)
|
||||||
pub enum NetworkMessage {
|
pub enum NetworkMessage {
|
||||||
/// `version`
|
/// `version`
|
||||||
Version(message_network::VersionMessage),
|
Version(message_network::VersionMessage),
|
||||||
|
|
|
@ -171,11 +171,11 @@ pub fn tweak_keys(secp: &Secp256k1, keys: &[PublicKey], contract: &[u8]) -> Resu
|
||||||
let mut ret = Vec::with_capacity(keys.len());
|
let mut ret = Vec::with_capacity(keys.len());
|
||||||
for mut key in keys.iter().cloned() {
|
for mut key in keys.iter().cloned() {
|
||||||
let mut hmac_raw = [0; 32];
|
let mut hmac_raw = [0; 32];
|
||||||
let mut hmac = hmac::Hmac::new(sha2::Sha256::new(), &key.serialize_vec(&secp, true));
|
let mut hmac = hmac::Hmac::new(sha2::Sha256::new(), &key.serialize_vec(secp, true));
|
||||||
hmac.input(contract);
|
hmac.input(contract);
|
||||||
hmac.raw_result(&mut hmac_raw);
|
hmac.raw_result(&mut hmac_raw);
|
||||||
let hmac_sk = try!(SecretKey::from_slice(&secp, &hmac_raw).map_err(Error::BadTweak));
|
let hmac_sk = try!(SecretKey::from_slice(secp, &hmac_raw).map_err(Error::BadTweak));
|
||||||
try!(key.add_exp_assign(&secp, &hmac_sk).map_err(Error::Secp));
|
try!(key.add_exp_assign(secp, &hmac_sk).map_err(Error::Secp));
|
||||||
ret.push(key);
|
ret.push(key);
|
||||||
}
|
}
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
|
@ -184,10 +184,10 @@ pub fn tweak_keys(secp: &Secp256k1, keys: &[PublicKey], contract: &[u8]) -> Resu
|
||||||
/// Compute a tweak from some given data for the given public key
|
/// Compute a tweak from some given data for the given public key
|
||||||
pub fn compute_tweak(secp: &Secp256k1, pk: &PublicKey, contract: &[u8]) -> Result<SecretKey, Error> {
|
pub fn compute_tweak(secp: &Secp256k1, pk: &PublicKey, contract: &[u8]) -> Result<SecretKey, Error> {
|
||||||
let mut hmac_raw = [0; 32];
|
let mut hmac_raw = [0; 32];
|
||||||
let mut hmac = hmac::Hmac::new(sha2::Sha256::new(), &pk.serialize_vec(&secp, true));
|
let mut hmac = hmac::Hmac::new(sha2::Sha256::new(), &pk.serialize_vec(secp, true));
|
||||||
hmac.input(contract);
|
hmac.input(contract);
|
||||||
hmac.raw_result(&mut hmac_raw);
|
hmac.raw_result(&mut hmac_raw);
|
||||||
SecretKey::from_slice(&secp, &hmac_raw).map_err(Error::BadTweak)
|
SecretKey::from_slice(secp, &hmac_raw).map_err(Error::BadTweak)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tweak a secret key using some arbitrary data (calls `compute_tweak` internally)
|
/// Tweak a secret key using some arbitrary data (calls `compute_tweak` internally)
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub fn hex_bytes(s: &str) -> Result<Vec<u8>, Error> {
|
||||||
// Check that there was no remainder
|
// Check that there was no remainder
|
||||||
match iter.remainder() {
|
match iter.remainder() {
|
||||||
Some(_) => Err(Error::Detail(
|
Some(_) => Err(Error::Detail(
|
||||||
format!("hexstring of odd length"),
|
"hexstring of odd length".to_owned(),
|
||||||
Box::new(Error::ParseFailed)
|
Box::new(Error::ParseFailed)
|
||||||
)),
|
)),
|
||||||
None => Ok(v)
|
None => Ok(v)
|
||||||
|
|
|
@ -111,7 +111,7 @@ impl error::Error for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prepend the detail of an IoResult's error with some text to get poor man's backtracing
|
/// Prepend the detail of an `IoResult`'s error with some text to get poor man's backtracing
|
||||||
pub fn propagate_err<T>(s: String, res: Result<T, Error>) -> Result<T, Error> {
|
pub fn propagate_err<T>(s: String, res: Result<T, Error>) -> Result<T, Error> {
|
||||||
res.map_err(|err| Error::Detail(s, Box::new(err)))
|
res.map_err(|err| Error::Detail(s, Box::new(err)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -375,27 +375,21 @@ impl<K: Copy + BitArray, V: Debug> Debug for PatriciaTree<K, V> {
|
||||||
}
|
}
|
||||||
try!(writeln!(f, ": {:?}", tree.data));
|
try!(writeln!(f, ": {:?}", tree.data));
|
||||||
// left gets no indentation
|
// left gets no indentation
|
||||||
match tree.child_l {
|
if let Some(ref t) = tree.child_l {
|
||||||
Some(ref t) => {
|
|
||||||
for _ in 0..(depth + tree.skip_len as usize) {
|
for _ in 0..(depth + tree.skip_len as usize) {
|
||||||
try!(write!(f, "-"));
|
try!(write!(f, "-"));
|
||||||
}
|
}
|
||||||
try!(write!(f, "0"));
|
try!(write!(f, "0"));
|
||||||
try!(recurse(&**t, f, depth + tree.skip_len as usize + 1));
|
try!(recurse(&**t, f, depth + tree.skip_len as usize + 1));
|
||||||
}
|
}
|
||||||
None => { }
|
|
||||||
}
|
|
||||||
// right one gets indentation
|
// right one gets indentation
|
||||||
match tree.child_r {
|
if let Some(ref t) = tree.child_r {
|
||||||
Some(ref t) => {
|
|
||||||
for _ in 0..(depth + tree.skip_len as usize) {
|
for _ in 0..(depth + tree.skip_len as usize) {
|
||||||
try!(write!(f, "_"));
|
try!(write!(f, "_"));
|
||||||
}
|
}
|
||||||
try!(write!(f, "1"));
|
try!(write!(f, "1"));
|
||||||
try!(recurse(&**t, f, depth + tree.skip_len as usize + 1));
|
try!(recurse(&**t, f, depth + tree.skip_len as usize + 1));
|
||||||
}
|
}
|
||||||
None => { }
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
recurse(self, f, 0)
|
recurse(self, f, 0)
|
||||||
|
|
Loading…
Reference in New Issue