From b723c11539999c25319c5157e05ef3cf918823be Mon Sep 17 00:00:00 2001 From: Jake Lang Date: Mon, 13 Aug 2018 09:20:22 -0400 Subject: [PATCH] add more type aliases --- src/lib.rs | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9e8dda4..671660a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,6 +44,11 @@ fn unsafe_alloc_buffer(len: usize) -> Vec { ret } +#[derive(Copy, Clone)] +pub struct Uint128 { + pub bytes: [u8; 16], +} + #[derive(Copy, Clone)] pub struct Uint160 { pub bytes: [u8; 20], @@ -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; @@ -77,25 +79,25 @@ impl 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], } } @@ -126,7 +128,7 @@ 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); @@ -134,8 +136,8 @@ pub fn current_address() -> Address { 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);