Skip to content

Commit

Permalink
Merge pull request #297 from ethereum/rust-result
Browse files Browse the repository at this point in the history
rust: add failure() and success() helpers to ExecutionResult
  • Loading branch information
axic authored May 30, 2019
2 parents 1ca32bf + 4eeb42d commit f12ea3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 8 additions & 0 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ impl ExecutionResult {
}
}

pub fn failure() -> Self {
ExecutionResult::new(ffi::evmc_status_code::EVMC_FAILURE, 0, None)
}

pub fn success(_gas_left: i64, _output: Option<Vec<u8>>) -> Self {
ExecutionResult::new(ffi::evmc_status_code::EVMC_SUCCESS, _gas_left, _output)
}

pub fn get_status_code(&self) -> ffi::evmc_status_code {
self.status_code
}
Expand Down
9 changes: 2 additions & 7 deletions examples/example-rust-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ extern "C" fn execute(
let is_create = execution_ctx.get_message().kind == ffi::evmc_call_kind::EVMC_CREATE;

if is_create {
evmc_vm::ExecutionResult::new(ffi::evmc_status_code::EVMC_FAILURE, 0, None).into()
ExecutionResult::failure().into()
} else {
evmc_vm::ExecutionResult::new(
ffi::evmc_status_code::EVMC_SUCCESS,
66,
Some(vec![0xc0, 0xff, 0xee]),
)
.into()
ExecutionResult::success(66, Some(vec![0xc0, 0xff, 0xee])).into()
}
}

Expand Down

0 comments on commit f12ea3d

Please sign in to comment.