Fixing all obvious warnings

This commit is contained in:
Tomusdrw 2016-01-19 11:10:38 +01:00
parent db6e6a3e58
commit f169951d4e
12 changed files with 37 additions and 40 deletions

View File

@ -66,7 +66,7 @@ impl AccountDiff {
post.storage.get(&k).cloned().unwrap_or(H256::new()) post.storage.get(&k).cloned().unwrap_or(H256::new())
))).collect(), ))).collect(),
}; };
if r.balance.is_same() && r.nonce.is_same() && r.code.is_same() && r.storage.len() == 0 { if r.balance.is_same() && r.nonce.is_same() && r.code.is_same() && r.storage.is_empty() {
None None
} else { } else {
Some(r) Some(r)

View File

@ -1,3 +1,5 @@
#![allow(ptr_arg)] // Because of &LastHashes -> &Vec<_>
use common::*; use common::*;
use engine::*; use engine::*;
use state::*; use state::*;
@ -169,7 +171,7 @@ impl<'x, 'y> OpenBlock<'x, 'y> {
timestamp: self.block.header.timestamp, timestamp: self.block.header.timestamp,
difficulty: self.block.header.difficulty.clone(), difficulty: self.block.header.difficulty.clone(),
last_hashes: self.last_hashes.clone(), // TODO: should be a reference. last_hashes: self.last_hashes.clone(), // TODO: should be a reference.
gas_used: self.block.archive.last().map(|t| t.receipt.gas_used).unwrap_or(U256::from(0)), gas_used: self.block.archive.last().map_or(U256::zero(), |t| t.receipt.gas_used),
gas_limit: self.block.header.gas_limit.clone(), gas_limit: self.block.header.gas_limit.clone(),
} }
} }
@ -200,7 +202,7 @@ impl<'x, 'y> OpenBlock<'x, 'y> {
s.block.header.state_root = s.block.state.root().clone(); s.block.header.state_root = s.block.state.root().clone();
s.block.header.receipts_root = ordered_trie_root(s.block.archive.iter().map(|ref e| e.receipt.rlp_bytes()).collect()); s.block.header.receipts_root = ordered_trie_root(s.block.archive.iter().map(|ref e| e.receipt.rlp_bytes()).collect());
s.block.header.log_bloom = s.block.archive.iter().fold(LogBloom::zero(), |mut b, e| {b |= &e.receipt.log_bloom; b}); s.block.header.log_bloom = s.block.archive.iter().fold(LogBloom::zero(), |mut b, e| {b |= &e.receipt.log_bloom; b});
s.block.header.gas_used = s.block.archive.last().map(|t| t.receipt.gas_used).unwrap_or(U256::from(0)); s.block.header.gas_used = s.block.archive.last().map_or(U256::zero(), |t| t.receipt.gas_used);
s.block.header.note_dirty(); s.block.header.note_dirty();
ClosedBlock::new(s, uncle_bytes) ClosedBlock::new(s, uncle_bytes)
@ -251,7 +253,7 @@ impl SealedBlock {
let mut block_rlp = RlpStream::new_list(3); let mut block_rlp = RlpStream::new_list(3);
self.block.header.stream_rlp(&mut block_rlp, Seal::With); self.block.header.stream_rlp(&mut block_rlp, Seal::With);
block_rlp.append_list(self.block.archive.len()); block_rlp.append_list(self.block.archive.len());
for e in self.block.archive.iter() { e.transaction.rlp_append(&mut block_rlp); } for e in &self.block.archive { e.transaction.rlp_append(&mut block_rlp); }
block_rlp.append_raw(&self.uncle_bytes, 1); block_rlp.append_raw(&self.uncle_bytes, 1);
block_rlp.out() block_rlp.out()
} }

View File

