Skip to content

Commit

Permalink
Rename EvmcResult to ExecutionResultP
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelang committed Mar 13, 2019
1 parent 9c282e6 commit b354de9
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ pub use evmc_sys as ffi;
// TODO: Add a derive macro here for creating evmc_create

/// EVMC result structure.
pub struct EvmcResult(Box<ffi::evmc_result>);
pub struct ExecutionResult(Box<ffi::evmc_result>);

impl EvmcResult {
impl ExecutionResult {
/// Initialize a new result struct given a status code, remaining gas, and optional output
/// data.
pub fn new(status: ffi::evmc_status_code, gasleft: i64, output: Option<&[u8]>) -> Self {
EvmcResult(Box::new(ffi::evmc_result {
ExecutionResult(Box::new(ffi::evmc_result {
status_code: status,
gas_left: gasleft,
output_data: if let Some(buf) = output {
buf.clone().as_ptr()
Box::into_raw(Box::new(buf)) as *const u8
} else {
std::ptr::null()
},
Expand All @@ -32,7 +32,7 @@ impl EvmcResult {
self.0.gas_left
}

/// Get the address of the created contract. Does not return valid data if the transaction was
/// Get the address of the created contract. May not return valid data if the transaction was
/// not a contract creation.
pub fn create_addr(&self) -> &ffi::evmc_address {
&self.0.create_address
Expand Down Expand Up @@ -61,7 +61,7 @@ impl EvmcResult {

/// Construct from a box containing the raw result struct.
pub fn from_boxed(inner: Box<ffi::evmc_result>) -> Self {
EvmcResult(inner)
ExecutionResult(inner)
}

/// Consume the struct and return a pointer to the raw result struct.
Expand All @@ -71,7 +71,7 @@ impl EvmcResult {

/// Construct from a pointer to the raw result struct.
pub fn from_raw(raw: *mut ffi::evmc_result) -> Self {
unsafe { EvmcResult::from_boxed(Box::from_raw(raw)) }
unsafe { ExecutionResult::from_boxed(Box::from_raw(raw)) }
}
}

Expand All @@ -89,7 +89,7 @@ mod tests {

#[test]
fn constructor() {
let result = EvmcResult::new(
let result = ExecutionResult::new(
ffi::evmc_status_code::EVMC_SUCCESS,
420,
Some(&[0xde, 0xad, 0xbe, 0xef]),
Expand All @@ -103,13 +103,13 @@ mod tests {

#[test]
fn inner() {
let result = EvmcResult::new(
let result = ExecutionResult::new(
ffi::evmc_status_code::EVMC_SUCCESS,
420,
Some(&[0xde, 0xad, 0xbe, 0xef]),
);
let inner = result.into_inner();
let back = EvmcResult::from_boxed(inner);
let back = ExecutionResult::from_boxed(inner);
assert!(back.status() == ffi::evmc_status_code::EVMC_SUCCESS);
assert!(back.gasleft() == 420);
assert!(back.output().is_some());
Expand All @@ -119,13 +119,13 @@ mod tests {

#[test]
fn raw() {
let result = EvmcResult::new(
let result = ExecutionResult::new(
ffi::evmc_status_code::EVMC_SUCCESS,
420,
Some(&[0xde, 0xad, 0xbe, 0xef]),
);
let raw = result.into_raw() as *mut ffi::evmc_result;
let back = EvmcResult::from_raw(raw);
let back = ExecutionResult::from_raw(raw);
assert!(back.status() == ffi::evmc_status_code::EVMC_SUCCESS);
assert!(back.gasleft() == 420);
assert!(back.output().is_some());
Expand Down

0 comments on commit b354de9

Please sign in to comment.