Fixing --no-default-features again and evmbin (#2670)
* Fixing --no-default-features again and evmbin * Fixing evmbin Result
This commit is contained in:
parent
1e6a2cb378
commit
70c3001d2d
@ -17,3 +17,6 @@ rustc-serialize = "0.3"
|
|||||||
docopt = { version = "0.6" }
|
docopt = { version = "0.6" }
|
||||||
ethcore = { path = "../ethcore" }
|
ethcore = { path = "../ethcore" }
|
||||||
ethcore-util = { path = "../util" }
|
ethcore-util = { path = "../util" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
evm-debug = ["ethcore/evm-debug-tests"]
|
||||||
|
@ -28,10 +28,11 @@ mod ext;
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Instant, Duration};
|
use std::time::{Instant, Duration};
|
||||||
|
use std::fmt;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use docopt::Docopt;
|
use docopt::Docopt;
|
||||||
use util::{U256, FromHex, Uint, Bytes};
|
use util::{U256, FromHex, Uint, Bytes};
|
||||||
use ethcore::evm::{Factory, VMType, Finalize};
|
use ethcore::evm::{self, Factory, VMType, Finalize};
|
||||||
use ethcore::action_params::ActionParams;
|
use ethcore::action_params::ActionParams;
|
||||||
|
|
||||||
const USAGE: &'static str = r#"
|
const USAGE: &'static str = r#"
|
||||||
@ -61,37 +62,68 @@ fn main() {
|
|||||||
params.data = args.data();
|
params.data = args.data();
|
||||||
|
|
||||||
let result = run_vm(params);
|
let result = run_vm(params);
|
||||||
println!("Gas used: {:?}", result.gas_used);
|
match result {
|
||||||
println!("Output: {:?}", result.output);
|
Ok(success) => println!("{}", success),
|
||||||
println!("Time: {}.{:.9}s", result.time.as_secs(), result.time.subsec_nanos());
|
Err(failure) => println!("{}", failure),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute VM with given `ActionParams`
|
/// Execute VM with given `ActionParams`
|
||||||
pub fn run_vm(params: ActionParams) -> ExecutionResults {
|
pub fn run_vm(params: ActionParams) -> Result<Success, Failure> {
|
||||||
let initial_gas = params.gas;
|
let initial_gas = params.gas;
|
||||||
let factory = Factory::new(VMType::Interpreter, 1024);
|
let factory = Factory::new(VMType::Interpreter, 1024);
|
||||||
let mut vm = factory.create(params.gas);
|
let mut vm = factory.create(params.gas);
|
||||||
let mut ext = ext::FakeExt::default();
|
let mut ext = ext::FakeExt::default();
|
||||||
|
|
||||||
let start = Instant::now();
|
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();
|
let duration = start.elapsed();
|
||||||
|
|
||||||
ExecutionResults {
|
match gas_left {
|
||||||
gas_used: initial_gas - gas_left,
|
Ok(gas_left) => Ok(Success {
|
||||||
output: Vec::new(),
|
gas_used: initial_gas - gas_left,
|
||||||
time: duration,
|
// TODO [ToDr] get output from ext
|
||||||
|
output: Vec::new(),
|
||||||
|
time: duration,
|
||||||
|
}),
|
||||||
|
Err(e) => Err(Failure {
|
||||||
|
error: e,
|
||||||
|
time: duration,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// VM execution results
|
/// Execution finished correctly
|
||||||
pub struct ExecutionResults {
|
pub struct Success {
|
||||||
/// Used gas
|
/// Used gas
|
||||||
pub gas_used: U256,
|
gas_used: U256,
|
||||||
/// Output as bytes
|
/// Output as bytes
|
||||||
pub output: Vec<u8>,
|
output: Vec<u8>,
|
||||||
/// Time Taken
|
/// 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)]
|
#[derive(Debug, RustcDecodable)]
|
||||||
|
@ -49,7 +49,6 @@ mod ui {
|
|||||||
#[cfg(not(feature = "ui"))]
|
#[cfg(not(feature = "ui"))]
|
||||||
mod ui {
|
mod ui {
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub content: &'static str,
|
|
||||||
pub content: &'static [u8],
|
pub content: &'static [u8],
|
||||||
pub content_type: &'static str,
|
pub content_type: &'static str,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user