@ -490,9 +490,8 @@ impl BlockChain {
K: ExtrasSliceConvertable + Eq + Hash + Clone { K: ExtrasSliceConvertable + Eq + Hash + Clone {
{ {
let read = cache.read().unwrap(); let read = cache.read().unwrap();
match read.get(hash) { if let Some(v) = read.get(hash) {
Some(v) => return Some(v.clone()), return Some(v.clone());
None => ()
} }
} }

View File

@ -31,13 +31,13 @@ impl Ethash {
} }
fn u64_param(&self, name: &str) -> u64 { fn u64_param(&self, name: &str) -> u64 {
*self.u64_params.write().unwrap().entry(name.to_string()).or_insert_with(|| *self.u64_params.write().unwrap().entry(name.to_owned()).or_insert_with(||
self.spec().engine_params.get(name).map(|a| decode(&a)).unwrap_or(0u64)) self.spec().engine_params.get(name).map_or(0u64, |a| decode(&a)))
} }
fn u256_param(&self, name: &str) -> U256 { fn u256_param(&self, name: &str) -> U256 {
*self.u256_params.write().unwrap().entry(name.to_string()).or_insert_with(|| *self.u256_params.write().unwrap().entry(name.to_owned()).or_insert_with(||
self.spec().engine_params.get(name).map(|a| decode(&a)).unwrap_or(x!(0))) self.spec().engine_params.get(name).map_or(x!(0), |a| decode(&a)))
} }
} }
@ -83,7 +83,7 @@ impl Engine for Ethash {
/// Apply the block reward on finalisation of the block. /// Apply the block reward on finalisation of the block.
/// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current). /// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current).
fn on_close_block(&self, block: &mut Block) { fn on_close_block(&self, block: &mut Block) {
let reward = self.spec().engine_params.get("blockReward").map(|a| decode(&a)).unwrap_or(U256::from(0u64)); let reward = self.spec().engine_params.get("blockReward").map_or(U256::from(0u64), |a| decode(&a));
let fields = block.fields(); let fields = block.fields();
// Bestow block reward // Bestow block reward

View File

@ -65,10 +65,11 @@ impl Factory {
fn jit() -> Box<Evm> { fn jit() -> Box<Evm> {
unimplemented!() unimplemented!()
} }
}
impl Default for Factory {
/// Returns jitvm factory /// Returns jitvm factory
#[cfg(feature = "jit")] #[cfg(feature = "jit")]
pub fn default() -> Factory { fn default() -> Factory {
Factory { Factory {
evm: VMType::Jit evm: VMType::Jit
} }
@ -76,7 +77,7 @@ impl Factory {
/// Returns native rust evm factory /// Returns native rust evm factory
#[cfg(not(feature = "jit"))] #[cfg(not(feature = "jit"))]
pub fn default() -> Factory { fn default() -> Factory {
Factory { Factory {
evm: VMType::Interpreter evm: VMType::Interpreter
} }

View File

@ -229,6 +229,7 @@ struct CodeReader<'a> {
code: &'a Bytes code: &'a Bytes
} }
#[allow(len_without_is_empty)]
impl<'a> CodeReader<'a> { impl<'a> CodeReader<'a> {
/// Get `no_of_bytes` from code and convert to U256. Move PC /// Get `no_of_bytes` from code and convert to U256. Move PC
fn read(&mut self, no_of_bytes: usize) -> U256 { fn read(&mut self, no_of_bytes: usize) -> U256 {
@ -331,6 +332,7 @@ impl evm::Evm for Interpreter {
} }
impl Interpreter { impl Interpreter {
#[allow(cyclomatic_complexity)]
fn get_gas_cost_mem(&self, fn get_gas_cost_mem(&self,
ext: &evm::Ext, ext: &evm::Ext,
instruction: Instruction, instruction: Instruction,

View File

@ -3,6 +3,8 @@
#![feature(wrapping)] #![feature(wrapping)]
//#![feature(plugin)] //#![feature(plugin)]
//#![plugin(interpolate_idents)] //#![plugin(interpolate_idents)]
#![allow(match_bool, needless_range_loop, match_ref_pats)]
//! Ethcore's ethereum implementation //! Ethcore's ethereum implementation
//! //!
//! ### Rust version //! ### Rust version
@ -86,7 +88,6 @@ extern crate num_cpus;
#[cfg(feature = "jit" )] #[cfg(feature = "jit" )]
extern crate evmjit; extern crate evmjit;
#[macro_use] #[macro_use]
#[allow(match_bool)]
extern crate ethcore_util as util; extern crate ethcore_util as util;
pub mod common; pub mod common;

View File

@ -200,7 +200,7 @@ impl FromJson for Spec {
Spec { Spec {
name: json.find("name").map(|j| j.as_string().unwrap()).unwrap_or("unknown").to_owned(), name: json.find("name").map_or("unknown", |j| j.as_string().unwrap()).to_owned(),
engine_name: json["engineName"].as_string().unwrap().to_owned(), engine_name: json["engineName"].as_string().unwrap().to_owned(),
engine_params: json_to_rlp_map(&json["params"]), engine_params: json_to_rlp_map(&json["params"]),
builtins: builtins, builtins: builtins,

View File

@ -268,6 +268,7 @@ impl ChainSync {
Ok(()) Ok(())
} }
#[allow(cyclomatic_complexity)]
/// Called by peer once it has new block headers during sync /// Called by peer once it has new block headers during sync
fn on_peer_block_headers(&mut self, io: &mut SyncIo, peer_id: PeerId, r: &UntrustedRlp) -> Result<(), PacketDecodeError> { fn on_peer_block_headers(&mut self, io: &mut SyncIo, peer_id: PeerId, r: &UntrustedRlp) -> Result<(), PacketDecodeError> {
self.reset_peer_asking(peer_id, PeerAsking::BlockHeaders); self.reset_peer_asking(peer_id, PeerAsking::BlockHeaders);
@ -865,12 +866,9 @@ impl ChainSync {
let mut added = 0usize; let mut added = 0usize;
let mut data = Bytes::new(); let mut data = Bytes::new();
for i in 0..count { for i in 0..count {
match io.chain().block_body(&try!(r.val_at::<H256>(i))) { if let Some(mut hdr) = io.chain().block_body(&try!(r.val_at::<H256>(i))) {
Some(mut hdr) => { data.append(&mut hdr);
data.append(&mut hdr); added += 1;
added += 1;
}
None => {}
} }
} }
let mut rlp = RlpStream::new_list(added); let mut rlp = RlpStream::new_list(added);
@ -892,12 +890,9 @@ impl ChainSync {
let mut added = 0usize; let mut added = 0usize;
let mut data = Bytes::new(); let mut data = Bytes::new();
for i in 0..count { for i in 0..count {
match io.chain().state_data(&try!(r.val_at::<H256>(i))) { if let Some(mut hdr) = io.chain().state_data(&try!(r.val_at::<H256>(i))) {
Some(mut hdr) => { data.append(&mut hdr);
data.append(&mut hdr); added += 1;
added += 1;
}
None => {}
} }
} }
let mut rlp = RlpStream::new_list(added); let mut rlp = RlpStream::new_list(added);
@ -918,12 +913,9 @@ impl ChainSync {
let mut added = 0usize; let mut added = 0usize;
let mut data = Bytes::new(); let mut data = Bytes::new();
for i in 0..count { for i in 0..count {
match io.chain().block_receipts(&try!(r.val_at::<H256>(i))) { if let Some(mut hdr) = io.chain().block_receipts(&try!(r.val_at::<H256>(i))) {
Some(mut hdr) => { data.append(&mut hdr);
data.append(&mut hdr); added += 1;
added += 1;
}
None => {}
} }
} }
let mut rlp = RlpStream::new_list(added); let mut rlp = RlpStream::new_list(added);

View File

@ -14,7 +14,7 @@ pub trait SyncIo {
/// Send a packet to a peer. /// Send a packet to a peer.
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError>; fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError>;
/// Get the blockchain /// Get the blockchain
fn chain<'s>(&'s mut self) -> &'s mut BlockChainClient; fn chain(&mut self) -> &mut BlockChainClient;
/// Returns peer client identifier string /// Returns peer client identifier string
fn peer_info(&self, peer_id: PeerId) -> String { fn peer_info(&self, peer_id: PeerId) -> String {
peer_id.to_string() peer_id.to_string()
@ -50,7 +50,7 @@ impl<'s, 'h, 'op> SyncIo for NetSyncIo<'s, 'h, 'op> {
self.network.send(peer_id, packet_id, data) self.network.send(peer_id, packet_id, data)
} }
fn chain<'a>(&'a mut self) -> &'a mut BlockChainClient { fn chain(&mut self) -> &mut BlockChainClient {
self.chain self.chain
} }

View File

@ -29,7 +29,7 @@ pub trait RangeCollection<K, V> {
/// Remove all elements >= `tail` /// Remove all elements >= `tail`
fn insert_item(&mut self, key: K, value: V); fn insert_item(&mut self, key: K, value: V);
/// Get an iterator over ranges /// Get an iterator over ranges
fn range_iter<'c>(&'c self) -> RangeIterator<'c, K, V>; fn range_iter(& self) -> RangeIterator<K, V>;
} }
/// Range iterator. For each range yelds a key for the first element of the range and a vector of values. /// Range iterator. For each range yelds a key for the first element of the range and a vector of values.
@ -60,7 +60,7 @@ impl<'c, K:'c, V:'c> Iterator for RangeIterator<'c, K, V> where K: Add<Output =
} }
impl<K, V> RangeCollection<K, V> for Vec<(K, Vec<V>)> where K: Ord + PartialEq + Add<Output = K> + Sub<Output = K> + Copy + FromUsize + ToUsize { impl<K, V> RangeCollection<K, V> for Vec<(K, Vec<V>)> where K: Ord + PartialEq + Add<Output = K> + Sub<Output = K> + Copy + FromUsize + ToUsize {
fn range_iter<'c>(&'c self) -> RangeIterator<'c, K, V> { fn range_iter(&self) -> RangeIterator<K, V> {
RangeIterator { RangeIterator {
range: self.len(), range: self.len(),
collection: self collection: self

View File

@ -156,7 +156,7 @@ impl<'a> BlockView<'a> {
/// Return List of transactions in given block. /// Return List of transactions in given block.
pub fn uncle_views(&self) -> Vec<HeaderView> { pub fn uncle_views(&self) -> Vec<HeaderView> {
self.rlp.at(2).iter().map(|rlp| HeaderView::new_from_rlp(rlp)).collect() self.rlp.at(2).iter().map(HeaderView::new_from_rlp).collect()
} }
/// Return list of uncle hashes of given block. /// Return list of uncle hashes of given block.