evmhandle deref && deref mut, mapped balance && blockhash
This commit is contained in:
parent
963d967a46
commit
6697edc0ed
@ -14,6 +14,7 @@
|
|||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
use std::ops::{Deref, DerefMut};
|
||||||
use self::ffi::*;
|
use self::ffi::*;
|
||||||
|
|
||||||
pub use self::ffi::JitReturnCode as ReturnCode;
|
pub use self::ffi::JitReturnCode as ReturnCode;
|
||||||
@ -80,6 +81,8 @@ impl Drop for ContextHandle {
|
|||||||
pub trait Env {
|
pub trait Env {
|
||||||
fn sload(&self, index: *const JitI256, out_value: *mut JitI256);
|
fn sload(&self, index: *const JitI256, out_value: *mut JitI256);
|
||||||
fn sstore(&mut self, index: *const JitI256, value: *const JitI256);
|
fn sstore(&mut self, index: *const JitI256, value: *const JitI256);
|
||||||
|
fn balance(&self, address: *const JitI256, out_value: *mut JitI256);
|
||||||
|
fn blockhash(&self, number: *const JitI256, out_hash: *mut JitI256);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// C abi compatible wrapper for jit env implementers.
|
/// C abi compatible wrapper for jit env implementers.
|
||||||
@ -100,21 +103,24 @@ impl EnvHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Env for EnvHandle {
|
impl Deref for EnvHandle {
|
||||||
fn sload(&self, index: *const JitI256, out_value: *mut JitI256) {
|
type Target = Box<Env>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
match self.env_impl {
|
match self.env_impl {
|
||||||
Some(ref env) => env.sload(index, out_value),
|
Some(ref env) => env,
|
||||||
None => { panic!(); }
|
None => { panic!(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn sstore(&mut self, index: *const JitI256, value: *const JitI256) {
|
impl DerefMut for EnvHandle {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
match self.env_impl {
|
match self.env_impl {
|
||||||
Some(ref mut env) => env.sstore(index, value),
|
Some(ref mut env) => env,
|
||||||
None => { panic!(); }
|
None => { panic!(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ffi functions
|
/// ffi functions
|
||||||
@ -167,7 +173,7 @@ pub mod ffi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern fn env_sload(env: *mut EnvHandle, index: *const JitI256, out_value: *mut JitI256) {
|
pub unsafe extern fn env_sload(env: *const EnvHandle, index: *const JitI256, out_value: *mut JitI256) {
|
||||||
let env = &*env;
|
let env = &*env;
|
||||||
env.sload(index, out_value);
|
env.sload(index, out_value);
|
||||||
}
|
}
|
||||||
@ -179,13 +185,15 @@ pub mod ffi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn env_balance(_env: *mut EnvHandle, _address: *const JitI256, _value: *const JitI256) {
|
pub unsafe extern fn env_balance(env: *const EnvHandle, address: *const JitI256, out_value: *mut JitI256) {
|
||||||
unimplemented!()
|
let env = &*env;
|
||||||
|
env.balance(address, out_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn env_blockhash(_env: *mut EnvHandle, _number: *const JitI256, _hash: *const JitI256) {
|
pub unsafe extern fn env_blockhash(env: *const EnvHandle, number: *const JitI256, out_hash: *mut JitI256) {
|
||||||
unimplemented!()
|
let env = &*env;
|
||||||
|
env.blockhash(number, out_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
Loading…
Reference in New Issue
Block a user