evm call and create in progress
This commit is contained in:
parent
a0bb1068af
commit
8c6d6950ca
@ -109,19 +109,19 @@ pub trait Env {
|
|||||||
io_gas: *mut u64,
|
io_gas: *mut u64,
|
||||||
endowment: *const JitI256,
|
endowment: *const JitI256,
|
||||||
init_beg: *const u8,
|
init_beg: *const u8,
|
||||||
init_size: *const u64,
|
init_size: u64,
|
||||||
address: *mut JitI256);
|
address: *mut JitH256);
|
||||||
|
|
||||||
fn call(&mut self,
|
fn call(&mut self,
|
||||||
io_gas: *mut u64,
|
io_gas: *mut u64,
|
||||||
call_gas: *const u64,
|
call_gas: u64,
|
||||||
receive_address: *const JitI256,
|
receive_address: *const JitH256,
|
||||||
value: *const JitI256,
|
value: *const JitI256,
|
||||||
in_beg: *const u8,
|
in_beg: *const u8,
|
||||||
in_size: *const u64,
|
in_size: u64,
|
||||||
out_beg: *mut u8,
|
out_beg: *mut u8,
|
||||||
out_size: *mut u64,
|
out_size: u64,
|
||||||
code_address: JitI256) -> bool;
|
code_address: *const JitH256) -> bool;
|
||||||
|
|
||||||
fn log(&mut self,
|
fn log(&mut self,
|
||||||
beg: *const u8,
|
beg: *const u8,
|
||||||
@ -321,8 +321,8 @@ pub mod ffi {
|
|||||||
io_gas: *mut u64,
|
io_gas: *mut u64,
|
||||||
endowment: *const JitI256,
|
endowment: *const JitI256,
|
||||||
init_beg: *const u8,
|
init_beg: *const u8,
|
||||||
init_size: *const u64,
|
init_size: u64,
|
||||||
address: *mut JitI256) {
|
address: *mut JitH256) {
|
||||||
let env = &mut *env;
|
let env = &mut *env;
|
||||||
env.create(io_gas, endowment, init_beg, init_size, address);
|
env.create(io_gas, endowment, init_beg, init_size, address);
|
||||||
}
|
}
|
||||||
@ -330,20 +330,20 @@ pub mod ffi {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn env_call(env: *mut EnvHandle,
|
pub unsafe extern "C" fn env_call(env: *mut EnvHandle,
|
||||||
io_gas: *mut u64,
|
io_gas: *mut u64,
|
||||||
call_gas: *const u64,
|
call_gas: u64,
|
||||||
receive_address: *const JitI256,
|
receive_address: *const JitH256,
|
||||||
value: *const JitI256,
|
value: *const JitI256,
|
||||||
in_beg: *const u8,
|
in_beg: *const u8,
|
||||||
in_size: *const u64,
|
in_size: u64,
|
||||||
out_beg: *mut u8,
|
out_beg: *mut u8,
|
||||||
out_size: *mut u64,
|
out_size: u64,
|
||||||
code_address: JitI256) -> bool {
|
code_address: *const JitH256) -> bool {
|
||||||
let env = &mut *env;
|
let env = &mut *env;
|
||||||
env.call(io_gas, call_gas, receive_address, value, in_beg, in_size, out_beg, out_size, code_address)
|
env.call(io_gas, call_gas, receive_address, value, in_beg, in_size, out_beg, out_size, code_address)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn env_sha3(begin: *const u8, size: u64, out_hash: *mut JitI256) {
|
pub unsafe extern "C" fn env_sha3(begin: *const u8, size: u64, out_hash: *mut JitH256) {
|
||||||
let out_hash = &mut *out_hash;
|
let out_hash = &mut *out_hash;
|
||||||
let input = slice::from_raw_parts(begin, size as usize);
|
let input = slice::from_raw_parts(begin, size as usize);
|
||||||
let outlen = out_hash.words.len() * 8;
|
let outlen = out_hash.words.len() * 8;
|
||||||
|
@ -88,15 +88,15 @@ impl Env {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates new contract
|
/// Creates new contract.
|
||||||
/// Returns new contract address gas used
|
/// Returns new contract address and gas used.
|
||||||
pub fn create(&self, _gas: u64, _endowment: &U256, _code: &[u8]) -> (Address, u64) {
|
pub fn create(&self, _gas: u64, _endowment: &U256, _code: &[u8]) -> (Address, u64) {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calls existing contract
|
/// Calls existing contract.
|
||||||
/// Returns call output and gas used
|
/// Returns call output and gas used.
|
||||||
pub fn call(&self, _gas: u64, _call_gas: u64, _receive_address: &H256, _value: &U256, _data: &[u8], _code_address: &Address) -> Option<(Vec<u8>, u64)>{
|
pub fn call(&self, _gas: u64, _call_gas: u64, _receive_address: &Address, _value: &U256, _data: &[u8], _code_address: &Address) -> Option<(Vec<u8>, u64)>{
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,12 @@ impl IntoJit<evmjit::I256> for Address {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntoJit<evmjit::H256> for Address {
|
||||||
|
fn into_jit(self) -> evmjit::H256 {
|
||||||
|
H256::from(self).into_jit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl IntoJit<evmjit::RuntimeDataHandle> for evm::RuntimeData {
|
impl IntoJit<evmjit::RuntimeDataHandle> for evm::RuntimeData {
|
||||||
fn into_jit(self) -> evmjit::RuntimeDataHandle {
|
fn into_jit(self) -> evmjit::RuntimeDataHandle {
|
||||||
let mut data = evmjit::RuntimeDataHandle::new();
|
let mut data = evmjit::RuntimeDataHandle::new();
|
||||||
@ -157,25 +163,46 @@ impl<'a> evmjit::Env for EnvAdapter<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create(&mut self,
|
fn create(&mut self,
|
||||||
_io_gas: *mut u64,
|
io_gas: *mut u64,
|
||||||
_endowment: *const evmjit::I256,
|
endowment: *const evmjit::I256,
|
||||||
_init_beg: *const u8,
|
init_beg: *const u8,
|
||||||
_init_size: *const u64,
|
init_size: u64,
|
||||||
_address: *mut evmjit::I256) {
|
address: *mut evmjit::H256) {
|
||||||
unimplemented!();
|
unsafe {
|
||||||
|
let (addr, gas) = self.env.create(*io_gas, &U256::from_jit(&*endowment), slice::from_raw_parts(init_beg, init_size as usize));
|
||||||
|
*io_gas = gas;
|
||||||
|
*address = addr.into_jit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self,
|
fn call(&mut self,
|
||||||
_io_gas: *mut u64,
|
io_gas: *mut u64,
|
||||||
_call_gas: *const u64,
|
call_gas: u64,
|
||||||
_receive_address: *const evmjit::I256,
|
receive_address: *const evmjit::H256,
|
||||||
_value: *const evmjit::I256,
|
value: *const evmjit::I256,
|
||||||
_in_beg: *const u8,
|
in_beg: *const u8,
|
||||||
_in_size: *const u64,
|
in_size: u64,
|
||||||
_out_beg: *mut u8,
|
mut out_beg: *mut u8,
|
||||||
_out_size: *mut u64,
|
out_size: u64,
|
||||||
_code_address: evmjit::I256) -> bool {
|
code_address: *const evmjit::H256) -> bool {
|
||||||
unimplemented!();
|
unsafe {
|
||||||
|
let opt = self.env.call(*io_gas,
|
||||||
|
call_gas,
|
||||||
|
&Address::from_jit(&*receive_address),
|
||||||
|
&U256::from_jit(&*value),
|
||||||
|
slice::from_raw_parts(in_beg, in_size as usize),
|
||||||
|
&Address::from_jit(&*code_address));
|
||||||
|
|
||||||
|
if opt.is_none() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let (mut output, gas) = opt.unwrap();
|
||||||
|
out_beg = output.as_mut_ptr();
|
||||||
|
mem::forget(output);
|
||||||
|
*io_gas = gas;
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log(&mut self,
|
fn log(&mut self,
|
||||||
@ -281,7 +308,7 @@ mod tests {
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
let a = Address::from_str("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").unwrap();
|
let a = Address::from_str("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").unwrap();
|
||||||
let j = a.clone().into_jit();
|
let j: ::evmjit::I256 = a.clone().into_jit();
|
||||||
let a2 = Address::from_jit(&j);
|
let a2 = Address::from_jit(&j);
|
||||||
assert_eq!(a, a2);
|
assert_eq!(a, a2);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user