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); + } +}