From 7aa27652b7d4a8b9e77ab326a32d6173c97ca917 Mon Sep 17 00:00:00 2001 From: Tengfei Niu Date: Wed, 4 Sep 2019 21:53:05 +0800 Subject: [PATCH] refactor code (#2990) refactor: refactor code. --- core/src/core/transaction.rs | 4 ++-- core/src/libtx/build.rs | 2 +- core/src/libtx/error.rs | 2 +- core/src/libtx/reward.rs | 4 ++-- util/src/file.rs | 4 ++-- util/src/hex.rs | 2 +- util/src/logger.rs | 9 ++++----- util/src/rate_counter.rs | 4 ++-- 8 files changed, 15 insertions(+), 16 deletions(-) diff --git a/core/src/core/transaction.rs b/core/src/core/transaction.rs index bfcf961a5..1e7f4d878 100644 --- a/core/src/core/transaction.rs +++ b/core/src/core/transaction.rs @@ -1680,7 +1680,7 @@ mod test { let input = Input { features: OutputFeatures::Plain, - commit: commit, + commit, }; let block_hash = @@ -1696,7 +1696,7 @@ mod test { // different) and check it generates a different short_id let input = Input { features: OutputFeatures::Coinbase, - commit: commit, + commit, }; let short_id = input.short_id(&block_hash, nonce); diff --git a/core/src/libtx/build.rs b/core/src/libtx/build.rs index 1b1037f63..42aaff3f2 100644 --- a/core/src/libtx/build.rs +++ b/core/src/libtx/build.rs @@ -127,7 +127,7 @@ where ( tx.with_output(Output { features: OutputFeatures::Plain, - commit: commit, + commit, proof: rproof, }), kern, diff --git a/core/src/libtx/error.rs b/core/src/libtx/error.rs index 91071eb3d..7ce990834 100644 --- a/core/src/libtx/error.rs +++ b/core/src/libtx/error.rs @@ -79,7 +79,7 @@ impl From for Error { impl From> for Error { fn from(inner: Context) -> Error { - Error { inner: inner } + Error { inner } } } diff --git a/core/src/libtx/reward.rs b/core/src/libtx/reward.rs index 5765ddc8f..ee280df33 100644 --- a/core/src/libtx/reward.rs +++ b/core/src/libtx/reward.rs @@ -48,7 +48,7 @@ where let output = Output { features: OutputFeatures::Coinbase, - commit: commit, + commit, proof: rproof, }; @@ -81,7 +81,7 @@ where let proof = TxKernel { features: KernelFeatures::Coinbase, - excess: excess, + excess, excess_sig: sig, }; Ok((output, proof)) diff --git a/util/src/file.rs b/util/src/file.rs index 8ab4647cb..52b011f66 100644 --- a/util/src/file.rs +++ b/util/src/file.rs @@ -61,10 +61,10 @@ fn copy_to(src: &Path, src_type: &fs::FileType, dst: &Path) -> io::Result { } else if src_type.is_dir() { copy_dir_to(src, dst) } else { - return Err(io::Error::new( + Err(io::Error::new( io::ErrorKind::Other, format!("Could not copy: {}", src.display()), - )); + )) } } diff --git a/util/src/hex.rs b/util/src/hex.rs index fc5c63715..8a7255290 100644 --- a/util/src/hex.rs +++ b/util/src/hex.rs @@ -49,7 +49,7 @@ pub fn from_hex(hex_str: String) -> Result, num::ParseIntError> { } fn split_n(s: &str, n: usize) -> Vec<&str> { - (0..(s.len() - n + 1) / 2 + 1) + (0..=(s.len() - n + 1) / 2) .map(|i| &s[2 * i..2 * i + n]) .collect() } diff --git a/util/src/logger.rs b/util/src/logger.rs index 322098f1c..4cc43e014 100644 --- a/util/src/logger.rs +++ b/util/src/logger.rs @@ -88,14 +88,13 @@ pub fn init_logger(config: Option) { let level_stdout = convert_log_level(&c.stdout_log_level); let level_file = convert_log_level(&c.file_log_level); - let level_minimum; // Determine minimum logging level for Root logger - if level_stdout > level_file { - level_minimum = level_stdout; + let level_minimum = if level_stdout > level_file { + level_stdout } else { - level_minimum = level_file; - } + level_file + }; // Start logger let stdout = ConsoleAppender::builder() diff --git a/util/src/rate_counter.rs b/util/src/rate_counter.rs index dc94d645a..cd03c151d 100644 --- a/util/src/rate_counter.rs +++ b/util/src/rate_counter.rs @@ -77,7 +77,7 @@ impl RateCounter { fn truncate(&mut self) { let now_millis = millis_since_epoch(); - while self.last_min_entries.len() > 0 + while !self.last_min_entries.is_empty() && self.last_min_entries[0].timestamp + 60000 < now_millis { self.last_min_entries.remove(0); @@ -106,5 +106,5 @@ fn millis_since_epoch() -> u64 { let since_epoch = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap_or(Duration::new(0, 0)); - since_epoch.as_secs() * 1000 + since_epoch.subsec_millis() as u64 + since_epoch.as_secs() * 1000 + u64::from(since_epoch.subsec_millis()) }