env implementation in progress

This commit is contained in:
debris 2015-12-29 12:04:03 +01:00
parent 4e31fe5785
commit 3dd26582a2
2 changed files with 58 additions and 4 deletions

View File

@ -1,4 +1,5 @@
use util::hash::*; use util::hash::*;
use util::uint::*;
pub struct Env; pub struct Env;
@ -18,6 +19,35 @@ impl Env {
//unimplemented!(); //unimplemented!();
} }
pub fn balance(&self, _address: &Address) -> U256 {
unimplemented!();
}
pub fn blockhash(&self, _number: &U256) -> H256 {
unimplemented!();
}
/// Creates new contract
/// Returns new contract address gas used
pub fn create(&self, _gas: u64, _endowment: &U256, _code: &[u8]) -> (Address, u64) {
unimplemented!();
}
/// Calls existing contract
/// 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)>{
unimplemented!();
}
/// Returns code at given address
pub fn extcode(&self, _address: &Address) -> Vec<u8> {
unimplemented!();
}
pub fn log(&self, _topics: &[H256], _data: &[u8]) {
unimplemented!();
}
} }

View File

@ -34,6 +34,12 @@ impl<'a> FromJit<&'a evmjit::I256> for H256 {
} }
} }
impl<'a> FromJit<&'a evmjit::I256> for Address {
fn from_jit(input: &'a evmjit::I256) -> Self {
Address::from(H256::from_jit(input))
}
}
impl IntoJit<evmjit::I256> for U256 { impl IntoJit<evmjit::I256> for U256 {
fn into_jit(self) -> evmjit::I256 { fn into_jit(self) -> evmjit::I256 {
let mut res: evmjit::I256 = unsafe { mem::uninitialized() }; let mut res: evmjit::I256 = unsafe { mem::uninitialized() };
@ -115,12 +121,20 @@ impl<'a> evmjit::Env for EnvAdapter<'a> {
} }
} }
fn balance(&self, _address: *const evmjit::I256, _out_value: *mut evmjit::I256) { fn balance(&self, address: *const evmjit::I256, out_value: *mut evmjit::I256) {
unimplemented!(); unsafe {
let a = Address::from_jit(&*address);
let o = self.env.balance(&a);
*out_value = o.into_jit();
}
} }
fn blockhash(&self, _number: *const evmjit::I256, _out_hash: *mut evmjit::I256) { fn blockhash(&self, number: *const evmjit::I256, out_hash: *mut evmjit::I256) {
unimplemented!(); unsafe {
let n = U256::from_jit(&*number);
let o = self.env.blockhash(&n);
*out_hash = o.into_jit();
}
} }
fn create(&mut self, fn create(&mut self,
@ -212,6 +226,16 @@ mod tests {
assert_eq!(h, h2); assert_eq!(h, h2);
} }
#[test]
fn test_to_and_from_address() {
use std::str::FromStr;
let a = Address::from_str("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").unwrap();
let j = a.clone().into_jit();
let a2 = Address::from_jit(&j);
assert_eq!(a, a2);
}
#[test] #[test]
fn test_env_adapter() { fn test_env_adapter() {