Fix clippy lints

This commit is contained in:
Paul Hauner 2018-09-26 11:53:15 +10:00
parent 966d891cb5
commit baa7b06b56
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
11 changed files with 30 additions and 27 deletions

View File

@ -28,7 +28,7 @@ impl MemoryDB {
pub fn open() -> Self { pub fn open() -> Self {
let db: DBHashMap = HashMap::new(); let db: DBHashMap = HashMap::new();
let mut known_columns: ColumnHashSet = HashSet::new(); let mut known_columns: ColumnHashSet = HashSet::new();
for col in COLUMNS.iter() { for col in &COLUMNS {
known_columns.insert(col.to_string()); known_columns.insert(col.to_string());
} }
Self { Self {

View File

@ -21,7 +21,7 @@ impl<T: ClientDB> PoWChainStore<T> {
pub fn put_block_hash(&self, hash: &[u8]) pub fn put_block_hash(&self, hash: &[u8])
-> Result<(), DBError> -> Result<(), DBError>
{ {
self.db.put(DB_COLUMN, hash, &vec![0]) self.db.put(DB_COLUMN, hash, &[0])
} }
pub fn block_hash_exists(&self, hash: &[u8]) pub fn block_hash_exists(&self, hash: &[u8])

View File

@ -42,7 +42,7 @@ impl<T: ClientDB> ValidatorStore<T> {
} }
} }
fn prefix_bytes(&self, key_prefix: KeyPrefixes) fn prefix_bytes(&self, key_prefix: &KeyPrefixes)
-> Vec<u8> -> Vec<u8>
{ {
match key_prefix { match key_prefix {
@ -50,7 +50,7 @@ impl<T: ClientDB> ValidatorStore<T> {
} }
} }
fn get_db_key_for_index(&self, key_prefix: KeyPrefixes, index: usize) fn get_db_key_for_index(&self, key_prefix: &KeyPrefixes, index: usize)
-> Vec<u8> -> Vec<u8>
{ {
let mut buf = BytesMut::with_capacity(6 + 8); let mut buf = BytesMut::with_capacity(6 + 8);
@ -62,16 +62,16 @@ impl<T: ClientDB> ValidatorStore<T> {
pub fn put_public_key_by_index(&self, index: usize, public_key: &PublicKey) pub fn put_public_key_by_index(&self, index: usize, public_key: &PublicKey)
-> Result<(), ValidatorStoreError> -> Result<(), ValidatorStoreError>
{ {
let key = self.get_db_key_for_index(KeyPrefixes::PublicKey, index); let key = self.get_db_key_for_index(&KeyPrefixes::PublicKey, index);
let val = public_key.as_bytes(); let val = public_key.as_bytes();
self.db.put(DB_COLUMN, &key[..], &val[..]) self.db.put(DB_COLUMN, &key[..], &val[..])
.map_err(|e| ValidatorStoreError::from(e)) .map_err(ValidatorStoreError::from)
} }
pub fn get_public_key_by_index(&self, index: usize) pub fn get_public_key_by_index(&self, index: usize)
-> Result<Option<PublicKey>, ValidatorStoreError> -> Result<Option<PublicKey>, ValidatorStoreError>
{ {
let key = self.get_db_key_for_index(KeyPrefixes::PublicKey, index); let key = self.get_db_key_for_index(&KeyPrefixes::PublicKey, index);
let val = self.db.get(DB_COLUMN, &key[..])?; let val = self.db.get(DB_COLUMN, &key[..])?;
match val { match val {
None => Ok(None), None => Ok(None),
@ -129,7 +129,7 @@ mod tests {
let db = Arc::new(MemoryDB::open()); let db = Arc::new(MemoryDB::open());
let store = ValidatorStore::new(db.clone()); let store = ValidatorStore::new(db.clone());
let key = store.get_db_key_for_index(KeyPrefixes::PublicKey, 42); let key = store.get_db_key_for_index(&KeyPrefixes::PublicKey, 42);
db.put(DB_COLUMN, &key[..], "cats".as_bytes()).unwrap(); db.put(DB_COLUMN, &key[..], "cats".as_bytes()).unwrap();
assert_eq!(store.get_public_key_by_index(42), assert_eq!(store.get_public_key_by_index(42),

View File

@ -3,10 +3,10 @@ use super::ssz;
use super::utils; use super::utils;
mod attestation_record; mod structs;
mod ssz_splitter; mod ssz_splitter;
pub use self::attestation_record::{ pub use self::structs::{
AttestationRecord, AttestationRecord,
MIN_SSZ_ATTESTION_RECORD_LENGTH, MIN_SSZ_ATTESTION_RECORD_LENGTH,
}; };

View File

@ -24,8 +24,8 @@ pub fn split_all_attestations<'a>(full_ssz: &'a [u8], index: usize)
/// Given some ssz slice, find the bounds of one serialized AttestationRecord /// Given some ssz slice, find the bounds of one serialized AttestationRecord
/// and return a slice pointing to that. /// and return a slice pointing to that.
pub fn split_one_attestation<'a>(full_ssz: &'a [u8], index: usize) pub fn split_one_attestation(full_ssz: &[u8], index: usize)
-> Result<(&'a [u8], usize), AttestationSplitError> -> Result<(&[u8], usize), AttestationSplitError>
{ {
if full_ssz.len() < MIN_LENGTH { if full_ssz.len() < MIN_LENGTH {
return Err(AttestationSplitError::TooShort); return Err(AttestationSplitError::TooShort);

View File

@ -4,8 +4,8 @@ use super::ssz;
use super::utils; use super::utils;
use super::attestation_record; use super::attestation_record;
mod block; mod structs;
mod ssz_block; mod ssz_block;
pub use self::block::Block; pub use self::structs::Block;
pub use self::ssz_block::SszBlock; pub use self::ssz_block::SszBlock;

View File

@ -3,7 +3,7 @@ use super::ssz::decode::{
Decodable, Decodable,
}; };
use super::utils::hash::canonical_hash; use super::utils::hash::canonical_hash;
use super::block::{ use super::structs::{
MIN_SSZ_BLOCK_LENGTH, MIN_SSZ_BLOCK_LENGTH,
MAX_SSZ_BLOCK_LENGTH, MAX_SSZ_BLOCK_LENGTH,
}; };
@ -146,7 +146,7 @@ impl<'a> SszBlock<'a> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use super::super::block::Block; use super::super::structs::Block;
use super::super::attestation_record::AttestationRecord; use super::super::attestation_record::AttestationRecord;
use super::super::ssz::SszStream; use super::super::ssz::SszStream;
use super::super::utils::types::Hash256; use super::super::utils::types::Hash256;

View File

@ -8,7 +8,7 @@ pub struct ChainConfig {
/* /*
* Presently this is just some arbitrary time in Sept 2018. * Presently this is just some arbitrary time in Sept 2018.
*/ */
const GENESIS_TIME: u64 = 1537488655; const GENESIS_TIME: u64 = 1_537_488_655;
impl ChainConfig { impl ChainConfig {
pub fn standard() -> Self { pub fn standard() -> Self {

View File

@ -6,10 +6,10 @@ use super::utils::types::Hash256;
*/ */
pub fn get_block_hash( pub fn get_block_hash(
active_state_recent_block_hashes: &Vec<Hash256>, active_state_recent_block_hashes: &[Hash256],
current_block_slot: &u64, current_block_slot: u64,
slot: &u64, slot: u64,
cycle_length: &u64, // convert from standard u8 cycle_length: u64, // convert from standard u8
) -> Result<Hash256, ParameterError> { ) -> Result<Hash256, ParameterError> {
// active_state must have at 2*cycle_length hashes // active_state must have at 2*cycle_length hashes
assert_error!( assert_error!(
@ -19,16 +19,16 @@ pub fn get_block_hash(
)) ))
); );
let state_start_slot = (*current_block_slot) let state_start_slot = (current_block_slot)
.checked_sub(cycle_length * 2) .checked_sub(cycle_length * 2)
.unwrap_or(0); .unwrap_or(0);
assert_error!( assert_error!(
(state_start_slot <= *slot) && (*slot < *current_block_slot), (state_start_slot <= slot) && (slot < current_block_slot),
ParameterError::InvalidInput(String::from("incorrect slot number")) ParameterError::InvalidInput(String::from("incorrect slot number"))
); );
let index = 2 * cycle_length + (*slot) - *current_block_slot; // should always be positive let index = 2 * cycle_length + slot - current_block_slot; // should always be positive
Ok(active_state_recent_block_hashes[index as usize]) Ok(active_state_recent_block_hashes[index as usize])
} }
@ -47,13 +47,16 @@ mod tests {
block_hashes.push(Hash256::random()); block_hashes.push(Hash256::random());
} }
let result = get_block_hash(&block_hashes, &block_slot, &slot, &cycle_length).unwrap(); let result = get_block_hash(
&block_hashes,
block_slot,
slot,
cycle_length)
.unwrap();
assert_eq!( assert_eq!(
result, result,
block_hashes[(2 * cycle_length + slot - block_slot) as usize] block_hashes[(2 * cycle_length + slot - block_slot) as usize]
); );
println!("{:?}", result);
} }
} }