From 864ecc738b638183409e83c5daaac8915f99de46 Mon Sep 17 00:00:00 2001 From: Jake Lang Date: Tue, 19 Mar 2019 14:31:39 -0400 Subject: [PATCH] rust: Rename members to match EVMC closely --- bindings/rust/evmc-vm/src/lib.rs | 50 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/bindings/rust/evmc-vm/src/lib.rs b/bindings/rust/evmc-vm/src/lib.rs index 855c4ef6a..5a28f55eb 100644 --- a/bindings/rust/evmc-vm/src/lib.rs +++ b/bindings/rust/evmc-vm/src/lib.rs @@ -7,43 +7,43 @@ pub use evmc_sys as ffi; /// EVMC result structure. pub struct ExecutionResult { - status: ffi::evmc_status_code, - gas: i64, + status_code: ffi::evmc_status_code, + gas_left: i64, output: Option>, - create_addr: ffi::evmc_address, + create_address: ffi::evmc_address, } impl ExecutionResult { pub fn new( - _status: ffi::evmc_status_code, - _gas: i64, + _status_code: ffi::evmc_status_code, + _gas_left: i64, _output: Option>, - _create_addr: ffi::evmc_address, + _create_address: ffi::evmc_address, ) -> Self { ExecutionResult { - status: _status, - gas: _gas, + status_code: _status_code, + gas_left: _gas_left, output: _output, - create_addr: _create_addr, + create_address: _create_address, } } - pub fn get_status(&self) -> ffi::evmc_status_code { - self.status + pub fn get_status_code(&self) -> ffi::evmc_status_code { + self.status_code } pub fn get_gas_left(&self) -> i64 { - self.gas + self.gas_left } pub fn get_output(&self) -> Option<&Vec> { self.output.as_ref() } - pub fn get_create_addr(&self) -> Option<&ffi::evmc_address> { + pub fn get_create_address(&self) -> Option<&ffi::evmc_address> { // Only return Some if the address is valid (e.g. the status is EVMC_SUCCESS) - if self.status == ffi::evmc_status_code::EVMC_SUCCESS { - Some(&self.create_addr) + if self.status_code == ffi::evmc_status_code::EVMC_SUCCESS { + Some(&self.create_address) } else { None } @@ -53,8 +53,8 @@ impl ExecutionResult { impl From for ExecutionResult { fn from(result: ffi::evmc_result) -> Self { let ret = ExecutionResult { - status: result.status_code, - gas: result.gas_left, + status_code: result.status_code, + gas_left: result.gas_left, output: if !result.output_data.is_null() { // Pre-allocate a vector. let mut buf: Vec = Vec::with_capacity(result.output_size); @@ -70,7 +70,7 @@ impl From for ExecutionResult { } else { None }, - create_addr: result.create_address, + create_address: result.create_address, }; // Release allocated ffi struct. @@ -104,12 +104,12 @@ impl Into<*const ffi::evmc_result> for ExecutionResult { }; Box::into_raw(Box::new(ffi::evmc_result { - status_code: self.status, - gas_left: self.gas, + status_code: self.status_code, + gas_left: self.gas_left, output_data: buffer, output_size: len, release: Some(release_result), - create_address: self.create_addr, + create_address: self.create_address, padding: [0u8; 4], })) } @@ -141,12 +141,12 @@ mod tests { ffi::evmc_address { bytes: [0u8; 20] }, ); - assert!(r.get_status() == ffi::evmc_status_code::EVMC_FAILURE); + assert!(r.get_status_code() == ffi::evmc_status_code::EVMC_FAILURE); assert!(r.get_gas_left() == 420); assert!(r.get_output().is_none()); // Ensure that an address is not returned if it is not valid, per status code. - assert!(r.get_create_addr().is_none()); + assert!(r.get_create_address().is_none()); } #[test] @@ -163,11 +163,11 @@ mod tests { let r: ExecutionResult = f.into(); - assert!(r.get_status() == ffi::evmc_status_code::EVMC_SUCCESS); + assert!(r.get_status_code() == ffi::evmc_status_code::EVMC_SUCCESS); assert!(r.get_gas_left() == 1337); assert!(r.get_output().is_some()); assert!(r.get_output().unwrap().len() == 4); - assert!(r.get_create_addr().is_some()); + assert!(r.get_create_address().is_some()); } #[test]