Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: remove unneeded mutability in ExecutionContext #444

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 functions in `ExecutionContext` 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