Skip to content

Commit

Permalink
[clippy] fix clippy issue[skip travis]
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Jul 29, 2019
1 parent acbfd5b commit 8a78f7f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
33 changes: 14 additions & 19 deletions cita-executor/core/src/cita_executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -215,9 +215,7 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {
};
self.call(&params)
}
};

result
}
}

fn payment_required(&self) -> bool {
Expand Down Expand Up @@ -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(())
}
Expand All @@ -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(())
}
Expand All @@ -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(())
}
Expand Down Expand Up @@ -414,7 +412,7 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {

fn call_evm(&mut self, params: &VmExecParams) -> Result<ExecutedResult, ExecutionError> {
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(),
Expand All @@ -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(&params.sender, &params.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(),
Expand Down
6 changes: 3 additions & 3 deletions cita-executor/core/src/libexecutor/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion cita-executor/core/src/libexecutor/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions cita-executor/core/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down Expand Up @@ -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]);
Expand All @@ -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)
}

Expand Down

0 comments on commit 8a78f7f

Please sign in to comment.