Merge pull request #100 from ethcore/clippy
project workspace and linting using clippy
This commit is contained in:
commit
7291333654
|
@ -1,21 +1,18 @@
|
|||
[root]
|
||||
name = "pbtc"
|
||||
name = "verification"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"app_dirs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chain 0.1.0",
|
||||
"clap 2.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"db 0.1.0",
|
||||
"env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"import 0.1.0",
|
||||
"keys 0.1.0",
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"message 0.1.0",
|
||||
"miner 0.1.0",
|
||||
"p2p 0.1.0",
|
||||
"ethcore-devtools 1.3.0",
|
||||
"linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"primitives 0.1.0",
|
||||
"script 0.1.0",
|
||||
"sync 0.1.0",
|
||||
"verification 0.1.0",
|
||||
"serialization 0.1.0",
|
||||
"test-data 0.1.0",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -470,6 +467,26 @@ dependencies = [
|
|||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pbtc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"app_dirs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chain 0.1.0",
|
||||
"clap 2.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"db 0.1.0",
|
||||
"env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"import 0.1.0",
|
||||
"keys 0.1.0",
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"message 0.1.0",
|
||||
"miner 0.1.0",
|
||||
"p2p 0.1.0",
|
||||
"script 0.1.0",
|
||||
"sync 0.1.0",
|
||||
"verification 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "primitives"
|
||||
version = "0.1.0"
|
||||
|
@ -714,23 +731,6 @@ name = "vec_map"
|
|||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "verification"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chain 0.1.0",
|
||||
"db 0.1.0",
|
||||
"ethcore-devtools 1.3.0",
|
||||
"linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"primitives 0.1.0",
|
||||
"script 0.1.0",
|
||||
"serialization 0.1.0",
|
||||
"test-data 0.1.0",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
|
|
|
@ -24,3 +24,5 @@ import = { path = "import" }
|
|||
[[bin]]
|
||||
path = "pbtc/main.rs"
|
||||
name = "pbtc"
|
||||
|
||||
[workspace]
|
||||
|
|
|
@ -12,8 +12,8 @@ pub struct DHash160 {
|
|||
ripemd: Ripemd160,
|
||||
}
|
||||
|
||||
impl DHash160 {
|
||||
pub fn new() -> Self {
|
||||
impl Default for DHash160 {
|
||||
fn default() -> Self {
|
||||
DHash160 {
|
||||
sha256: Sha256::new(),
|
||||
ripemd: Ripemd160::new(),
|
||||
|
@ -21,6 +21,12 @@ impl DHash160 {
|
|||
}
|
||||
}
|
||||
|
||||
impl DHash160 {
|
||||
pub fn new() -> Self {
|
||||
DHash160::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Digest for DHash160 {
|
||||
fn input(&mut self, d: &[u8]) {
|
||||
self.sha256.input(d)
|
||||
|
@ -51,14 +57,20 @@ pub struct DHash256 {
|
|||
hasher: Sha256,
|
||||
}
|
||||
|
||||
impl DHash256 {
|
||||
pub fn new() -> Self {
|
||||
impl Default for DHash256 {
|
||||
fn default() -> Self {
|
||||
DHash256 {
|
||||
hasher: Sha256::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DHash256 {
|
||||
pub fn new() -> Self {
|
||||
DHash256::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Digest for DHash256 {
|
||||
fn input(&mut self, d: &[u8]) {
|
||||
self.hasher.input(d)
|
||||
|
|
|
@ -10,4 +10,3 @@ bitcrypto = { path = "../crypto" }
|
|||
chain = { path = "../chain" }
|
||||
primitives = { path = "../primitives" }
|
||||
serialization = { path = "../serialization" }
|
||||
|
||||
|
|
|
@ -33,6 +33,10 @@ impl Command {
|
|||
self.0.len() - trailing_zeros
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_zero()
|
||||
}
|
||||
|
||||
fn as_string(&self) -> String {
|
||||
String::from_utf8_lossy(&self.0[..self.len()]).to_ascii_lowercase()
|
||||
}
|
||||
|
|
|
@ -65,16 +65,16 @@ impl Payload for Version {
|
|||
impl Version {
|
||||
pub fn version(&self) -> u32 {
|
||||
match *self {
|
||||
Version::V0(ref s) => s.version,
|
||||
Version::V106(ref s, _) => s.version,
|
||||
Version::V0(ref s) |
|
||||
Version::V106(ref s, _) |
|
||||
Version::V70001(ref s, _, _) => s.version,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn services(&self) -> Services {
|
||||
match *self {
|
||||
Version::V0(ref s) => s.services,
|
||||
Version::V106(ref s, _) => s.services,
|
||||
Version::V0(ref s) |
|
||||
Version::V106(ref s, _) |
|
||||
Version::V70001(ref s, _, _) => s.services,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ impl Context {
|
|||
let peers = context.node_table.read().nodes_with_services(&Services::default(), max);
|
||||
let addresses = peers.into_iter()
|
||||
.map(|peer| peer.address())
|
||||
.filter(|address| !used_addresses.contains(&address))
|
||||
.filter(|address| !used_addresses.contains(address))
|
||||
.take(needed)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -396,12 +396,12 @@ impl P2P {
|
|||
}
|
||||
|
||||
pub fn run(&self) -> Result<(), Box<error::Error>> {
|
||||
for peer in self.config.peers.iter() {
|
||||
for peer in &self.config.peers {
|
||||
self.connect::<NormalSessionFactory>(*peer);
|
||||
}
|
||||
|
||||
let resolver = try!(DnsResolver::system_config(&self.event_loop_handle));
|
||||
for seed in self.config.seeds.iter() {
|
||||
for seed in &self.config.seeds {
|
||||
self.connect_to_seednode(&resolver, seed);
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ impl Ord for Node {
|
|||
let self_port = self_addr.port();
|
||||
let other_port = other_addr.port();
|
||||
if self_port == other_port {
|
||||
self_addr.ip().cmp(&other_addr.ip())
|
||||
self_addr.ip().cmp(other_addr.ip())
|
||||
}
|
||||
else {
|
||||
self_port.cmp(&other_port)
|
||||
|
@ -143,7 +143,7 @@ impl Ord for Node {
|
|||
let self_port = self_addr.port();
|
||||
let other_port = other_addr.port();
|
||||
if self_port == other_port {
|
||||
self_addr.ip().cmp(&other_addr.ip())
|
||||
self_addr.ip().cmp(other_addr.ip())
|
||||
}
|
||||
else {
|
||||
self_port.cmp(&other_port)
|
||||
|
@ -175,14 +175,13 @@ pub struct NodeTable<T = RealTime> where T: Time {
|
|||
impl NodeTable {
|
||||
/// Opens a file loads node_table from it.
|
||||
pub fn from_file<P>(path: P) -> Result<Self, io::Error> where P: AsRef<path::Path> {
|
||||
let res = fs::OpenOptions::new()
|
||||
fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.read(true)
|
||||
// without opening for write, mac os returns os error 22
|
||||
.write(true)
|
||||
.open(path)
|
||||
.and_then(Self::load);
|
||||
res
|
||||
.and_then(Self::load)
|
||||
}
|
||||
|
||||
/// Saves node table to file
|
||||
|
|
|
@ -27,7 +27,7 @@ pub fn import(cfg: Config, matches: &ArgMatches) -> Result<(), String> {
|
|||
Err(Error::OutOfOrderBlock) => {
|
||||
skipped += 1;
|
||||
},
|
||||
Err(_) => return Err(format!("Cannot append block")),
|
||||
Err(_) => return Err("Cannot append block".into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,9 +26,8 @@ pub const APP_INFO: AppInfo = AppInfo { name: "pbtc", author: "Parity" };
|
|||
|
||||
fn main() {
|
||||
env_logger::init().unwrap();
|
||||
match run() {
|
||||
Err(err) => println!("{}", err),
|
||||
Ok(_) => (),
|
||||
if let Err(err) = run() {
|
||||
println!("{}", err);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
13
pbtc/util.rs
13
pbtc/util.rs
|
@ -6,14 +6,11 @@ use {db, APP_INFO};
|
|||
use config::Config;
|
||||
|
||||
pub fn open_db(cfg: &Config) -> Arc<db::Store> {
|
||||
match cfg.use_disk_database {
|
||||
true => {
|
||||
let db_path = app_dir(AppDataType::UserData, &APP_INFO, "db").expect("Failed to get app dir");
|
||||
Arc::new(db::Storage::new(db_path).expect("Failed to open database"))
|
||||
},
|
||||
false => {
|
||||
Arc::new(db::TestStorage::default())
|
||||
}
|
||||
if cfg.use_disk_database {
|
||||
let db_path = app_dir(AppDataType::UserData, &APP_INFO, "db").expect("Failed to get app dir");
|
||||
Arc::new(db::Storage::new(db_path).expect("Failed to open database"))
|
||||
} else {
|
||||
Arc::new(db::TestStorage::default())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -201,7 +201,7 @@ impl Serializable for Bytes {
|
|||
fn serialize(&self, stream: &mut Stream) {
|
||||
stream
|
||||
.append(&CompactInteger::from(self.len()))
|
||||
.append_slice(&self);
|
||||
.append_slice(self);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -5,9 +5,10 @@ pub fn deserialize<R, T>(buffer: R) -> Result<T, Error> where R: io::Read, T: De
|
|||
let mut reader = Reader::from_read(buffer);
|
||||
let result = try!(reader.read());
|
||||
|
||||
match reader.is_finished() {
|
||||
false => Err(Error::UnreadData),
|
||||
true => Ok(result),
|
||||
if reader.is_finished() {
|
||||
Ok(result)
|
||||
} else {
|
||||
Err(Error::UnreadData)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,6 +114,7 @@ impl<R> Reader<R> where R: io::Read {
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature="cargo-clippy", allow(wrong_self_convention))]
|
||||
pub fn is_finished(&mut self) -> bool {
|
||||
if self.peeked.is_some() {
|
||||
return false;
|
||||
|
@ -139,9 +141,10 @@ impl<R, T> Iterator for ReadIterator<R, T> where R: io::Read, T: Deserializable
|
|||
type Item = Result<T, Error>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.reader.is_finished() {
|
||||
true => None,
|
||||
false => Some(self.reader.read())
|
||||
if self.reader.is_finished() {
|
||||
None
|
||||
} else {
|
||||
Some(self.reader.read())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
# NOTE!
|
||||
# this script requires nightly version of rustc
|
||||
# clippy plugin needs to be compiled with the same nigtly version as currently set one
|
||||
# tested with clippy 0.0.98
|
||||
|
||||
# temporary workaround for cargo clippy issue #1330
|
||||
# https://github.com/Manishearth/rust-clippy/issues/1330
|
||||
|
||||
# first, let's enter any directory in a workspace with target kind `lib`
|
||||
# https://github.com/Manishearth/rust-clippy/blob/6a73c8f8e3f513f6a16c6876be3d326633dbc78d/src/main.rs#L186
|
||||
cd primitives
|
||||
|
||||
# now let's run clippy
|
||||
# clippy does not support multiple packages, so let's run them one after another
|
||||
cargo clippy -p bitcrypto
|
||||
cargo clippy -p chain
|
||||
cargo clippy -p db
|
||||
cargo clippy -p ethcore-devtools
|
||||
cargo clippy -p import
|
||||
cargo clippy -p keys
|
||||
cargo clippy -p message
|
||||
cargo clippy -p miner
|
||||
cargo clippy -p p2p
|
||||
cargo clippy -p primitives
|
||||
cargo clippy -p script
|
||||
cargo clippy -p serialization
|
||||
cargo clippy -p sync
|
||||
cargo clippy -p verification
|
||||
|
|
@ -1,4 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
cargo graph --build-shape box --build-line-style dashed > graph.dot
|
||||
dot -Tpng > graph.png graph.dot
|
||||
# Cargo graph does not work with cargo worspaces #33
|
||||
# https://github.com/kbknapp/cargo-graph/issues/33
|
||||
# so first we need to patch Cargo.toml and remove workspace
|
||||
patch -R Cargo.toml tools/workspace.diff
|
||||
|
||||
# Now let's rebuild Cargo.lock by telling cargo to update local package
|
||||
cargo update -p pbtc
|
||||
|
||||
# And draw dependencies graph using cargo graph
|
||||
cargo graph --build-shape box --build-line-style dashed > tools/graph.dot
|
||||
dot -Tpng > tools/graph.png tools/graph.dot
|
||||
|
||||
# Finally let's bring back old Cargo.toml file
|
||||
patch Cargo.toml tools/workspace.diff
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
cargo test\
|
||||
-p bitcrypto\
|
||||
-p chain\
|
||||
-p db\
|
||||
-p ethcore-devtools\
|
||||
-p chain\
|
||||
-p bitcrypto\
|
||||
-p import\
|
||||
-p keys\
|
||||
-p message\
|
||||
-p miner\
|
||||
-p pbtc\
|
||||
-p p2p\
|
||||
-p primitives\
|
||||
-p script\
|
||||
-p serialization\
|
||||
-p sync\
|
||||
-p import\
|
||||
-p pbtc\
|
||||
-p verification
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
diff --git Cargo.toml Cargo.toml
|
||||
index fca51d5..6a16dd6 100644
|
||||
--- Cargo.toml
|
||||
+++ Cargo.toml
|
||||
@@ -24,3 +24,5 @@ import = { path = "import" }
|
||||
[[bin]]
|
||||
path = "pbtc/main.rs"
|
||||
name = "pbtc"
|
||||
+
|
||||
+[workspace]
|
Loading…
Reference in New Issue