From 70c3001d2d623c5913f70425872234c615d5b84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 18 Oct 2016 12:13:49 +0200 Subject: [PATCH] Fixing --no-default-features again and evmbin (#2670) * Fixing --no-default-features again and evmbin * Fixing evmbin Result --- evmbin/Cargo.toml | 3 ++ evmbin/src/main.rs | 62 +++++++++++++++++++++++++-------- signer/src/ws_server/session.rs | 1 - 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/evmbin/Cargo.toml b/evmbin/Cargo.toml index 8ec687687..479e7e7ec 100644 --- a/evmbin/Cargo.toml +++ b/evmbin/Cargo.toml @@ -17,3 +17,6 @@ rustc-serialize = "0.3" docopt = { version = "0.6" } ethcore = { path = "../ethcore" } ethcore-util = { path = "../util" } + +[features] +evm-debug = ["ethcore/evm-debug-tests"] diff --git a/evmbin/src/main.rs b/evmbin/src/main.rs index a63e84e4b..aa9faa1da 100644 --- a/evmbin/src/main.rs +++ b/evmbin/src/main.rs @@ -28,10 +28,11 @@ mod ext; use std::sync::Arc; use std::time::{Instant, Duration}; +use std::fmt; use std::str::FromStr; use docopt::Docopt; use util::{U256, FromHex, Uint, Bytes}; -use ethcore::evm::{Factory, VMType, Finalize}; +use ethcore::evm::{self, Factory, VMType, Finalize}; use ethcore::action_params::ActionParams; const USAGE: &'static str = r#" @@ -61,37 +62,68 @@ fn main() { params.data = args.data(); let result = run_vm(params); - println!("Gas used: {:?}", result.gas_used); - println!("Output: {:?}", result.output); - println!("Time: {}.{:.9}s", result.time.as_secs(), result.time.subsec_nanos()); + match result { + Ok(success) => println!("{}", success), + Err(failure) => println!("{}", failure), + } } /// Execute VM with given `ActionParams` -pub fn run_vm(params: ActionParams) -> ExecutionResults { +pub fn run_vm(params: ActionParams) -> Result { let initial_gas = params.gas; let factory = Factory::new(VMType::Interpreter, 1024); let mut vm = factory.create(params.gas); let mut ext = ext::FakeExt::default(); let start = Instant::now(); - let gas_left = vm.exec(params, &mut ext).finalize(ext).expect("OK"); + let gas_left = vm.exec(params, &mut ext).finalize(ext); let duration = start.elapsed(); - ExecutionResults { - gas_used: initial_gas - gas_left, - output: Vec::new(), - time: duration, + match gas_left { + Ok(gas_left) => Ok(Success { + gas_used: initial_gas - gas_left, + // TODO [ToDr] get output from ext + output: Vec::new(), + time: duration, + }), + Err(e) => Err(Failure { + error: e, + time: duration, + }), } } -/// VM execution results -pub struct ExecutionResults { +/// Execution finished correctly +pub struct Success { /// Used gas - pub gas_used: U256, + gas_used: U256, /// Output as bytes - pub output: Vec, + output: Vec, /// Time Taken - pub time: Duration, + time: Duration, +} +impl fmt::Display for Success { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + try!(writeln!(f, "Gas used: {:?}", self.gas_used)); + try!(writeln!(f, "Output: {:?}", self.output)); + try!(writeln!(f, "Time: {}.{:.9}s", self.time.as_secs(), self.time.subsec_nanos())); + Ok(()) + } +} + +/// Execution failed +pub struct Failure { + /// Internal error + error: evm::Error, + /// Duration + time: Duration, +} +impl fmt::Display for Failure { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + try!(writeln!(f, "Error: {:?}", self.error)); + try!(writeln!(f, "Time: {}.{:.9}s", self.time.as_secs(), self.time.subsec_nanos())); + Ok(()) + } } #[derive(Debug, RustcDecodable)] diff --git a/signer/src/ws_server/session.rs b/signer/src/ws_server/session.rs index 45146f988..45518850e 100644 --- a/signer/src/ws_server/session.rs +++ b/signer/src/ws_server/session.rs @@ -49,7 +49,6 @@ mod ui { #[cfg(not(feature = "ui"))] mod ui { pub struct File { - pub content: &'static str, pub content: &'static [u8], pub content_type: &'static str, }