mirror of https://github.com/status-im/evmc.git
Merge pull request #340 from ethereum/rust-result-ref
rust: pass output as slice reference in ExecutionResult
This commit is contained in:
commit
50821813cb
|
@ -51,12 +51,16 @@ impl ExecutionResult {
|
|||
pub fn new(
|
||||
_status_code: ffi::evmc_status_code,
|
||||
_gas_left: i64,
|
||||
_output: Option<Vec<u8>>,
|
||||
_output: Option<&[u8]>,
|
||||
) -> Self {
|
||||
ExecutionResult {
|
||||
status_code: _status_code,
|
||||
gas_left: _gas_left,
|
||||
output: _output,
|
||||
output: if _output.is_some() {
|
||||
Some(_output.unwrap().to_vec())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
create_address: None,
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +69,7 @@ impl ExecutionResult {
|
|||
ExecutionResult::new(ffi::evmc_status_code::EVMC_FAILURE, 0, None)
|
||||
}
|
||||
|
||||
pub fn success(_gas_left: i64, _output: Option<Vec<u8>>) -> Self {
|
||||
pub fn success(_gas_left: i64, _output: Option<&[u8]>) -> Self {
|
||||
ExecutionResult::new(ffi::evmc_status_code::EVMC_SUCCESS, _gas_left, _output)
|
||||
}
|
||||
|
||||
|
@ -482,7 +486,7 @@ mod tests {
|
|||
let r = ExecutionResult::new(
|
||||
ffi::evmc_status_code::EVMC_FAILURE,
|
||||
420,
|
||||
Some(vec![0xc0, 0xff, 0xee, 0x71, 0x75]),
|
||||
Some(&[0xc0, 0xff, 0xee, 0x71, 0x75]),
|
||||
);
|
||||
|
||||
let f: *const ffi::evmc_result = r.into();
|
||||
|
@ -526,7 +530,7 @@ mod tests {
|
|||
let r = ExecutionResult::new(
|
||||
ffi::evmc_status_code::EVMC_FAILURE,
|
||||
420,
|
||||
Some(vec![0xc0, 0xff, 0xee, 0x71, 0x75]),
|
||||
Some(&[0xc0, 0xff, 0xee, 0x71, 0x75]),
|
||||
);
|
||||
|
||||
let f: ffi::evmc_result = r.into();
|
||||
|
|
|
@ -20,7 +20,7 @@ impl EvmcVm for ExampleRustVM {
|
|||
if is_create {
|
||||
ExecutionResult::failure()
|
||||
} else {
|
||||
ExecutionResult::success(66, Some(vec![0xc0, 0xff, 0xee]))
|
||||
ExecutionResult::success(66, Some(&[0xc0, 0xff, 0xee]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue