Skip to content

Commit

Permalink
add more type aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelang committed Aug 16, 2018
1 parent 7ac9942 commit b723c11
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ fn unsafe_alloc_buffer(len: usize) -> Vec<u8> {
ret
}

#[derive(Copy, Clone)]
pub struct Uint128 {
pub bytes: [u8; 16],
}

#[derive(Copy, Clone)]
pub struct Uint160 {
pub bytes: [u8; 20],
Expand All @@ -54,14 +59,11 @@ pub struct Uint256 {
pub bytes: [u8; 32],
}

#[derive(Copy, Clone)]
pub struct Uint128 {
pub bytes: [u8; 16],
}

type EtherValue = Uint128;
type Address = Uint160;
type StorageKey = Uint256;
type StorageValue = Uint256;
type Hash = Uint256;
type Value = Uint128;

trait EwasmType {
fn new() -> Self;
Expand All @@ -77,25 +79,25 @@ impl<T> RawPtr for T {
}
}

impl EwasmType for Address {
impl EwasmType for Uint128 {
fn new() -> Self {
Address {
bytes: [0; 20],
Uint128 {
bytes: [0; 16],
}
}
}

impl EwasmType for Value {
impl EwasmType for Uint160 {
fn new() -> Self {
Value {
bytes: [0; 16],
Uint160 {
bytes: [0; 20],
}
}
}

impl EwasmType for Hash {
impl EwasmType for Uint256 {
fn new() -> Self {
Hash {
Uint256 {
bytes: [0; 32],
}
}
Expand Down Expand Up @@ -126,16 +128,16 @@ pub fn gas_left() -> u64 {
}

pub fn current_address() -> Address {
let mut ret = Address::new();
let ret = Address::new();

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

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

unsafe {
ethereum_getBalance(address.as_raw_ptr() as *const u32, ret.as_raw_ptr() as *const u32);
Expand Down

0 comments on commit b723c11

Please sign in to comment.