From 8c9d88db966583f25cbc1bfae894a9df20589a31 Mon Sep 17 00:00:00 2001 From: ouwenkg <2630582710@qq.com> Date: Mon, 29 Jul 2019 11:49:59 +0800 Subject: [PATCH] [clippy] fix clippy issue[skip travis] --- cita-executor/core/src/cita_executive.rs | 33 ++++++++----------- cita-executor/core/src/libexecutor/block.rs | 6 ++-- cita-executor/core/src/libexecutor/command.rs | 2 +- cita-executor/core/src/storage.rs | 6 ++-- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/cita-executor/core/src/cita_executive.rs b/cita-executor/core/src/cita_executive.rs index a7b2153b9..a12170f50 100644 --- a/cita-executor/core/src/cita_executive.rs +++ b/cita-executor/core/src/cita_executive.rs @@ -112,7 +112,7 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> { let init_gas = t.gas - U256::from(base_gas_required); - let result = match t.action { + match t.action { Action::Store | Action::AbiStore => { // Prepaid t.gas for the transaction. self.prepaid(t.sender(), t.gas, t.gas_price, t.value)?; @@ -215,9 +215,7 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> { }; self.call(¶ms) } - }; - - result + } } fn payment_required(&self) -> bool { @@ -253,7 +251,7 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> { self.state_provider .borrow_mut() .add_balance(address, value) - .map_err(|e| ExecutionError::State(e)) + .map_err(ExecutionError::State) } else { Ok(()) } @@ -268,7 +266,7 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> { self.state_provider .borrow_mut() .add_balance(coin_base, fee_value) - .map_err(|e| ExecutionError::State(e)) + .map_err(ExecutionError::State) } else { Ok(()) } @@ -284,7 +282,7 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> { self.state_provider .borrow_mut() .transfer_balance(from, to, value) - .map_err(|e| ExecutionError::State(e)) + .map_err(ExecutionError::State) } else { Ok(()) } @@ -414,7 +412,7 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> { fn call_evm(&mut self, params: &VmExecParams) -> Result { let evm_transaction = build_evm_transaction(params); - let evm_config = build_evm_config(self.env_info.gas_limit.clone().as_u64()); + let evm_config = build_evm_config(self.env_info.gas_limit.as_u64()); let evm_context = build_evm_context(&self.env_info); let result = match cita_vm::exec( self.block_provider.clone(), @@ -441,23 +439,20 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> { self.state_provider.borrow_mut().checkpoint(); // At first, transfer value to destination. - if self.payment_required() { - if self + if self.payment_required() + && self .transfer_balance(¶ms.sender, ¶ms.to_address.unwrap(), params.value) .is_err() - { - // Discard the checkpoint - self.state_provider.borrow_mut().revert_checkpoint(); - return Err(ExecutionError::Internal( - "Transfer balance failed while calling native contract.".to_string(), - )); - } + { + // Discard the checkpoint + self.state_provider.borrow_mut().revert_checkpoint(); + return Err(ExecutionError::Internal( + "Transfer balance failed while calling native contract.".to_string(), + )); } let store = VmSubState::default(); - let store = Arc::new(RefCell::new(store)); - let mut vm_data_provider = DataProvider::new( self.block_provider.clone(), self.state_provider.clone(), diff --git a/cita-executor/core/src/libexecutor/block.rs b/cita-executor/core/src/libexecutor/block.rs index 3a1dfcfd0..678e8e4de 100644 --- a/cita-executor/core/src/libexecutor/block.rs +++ b/cita-executor/core/src/libexecutor/block.rs @@ -156,7 +156,7 @@ impl ExecutedBlock { if (*conf).check_options.fee_back_platform { // Set coin_base to chain_owner if check_fee_back_platform is true, and chain_owner is set. if (*conf).chain_owner != Address::from(0) { - env_info.coin_base = (*conf).chain_owner.clone(); + env_info.coin_base = (*conf).chain_owner; } } let block_data_provider = EVMBlockDataProvider::new(env_info.clone()); @@ -175,10 +175,10 @@ impl ExecutedBlock { // FIXME: logic from old cita, but there is some confuse about this logic. let quota_used = U256::from(ret.quota_used); let transaction_quota_used = quota_used - self.current_quota_used; - self.current_quota_used = U256::from(quota_used); + self.current_quota_used = quota_used; if conf.check_options.quota { if let Some(value) = self.account_gas.get_mut(t.sender()) { - *value = *value - transaction_quota_used; + *value -= transaction_quota_used; } } diff --git a/cita-executor/core/src/libexecutor/command.rs b/cita-executor/core/src/libexecutor/command.rs index 464a0929f..d797ef103 100644 --- a/cita-executor/core/src/libexecutor/command.rs +++ b/cita-executor/core/src/libexecutor/command.rs @@ -301,7 +301,7 @@ impl Commander for Executor { let native_factory = NativeFactory::default(); let state_root = if let Some(h) = self.block_header(block_id) { - (*h.state_root()).clone() + (*h.state_root()) } else { error!("Can not get state rott from trie db!"); return Err(CallError::StatePruned); diff --git a/cita-executor/core/src/storage.rs b/cita-executor/core/src/storage.rs index fcd0f25c2..bee68053c 100644 --- a/cita-executor/core/src/storage.rs +++ b/cita-executor/core/src/storage.rs @@ -100,7 +100,7 @@ impl Scalar { for chunk in encoded.chunks(32) { let value = H256::from(chunk); data_provider.set_storage(addr, H256::from(key), value); - key = key + U256::one(); + key += U256::one(); } } Ok(()) @@ -129,7 +129,7 @@ impl Scalar { let v = data_provider.get_storage(addr, &H256::from(key)); if len > 32 { bytes.extend_from_slice(v.as_ref()); - key = key + U256::one(); + key += U256::one(); len -= 32; } else { bytes.extend_from_slice(&v[0..len]); @@ -153,7 +153,7 @@ impl Array { #[inline] fn key(&self, index: u64) -> H256 { let mut key = U256::from(H256::from_slice(&sha3::keccak256(&self.position))); - key = key + U256::from(index); + key += U256::from(index); H256::from(key) }