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 {
let db: DBHashMap = HashMap::new();
let mut known_columns: ColumnHashSet = HashSet::new();
for col in COLUMNS.iter() {
for col in &COLUMNS {
known_columns.insert(col.to_string());
}
Self {

View File

@ -21,7 +21,7 @@ impl<T: ClientDB> PoWChainStore<T> {
pub fn put_block_hash(&self, hash: &[u8])
-> 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])

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>
{
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>
{
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)
-> 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();
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)
-> 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[..])?;
match val {
None => Ok(None),
@ -129,7 +129,7 @@ mod tests {
let db = Arc::new(MemoryDB::open());
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();
assert_eq!(store.get_public_key_by_index(42),

View File

@ -3,10 +3,10 @@ use super::ssz;
use super::utils;
mod attestation_record;
mod structs;
mod ssz_splitter;
pub use self::attestation_record::{
pub use self::structs::{
AttestationRecord,
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
/// and return a slice pointing to that.
pub fn split_one_attestation<'a>(full_ssz: &'a [u8], index: usize)
-> Result<(&'a [u8], usize), AttestationSplitError>
pub fn split_one_attestation(full_ssz: &[u8], index: usize)
-> Result<(&[u8], usize), AttestationSplitError>
{
if full_ssz.len() < MIN_LENGTH {
return Err(AttestationSplitError::TooShort);

View File

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

View File

@ -3,7 +3,7 @@ use super::ssz::decode::{
Decodable,
};
use super::utils::hash::canonical_hash;
use super::block::{
use super::structs::{
MIN_SSZ_BLOCK_LENGTH,
MAX_SSZ_BLOCK_LENGTH,
};
@ -146,7 +146,7 @@ impl<'a> SszBlock<'a> {
#[cfg(test)]
mod tests {
use super::*;
use super::super::block::Block;
use super::super::structs::Block;
use super::super::attestation_record::AttestationRecord;
use super::super::ssz::SszStream;
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.
*/
const GENESIS_TIME: u64 = 1537488655;
const GENESIS_TIME: u64 = 1_537_488_655;
impl ChainConfig {
pub fn standard() -> Self {

View File

@ -6,10 +6,10 @@ use super::utils::types::Hash256;
*/
pub fn get_block_hash(
active_state_recent_block_hashes: &Vec<Hash256>,
current_block_slot: &u64,
slot: &u64,
cycle_length: &u64, // convert from standard u8
active_state_recent_block_hashes: &[Hash256],
current_block_slot: u64,
slot: u64,
cycle_length: u64, // convert from standard u8
) -> Result<Hash256, ParameterError> {
// active_state must have at 2*cycle_length hashes
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)
.unwrap_or(0);
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"))
);
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])
}
@ -47,13 +47,16 @@ mod tests {
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!(
result,
block_hashes[(2 * cycle_length + slot - block_slot) as usize]
);
println!("{:?}", result);
}
}