Skip to content

Commit

Permalink
refactor all EEI methods to use new types
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelang committed Aug 16, 2018
1 parent b723c11 commit 73ad8e4
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub enum CallResult {
}

pub enum CreateResult {
Successful([u8;20]),
Successful([u8; 20]),
Failure,
Revert
}
Expand All @@ -136,7 +136,7 @@ pub fn current_address() -> Address {
ret
}

pub fn external_balance(address: Address) -> EtherValue {
pub fn external_balance(address: &Address) -> EtherValue {
let ret = EtherValue::new();

unsafe {
Expand All @@ -145,20 +145,20 @@ pub fn external_balance(address: Address) -> EtherValue {
ret
}

pub fn block_coinbase() -> [u8;20] {
let mut ret = [0u8;20];
pub fn block_coinbase() -> Address {
let ret = Address::new();

unsafe {
ethereum_getBlockCoinbase(ret.as_mut_ptr() as *const u32);
ethereum_getBlockCoinbase(ret.as_raw_ptr() as *const u32);
}
ret
}

pub fn block_difficulty() -> [u8;32] {
let mut ret = [0u8;32];
pub fn block_difficulty() -> Uint256 {
let ret = Uint256::new();

unsafe {
ethereum_getBlockDifficulty(ret.as_mut_ptr() as *const u32);
ethereum_getBlockDifficulty(ret.as_raw_ptr() as *const u32);
}
ret
}
Expand All @@ -169,11 +169,11 @@ pub fn block_gas_limit() -> u64 {
}
}

pub fn block_hash(number: u64) -> [u8;32] {
let mut ret = [0u8;32];
pub fn block_hash(number: u64) -> Hash {
let ret = Hash::new();

unsafe {
ethereum_getBlockHash(number, ret.as_mut_ptr() as *const u32);
ethereum_getBlockHash(number, ret.as_raw_ptr() as *const u32);
}
ret
}
Expand All @@ -190,20 +190,20 @@ pub fn block_timestamp() -> u64 {
}
}

pub fn tx_gas_price() -> [u8;16] {
let mut ret = [0u8;16];
pub fn tx_gas_price() -> EtherValue {
let ret = EtherValue::new();

unsafe {
ethereum_getTxGasPrice(ret.as_mut_ptr() as *const u32);
ethereum_getTxGasPrice(ret.as_raw_ptr() as *const u32);
}
ret
}

pub fn tx_origin() -> [u8;20] {
let mut ret = [0u8;20];
pub fn tx_origin() -> Address {
let ret = Address::new();

unsafe {
ethereum_getTxOrigin(ret.as_mut_ptr() as *const u32);
ethereum_getTxOrigin(ret.as_raw_ptr() as *const u32);
}
ret
}
Expand Down Expand Up @@ -242,12 +242,12 @@ pub fn log4(data: &[u8], topic1: [u8;32], topic2: [u8;32], topic3: [u8;32], topi
log(data, 4, topic1.as_ptr() as *const u8, topic2.as_ptr() as *const u8, topic3.as_ptr() as *const u8, topic4.as_ptr() as *const u8)
}

pub fn call_mutable(gas_limit: u64, address: &[u8;20], value: &[u8;16], data: &[u8]) -> CallResult {
pub fn call_mutable(gas_limit: u64, address: &Address, value: &EtherValue, data: &[u8]) -> CallResult {
let ret = unsafe {
ethereum_call(
gas_limit,
address.as_ptr() as *const u32,
value.as_ptr() as *const u32,
address.as_raw_ptr() as *const u32,
value.as_raw_ptr() as *const u32,
data.as_ptr() as *const u32,
data.len() as u32
)
Expand All @@ -261,12 +261,12 @@ pub fn call_mutable(gas_limit: u64, address: &[u8;20], value: &[u8;16], data: &[
}
}

pub fn call_code(gas_limit: u64, address: &[u8;20], value: &[u8;16], data: &[u8]) -> CallResult {
pub fn call_code(gas_limit: u64, address: &Address, value: &EtherValue, data: &[u8]) -> CallResult {
let ret = unsafe {
ethereum_callCode(
gas_limit,
address.as_ptr() as *const u32,
value.as_ptr() as *const u32,
address.as_raw_ptr() as *const u32,
value.as_raw_ptr() as *const u32,
data.as_ptr() as *const u32,
data.len() as u32
)
Expand All @@ -280,11 +280,11 @@ pub fn call_code(gas_limit: u64, address: &[u8;20], value: &[u8;16], data: &[u8]
}
}

pub fn call_delegate(gas_limit: u64, address: &[u8;20], data: &[u8]) -> CallResult {
pub fn call_delegate(gas_limit: u64, address: &Address, data: &[u8]) -> CallResult {
let ret = unsafe {
ethereum_callDelegate(
gas_limit,
address.as_ptr() as *const u32,
address.as_raw_ptr() as *const u32,
data.as_ptr() as *const u32,
data.len() as u32
)
Expand All @@ -299,11 +299,11 @@ pub fn call_delegate(gas_limit: u64, address: &[u8;20], data: &[u8]) -> CallResu
}
}

pub fn call_static(gas_limit: u64, address: &[u8;20], data: &[u8]) -> CallResult {
pub fn call_static(gas_limit: u64, address: &Address, data: &[u8]) -> CallResult {
let ret = unsafe {
ethereum_callStatic(
gas_limit,
address.as_ptr() as *const u32,
address.as_raw_ptr() as *const u32,
data.as_ptr() as *const u32,
data.len() as u32
)
Expand All @@ -317,12 +317,12 @@ pub fn call_static(gas_limit: u64, address: &[u8;20], data: &[u8]) -> CallResult
}
}

pub fn create(value: &[u8;16], data: &[u8]) -> CreateResult {
let mut result = [0u8;20];
pub fn create(value: &EtherValue, data: &[u8]) -> CreateResult {
let mut result = [0u8; 20];

let ret = unsafe {
ethereum_create(
value.as_ptr() as *const u32,
value.as_raw_ptr() as *const u32,
data.as_ptr() as *const u32,
data.len() as u32,
result.as_mut_ptr() as *const u32
Expand Down Expand Up @@ -352,20 +352,20 @@ pub fn calldata_size() -> usize {
}
}

pub fn caller() -> [u8;20] {
let mut ret = [0u8;20];
pub fn caller() -> Address {
let ret = Address::new();

unsafe {
ethereum_getCaller(ret.as_mut_ptr() as *const u32);
ethereum_getCaller(ret.as_raw_ptr() as *const u32);
}
ret
}

pub fn callvalue() -> [u8;16] {
let mut ret = [0u8;16];
pub fn callvalue() -> EtherValue {
let ret = EtherValue::new();

unsafe {
ethereum_getCallValue(ret.as_mut_ptr() as *const u32);
ethereum_getCallValue(ret.as_raw_ptr() as *const u32);
}
ret
}
Expand All @@ -385,18 +385,18 @@ pub fn code_size() -> usize {
}
}

pub fn external_code_copy(address: &[u8;20], from: usize, length: usize) -> Vec<u8> {
pub fn external_code_copy(address: &Address, from: usize, length: usize) -> Vec<u8> {
let mut ret: Vec<u8> = unsafe_alloc_buffer(length);

unsafe {
ethereum_externalCodeCopy(address.as_ptr() as *const u32, ret.as_mut_ptr() as *const u32, from as u32, length as u32);
ethereum_externalCodeCopy(address.as_raw_ptr() as *const u32, ret.as_mut_ptr() as *const u32, from as u32, length as u32);
}
ret
}

pub fn external_code_size(address: &[u8;20]) -> usize {
pub fn external_code_size(address: &Address) -> usize {
unsafe {
ethereum_getExternalCodeSize(address.as_ptr() as *const u32) as usize
ethereum_getExternalCodeSize(address.as_raw_ptr() as *const u32) as usize
}
}

Expand Down Expand Up @@ -439,23 +439,23 @@ pub fn finish_data(data: &[u8]) -> ! {
}
}

pub fn storage_load(key: &[u8;32]) -> [u8;32] {
let mut ret = [0u8;32];
pub fn storage_load(key: &StorageKey) -> StorageValue {
let ret = StorageValue::new();

unsafe {
ethereum_storageLoad(key.as_ptr() as *const u32, ret.as_mut_ptr() as *const u32);
ethereum_storageLoad(key.as_raw_ptr() as *const u32, ret.as_raw_ptr() as *const u32);
}
ret
}

pub fn storage_store(key: &[u8;32], value: &[u8;32]) {
pub fn storage_store(key: &StorageKey, value: &StorageValue) {
unsafe {
ethereum_storageStore(key.as_ptr() as *const u32, value.as_ptr() as *const u32);
ethereum_storageStore(key.as_raw_ptr() as *const u32, value.as_raw_ptr() as *const u32);
}
}

pub fn selfdestruct(address: &[u8; 20]) -> ! {
pub fn selfdestruct(address: &Address) -> ! {
unsafe {
ethereum_selfDestruct(address.as_ptr() as *const u32);
ethereum_selfDestruct(address.as_raw_ptr() as *const u32);
}
}

0 comments on commit 73ad8e4

Please sign in to comment.