Skip to content

Commit

Permalink
Add high-level result interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelang committed Mar 13, 2019
1 parent 139985d commit 8c6a7ce
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions .codespell-whitelist
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
iff
mut
38 changes: 38 additions & 0 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ffi::evmc_result>);

impl EvmcResult {
pub fn new(
status: ffi::evmc_status_code,
gasleft: i64,
output: &[u8],
create_addr: Option<ffi::evmc_address>,
) -> 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);
}
}

0 comments on commit 8c6a7ce

Please sign in to comment.