Skip to content

Commit

Permalink
rust: remove unneeded mutability in ExecutionContext
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Nov 26, 2019
1 parent e04a90e commit 8a20d5c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning].
which can be used to emulate Host behavior when testing VM implementations.
[#456](https://github.com/ethereum/evmc/pull/456)

### Changed

- In the Rust bindings mark read-only EVMC functions as non-mutating.
[#444](https://github.com/ethereum/evmc/pull/444)


## [7.0.0] „Istanbul Ready” — 2019-11-11

Expand Down
14 changes: 7 additions & 7 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ impl<'a> ExecutionContext<'a> {
}

/// Check if an account exists.
pub fn account_exists(&mut self, address: &Address) -> bool {
pub fn account_exists(&self, address: &Address) -> bool {
unsafe {
assert!((*self.host).account_exists.is_some());
(*self.host).account_exists.unwrap()(self.context, address as *const Address)
}
}

/// Read from a storage key.
pub fn get_storage(&mut self, address: &Address, key: &Bytes32) -> Bytes32 {
pub fn get_storage(&self, address: &Address, key: &Bytes32) -> Bytes32 {
unsafe {
assert!((*self.host).get_storage.is_some());
(*self.host).get_storage.unwrap()(
Expand Down Expand Up @@ -252,31 +252,31 @@ impl<'a> ExecutionContext<'a> {
}

/// Get balance of an account.
pub fn get_balance(&mut self, address: &Address) -> Uint256 {
pub fn get_balance(&self, address: &Address) -> Uint256 {
unsafe {
assert!((*self.host).get_balance.is_some());
(*self.host).get_balance.unwrap()(self.context, address as *const Address)
}
}

/// Get code size of an account.
pub fn get_code_size(&mut self, address: &Address) -> usize {
pub fn get_code_size(&self, address: &Address) -> usize {
unsafe {
assert!((*self.host).get_code_size.is_some());
(*self.host).get_code_size.unwrap()(self.context, address as *const Address)
}
}

/// Get code hash of an account.
pub fn get_code_hash(&mut self, address: &Address) -> Bytes32 {
pub fn get_code_hash(&self, address: &Address) -> Bytes32 {
unsafe {
assert!((*self.host).get_code_size.is_some());
(*self.host).get_code_hash.unwrap()(self.context, address as *const Address)
}
}

/// Copy code of an account.
pub fn copy_code(&mut self, address: &Address, code_offset: usize, buffer: &mut [u8]) -> usize {
pub fn copy_code(&self, address: &Address, code_offset: usize, buffer: &mut [u8]) -> usize {
unsafe {
assert!((*self.host).copy_code.is_some());
(*self.host).copy_code.unwrap()(
Expand Down Expand Up @@ -338,7 +338,7 @@ impl<'a> ExecutionContext<'a> {
}

/// Get block hash of an account.
pub fn get_block_hash(&mut self, num: i64) -> Bytes32 {
pub fn get_block_hash(&self, num: i64) -> Bytes32 {
unsafe {
assert!((*self.host).get_block_hash.is_some());
(*self.host).get_block_hash.unwrap()(self.context, num)
Expand Down

0 comments on commit 8a20d5c

Please sign in to comment.