From 8c6a7cef1f43ef435e5f7ca2e886f78feead7afd Mon Sep 17 00:00:00 2001 From: Jake Lang Date: Wed, 13 Mar 2019 11:16:47 -0400 Subject: [PATCH] Add high-level result interface --- .codespell-whitelist | 1 + bindings/rust/evmc-vm/src/lib.rs | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/.codespell-whitelist b/.codespell-whitelist index 0aa9bbca2..ddc16b0ef 100644 --- a/.codespell-whitelist +++ b/.codespell-whitelist @@ -1 +1,2 @@ iff +mut diff --git a/bindings/rust/evmc-vm/src/lib.rs b/bindings/rust/evmc-vm/src/lib.rs index 37a7e1f8a..fc86abfe0 100644 --- a/bindings/rust/evmc-vm/src/lib.rs +++ b/bindings/rust/evmc-vm/src/lib.rs @@ -5,3 +5,41 @@ pub use evmc_sys as ffi; // TODO: Add convenient helpers for evmc_result // TODO: Add convenient helpers for evmc_execute // TODO: Add a derive macro here for creating evmc_create + +//pub fn destroy_result(&mut evmc_result) + +/// EVMC result structure. +pub struct EvmcResult(Box); + +impl EvmcResult { + pub fn new( + status: ffi::evmc_status_code, + gasleft: i64, + output: &[u8], + create_addr: Option, + ) -> Self + { + EvmcResult { + status_code: status, + gas_left: i64, + output_data: output.as_ptr(), + output_size: output.len(), + release: release_result, + create_address: if let Some(addr) = create_addr { + addr + } else { + evmc_address { + bytes: [0u8; 20], + } + }, + padding: [0u8; 4], + } + } +} + +#[no_mangle] +pub extern "C" fn release_result(result: *const ffi::evmc_result) { + unsafe { + Box::from_raw(result); + } +}