From 239e2c82e62078c580c7e568a00643a259a9c697 Mon Sep 17 00:00:00 2001 From: debris Date: Fri, 1 Apr 2016 03:08:42 +0200 Subject: [PATCH] simplified trace from functions, removed clippy warnings --- ethcore/src/action_params.rs | 9 +++++++++ ethcore/src/trace.rs | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ethcore/src/action_params.rs b/ethcore/src/action_params.rs index 2f5aa3340..57100b2c5 100644 --- a/ethcore/src/action_params.rs +++ b/ethcore/src/action_params.rs @@ -27,6 +27,15 @@ pub enum ActionValue { Apparent(U256) } +impl ActionValue { + /// Returns action value as U256. + pub fn value(&self) -> U256 { + match *self { + ActionValue::Transfer(x) | ActionValue::Apparent(x) => x + } + } +} + // TODO: should be a trait, possible to avoid cloning everything from a Transaction(/View). /// Action (call/create) input params. Everything else should be specified in Externalities. #[derive(Clone, Debug)] diff --git a/ethcore/src/trace.rs b/ethcore/src/trace.rs index 858230bcd..1ea26b07e 100644 --- a/ethcore/src/trace.rs +++ b/ethcore/src/trace.rs @@ -90,9 +90,9 @@ impl TraceAction { TraceAction::Call(TraceCall { from: p.sender.clone(), to: p.address.clone(), - value: match p.value { ActionValue::Transfer(ref x) | ActionValue::Apparent(ref x) => x.clone() }, - gas: p.gas.clone(), - input: p.data.clone().unwrap_or(vec![]), + value: p.value.value(), + gas: p.gas, + input: p.data.clone().unwrap_or_else(Vec::new), result: None, }) } @@ -101,9 +101,9 @@ impl TraceAction { pub fn from_create(p: &ActionParams) -> TraceAction { TraceAction::Create(TraceCreate { from: p.sender.clone(), - value: match p.value { ActionValue::Transfer(ref x) | ActionValue::Apparent(ref x) => x.clone() }, - gas: p.gas.clone(), - init: p.code.clone().unwrap_or(vec![]), + value: p.value.value(), + gas: p.gas, + init: p.code.clone().unwrap_or_else(Vec::new), result: None, }) }