Skip to content

Commit

Permalink
rust: reorganize alias types
Browse files Browse the repository at this point in the history
1. remove duplicate types
2. add an alias type Capabilities in evmc-vm
  • Loading branch information
CaptainVincent committed Jul 20, 2020
1 parent e35812f commit f726610
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion bindings/rust/evmc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ edition = "2018"

[dependencies]
evmc-sys = { path = "../evmc-sys", version = "7.4.0" }
libloading = "0.5"
evmc-vm = { path = "../evmc-vm", version = "7.4.0" }
libloading = "0.5"
2 changes: 1 addition & 1 deletion bindings/rust/evmc-client/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub trait HostInterface {
fn emit_log(&mut self, addr: &Address, topics: &Vec<Bytes32>, data: &Bytes);
fn call(
&mut self,
kind: CallKind,
kind: MessageKind,
destination: &Address,
sender: &Address,
value: &Bytes32,
Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/evmc-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl EvmcVm {
&self,
host_interface: Box<dyn host::HostInterface>,
rev: Revision,
kind: CallKind,
kind: MessageKind,
is_static: bool,
depth: i32,
gas: i64,
Expand Down
8 changes: 1 addition & 7 deletions bindings/rust/evmc-client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
* Licensed under the Apache License, Version 2.0.
*/

pub use evmc_sys as ffi;
pub use evmc_vm::{Capabilities, MessageKind, Revision, StatusCode, StorageStatus};

pub const ADDRESS_LENGTH: usize = 20;
pub const BYTES32_LENGTH: usize = 32;
pub type Address = [u8; ADDRESS_LENGTH];
pub type Bytes32 = [u8; BYTES32_LENGTH];
pub type Bytes = [u8];

pub type StorageStatus = ffi::evmc_storage_status;
pub type CallKind = ffi::evmc_call_kind;
pub type Revision = ffi::evmc_revision;
pub type StatusCode = ffi::evmc_status_code;
pub type Capabilities = ffi::evmc_capabilities;
19 changes: 19 additions & 0 deletions bindings/rust/evmc-vm/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub type MessageKind = ffi::evmc_call_kind;
/// EVMC message (call) flags.
pub type MessageFlags = ffi::evmc_flags;

/// EVMC VM capabilities.
pub type Capabilities = ffi::evmc_capabilities;

/// EVMC status code.
pub type StatusCode = ffi::evmc_status_code;

Expand Down Expand Up @@ -69,6 +72,22 @@ mod tests {
assert_eq!(MessageFlags::EVMC_STATIC, ffi::evmc_flags::EVMC_STATIC);
}

#[test]
fn capabilities() {
assert_eq!(
Capabilities::EVMC_CAPABILITY_EVM1,
ffi::evmc_capabilities::EVMC_CAPABILITY_EVM1
);
assert_eq!(
Capabilities::EVMC_CAPABILITY_EWASM,
ffi::evmc_capabilities::EVMC_CAPABILITY_EWASM
);
assert_eq!(
Capabilities::EVMC_CAPABILITY_PRECOMPILES,
ffi::evmc_capabilities::EVMC_CAPABILITY_PRECOMPILES
);
}

#[test]
fn status_code() {
assert_eq!(
Expand Down

0 comments on commit f726610

Please sign in to comment.