mirror of https://github.com/status-im/evmc.git
rust: prefer getters as opposed to pub members on structs
This commit is contained in:
parent
31e6964b04
commit
315137edd2
|
@ -23,15 +23,15 @@ pub struct ExecutionResult {
|
|||
|
||||
/// EVMC execution message structure.
|
||||
pub struct ExecutionMessage {
|
||||
pub kind: ffi::evmc_call_kind,
|
||||
pub flags: u32,
|
||||
pub depth: i32,
|
||||
pub gas: i64,
|
||||
pub destination: ffi::evmc_address,
|
||||
pub sender: ffi::evmc_address,
|
||||
pub input: Option<Vec<u8>>,
|
||||
pub value: ffi::evmc_uint256be,
|
||||
pub create2_salt: ffi::evmc_bytes32,
|
||||
kind: ffi::evmc_call_kind,
|
||||
flags: u32,
|
||||
depth: i32,
|
||||
gas: i64,
|
||||
destination: ffi::evmc_address,
|
||||
sender: ffi::evmc_address,
|
||||
input: Option<Vec<u8>>,
|
||||
value: ffi::evmc_uint256be,
|
||||
create2_salt: ffi::evmc_bytes32,
|
||||
}
|
||||
|
||||
/// EVMC context structure. Exposes the EVMC host functions, message data, and transaction context
|
||||
|
@ -81,6 +81,44 @@ impl ExecutionResult {
|
|||
}
|
||||
}
|
||||
|
||||
impl ExecutionMessage {
|
||||
pub fn kind(&self) -> ffi::evmc_call_kind {
|
||||
self.kind
|
||||
}
|
||||
|
||||
pub fn flags(&self) -> u32 {
|
||||
self.flags
|
||||
}
|
||||
|
||||
pub fn depth(&self) -> i32 {
|
||||
self.depth
|
||||
}
|
||||
|
||||
pub fn gas(&self) -> i64 {
|
||||
self.gas
|
||||
}
|
||||
|
||||
pub fn destination(&self) -> &ffi::evmc_address {
|
||||
&self.destination
|
||||
}
|
||||
|
||||
pub fn sender(&self) -> &ffi::evmc_address {
|
||||
&self.sender
|
||||
}
|
||||
|
||||
pub fn input(&self) -> Option<&Vec<u8>> {
|
||||
self.input.as_ref()
|
||||
}
|
||||
|
||||
pub fn value(&self) -> &ffi::evmc_uint256be {
|
||||
&self.value
|
||||
}
|
||||
|
||||
pub fn create2_salt(&self) -> &ffi::evmc_bytes32 {
|
||||
&self.create2_salt
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExecutionContext<'a> {
|
||||
pub fn new(_message: &'a ffi::evmc_message, _context: &'a mut ffi::evmc_context) -> Self {
|
||||
let _tx_context = unsafe {
|
||||
|
@ -609,10 +647,10 @@ mod tests {
|
|||
assert_eq!(c.depth, d.depth);
|
||||
assert_eq!(c.gas, d.gas);
|
||||
if d.input_data.is_null() {
|
||||
assert!(c.input.is_none());
|
||||
assert!(c.input().is_none());
|
||||
} else {
|
||||
assert!(c.input.is_some());
|
||||
assert_eq!(c.input.clone().unwrap().len(), d.input_size);
|
||||
assert!(c.input().is_some());
|
||||
assert_eq!(c.input().unwrap().len(), d.input_size);
|
||||
}
|
||||
|
||||
dummy_context_dispose(context_raw);
|
||||
|
|
|
@ -15,7 +15,7 @@ impl EvmcVm for ExampleRustVM {
|
|||
}
|
||||
|
||||
fn execute(&self, _code: &[u8], context: &ExecutionContext) -> ExecutionResult {
|
||||
let is_create = context.get_message().kind == evmc_sys::evmc_call_kind::EVMC_CREATE;
|
||||
let is_create = context.get_message().kind() == evmc_sys::evmc_call_kind::EVMC_CREATE;
|
||||
|
||||
if is_create {
|
||||
ExecutionResult::failure()
|
||||
|
|
Loading…
Reference in New Issue