From 80f99dfe6bcf7f528e53eb33b2ed9b938c9b6b49 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 22 May 2019 17:30:14 +0100 Subject: [PATCH 1/2] examples: Remove explicit namespace in rust-example-vm --- examples/example-rust-vm/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/example-rust-vm/src/lib.rs b/examples/example-rust-vm/src/lib.rs index dc73e1b..23b388d 100644 --- a/examples/example-rust-vm/src/lib.rs +++ b/examples/example-rust-vm/src/lib.rs @@ -19,9 +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::new(ffi::evmc_status_code::EVMC_FAILURE, 0, None).into() } else { - evmc_vm::ExecutionResult::new( + ExecutionResult::new( ffi::evmc_status_code::EVMC_SUCCESS, 66, Some(vec![0xc0, 0xff, 0xee]), From 4eeb42d07424f7d91bad971eec5ad5e4588a51ec Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 22 May 2019 17:33:16 +0100 Subject: [PATCH 2/2] rust: add failure() and success() helpers to ExecutionResult --- bindings/rust/evmc-vm/src/lib.rs | 8 ++++++++ examples/example-rust-vm/src/lib.rs | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bindings/rust/evmc-vm/src/lib.rs b/bindings/rust/evmc-vm/src/lib.rs index cde142f..706efd7 100644 --- a/bindings/rust/evmc-vm/src/lib.rs +++ b/bindings/rust/evmc-vm/src/lib.rs @@ -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>) -> 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 } diff --git a/examples/example-rust-vm/src/lib.rs b/examples/example-rust-vm/src/lib.rs index 23b388d..9a8419c 100644 --- a/examples/example-rust-vm/src/lib.rs +++ b/examples/example-rust-vm/src/lib.rs @@ -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 { - ExecutionResult::new(ffi::evmc_status_code::EVMC_FAILURE, 0, None).into() + ExecutionResult::failure().into() } else { - ExecutionResult::new( - ffi::evmc_status_code::EVMC_SUCCESS, - 66, - Some(vec![0xc0, 0xff, 0xee]), - ) - .into() + ExecutionResult::success(66, Some(vec![0xc0, 0xff, 0xee])).into() } }