Skip to content

Commit baa76bb

Browse files
authored
Merge pull request #36 from ewasm/types
Split out EVM types into its own file
2 parents 41cad09 + 2e174a8 commit baa76bb

File tree

2 files changed

+47
-45
lines changed

2 files changed

+47
-45
lines changed

src/lib.rs

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
/// }
2020
/// ```
2121
mod native;
22+
pub mod types;
2223

2324
#[cfg(feature = "std")]
2425
use std::vec::Vec;
2526

27+
use types::*;
28+
2629
#[cfg(feature = "std")]
2730
fn unsafe_alloc_buffer(len: usize) -> Vec<u8> {
2831
let mut ret: Vec<u8> = Vec::with_capacity(len);
@@ -32,51 +35,6 @@ fn unsafe_alloc_buffer(len: usize) -> Vec<u8> {
3235
ret
3336
}
3437

35-
/// A little-endian unsigned 128-bit integer.
36-
#[derive(Default, Copy, Clone)]
37-
pub struct Uint128 {
38-
pub bytes: [u8; 16],
39-
}
40-
41-
/// A little-endian unsigned 256-bit integer.
42-
#[derive(Default, Copy, Clone)]
43-
pub struct Uint256 {
44-
pub bytes: [u8; 32],
45-
}
46-
47-
/// An array of 160 bits.
48-
#[derive(Default, Copy, Clone)]
49-
pub struct Bytes20 {
50-
pub bytes: [u8; 20],
51-
}
52-
53-
/// An array of 256 bits.
54-
#[derive(Default, Copy, Clone)]
55-
pub struct Bytes32 {
56-
pub bytes: [u8; 32],
57-
}
58-
59-
/// Type representing a value in wei.
60-
pub type EtherValue = Uint128;
61-
62-
/// Type representing an address.
63-
pub type Address = Bytes20;
64-
65-
/// Type representing a storage key.
66-
pub type StorageKey = Bytes32;
67-
68-
/// Type representing a storage value.
69-
pub type StorageValue = Bytes32;
70-
71-
/// Type representing a log topic.
72-
pub type Topic = Bytes32;
73-
74-
/// Type representing a Keccak-256 or SHA-256 hash.
75-
pub type Hash = Bytes32;
76-
77-
/// Type representing a block's difficulty.
78-
pub type Difficulty = Uint256;
79-
8038
/// Enum representing an error code for EEI calls. Currently used by `codeCopy`, `callDataCopy`,
8139
/// `externalCodeCopy`, and `returnDataCopy`.
8240
pub enum Error {

src/types.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/// A little-endian unsigned 128-bit integer.
2+
#[derive(Default, Copy, Clone)]
3+
pub struct Uint128 {
4+
pub bytes: [u8; 16],
5+
}
6+
7+
/// A little-endian unsigned 256-bit integer.
8+
#[derive(Default, Copy, Clone)]
9+
pub struct Uint256 {
10+
pub bytes: [u8; 32],
11+
}
12+
13+
/// An array of 160 bits.
14+
#[derive(Default, Copy, Clone)]
15+
pub struct Bytes20 {
16+
pub bytes: [u8; 20],
17+
}
18+
19+
/// An array of 256 bits.
20+
#[derive(Default, Copy, Clone)]
21+
pub struct Bytes32 {
22+
pub bytes: [u8; 32],
23+
}
24+
25+
/// Type representing a value in wei.
26+
pub type EtherValue = Uint128;
27+
28+
/// Type representing an address.
29+
pub type Address = Bytes20;
30+
31+
/// Type representing a storage key.
32+
pub type StorageKey = Bytes32;
33+
34+
/// Type representing a storage value.
35+
pub type StorageValue = Bytes32;
36+
37+
/// Type representing a log topic.
38+
pub type Topic = Bytes32;
39+
40+
/// Type representing a Keccak-256 or SHA-256 hash.
41+
pub type Hash = Bytes32;
42+
43+
/// Type representing a block's difficulty.
44+
pub type Difficulty = Uint256;

0 commit comments

Comments
 (0)