executive create

This commit is contained in:
debris
2016-01-14 17:40:38 +01:00
parent 05246c4f7d
commit d59e074d65
6 changed files with 66 additions and 69 deletions

View File

@@ -21,10 +21,8 @@ pub trait Ext {
/// Creates new contract.
///
/// If contract creation is successfull, return gas_left and contract address,
/// If depth is too big or transfer value exceeds balance, return None
/// Otherwise return appropriate `Error`.
fn create(&mut self, gas: &U256, value: &U256, code: &[u8]) -> Result<(U256, Option<Address>), Error>;
/// Return gas_left and contract address if contract creation was succesfull.
fn create(&mut self, gas: &U256, value: &U256, code: &[u8]) -> (U256, Option<Address>);
/// Message call.
///

View File

@@ -209,23 +209,12 @@ impl<'a> evmjit::Ext for ExtAdapter<'a> {
init_size: u64,
address: *mut evmjit::H256) {
unsafe {
match self.ext.create(&U256::from(*io_gas), &U256::from_jit(&*endowment), slice::from_raw_parts(init_beg, init_size as usize)) {
Ok((gas_left, opt)) => {
*io_gas = gas_left.low_u64();
*address = match opt {
Some(addr) => addr.into_jit(),
_ => Address::new().into_jit()
};
},
Err(err @ evm::Error::OutOfGas) => {
*self.err = Some(err);
// hack to propagate `OutOfGas` to evmjit and stop
// the execution immediately.
// Works, cause evmjit uses i64, not u64
*io_gas = -1i64 as u64;
},
Err(err) => *self.err = Some(err)
}
let (gas_left, opt_addr) = self.ext.create(&U256::from(*io_gas), &U256::from_jit(&*endowment), slice::from_raw_parts(init_beg, init_size as usize));
*io_gas = gas_left.low_u64();
*address = match opt_addr {
Some(addr) => addr.into_jit(),
_ => Address::new().into_jit()
};
}
}
@@ -254,11 +243,11 @@ impl<'a> evmjit::Ext for ExtAdapter<'a> {
true
},
Err(err @ evm::Error::OutOfGas) => {
*self.err = Some(err);
//*self.err = Some(err);
// hack to propagate `OutOfGas` to evmjit and stop
// the execution immediately.
// Works, cause evmjit uses i64, not u64
*io_gas = -1i64 as u64;
*io_gas = 0 as u64;
false
},
Err(err) => {
@@ -337,6 +326,7 @@ impl evm::Evm for JitEvm {
let mut context = unsafe { evmjit::ContextHandle::new(data.into_jit(), &mut ext_handle) };
let res = context.exec();
println!("jit res: {:?}", res);
// check in adapter if execution of children contracts failed.
if let Some(err) = optional_err {

View File

@@ -42,7 +42,7 @@ impl Ext for FakeExt {
self.blockhashes.get(number).unwrap_or(&H256::new()).clone()
}
fn create(&mut self, _gas: &U256, _value: &U256, _code: &[u8]) -> result::Result<(U256, Option<Address>), evm::Error> {
fn create(&mut self, _gas: &U256, _value: &U256, _code: &[u8]) -> (U256, Option<Address>) {
unimplemented!();
}