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

Make Backend::set_code able to fail #231

Merged
merged 1 commit into from
Nov 23, 2023
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
2 changes: 1 addition & 1 deletion interpreter/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub trait RuntimeBackend: RuntimeBaseBackend {
/// Fully delete storages of an account.
fn reset_storage(&mut self, address: H160);
/// Set code of an account.
fn set_code(&mut self, address: H160, code: Vec<u8>);
fn set_code(&mut self, address: H160, code: Vec<u8>) -> Result<(), ExitError>;
/// Reset balance of an account.
fn reset_balance(&mut self, address: H160);
fn deposit(&mut self, target: H160, value: U256);
Expand Down
2 changes: 1 addition & 1 deletion interpreter/tests/usability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl<'a> RuntimeBackend for UnimplementedHandler {
unimplemented!()
}

fn set_code(&mut self, _address: H160, _code: Vec<u8>) {
fn set_code(&mut self, _address: H160, _code: Vec<u8>) -> Result<(), ExitError> {
unimplemented!()
}

Expand Down
4 changes: 3 additions & 1 deletion src/backend/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,14 @@ impl RuntimeBackend for InMemoryBackend {
.storage = Default::default();
}

fn set_code(&mut self, address: H160, code: Vec<u8>) {
fn set_code(&mut self, address: H160, code: Vec<u8>) -> Result<(), ExitError> {
self.current_layer_mut()
.state
.entry(address)
.or_default()
.code = code;

Ok(())
}

fn reset_balance(&mut self, address: H160) {
Expand Down
2 changes: 1 addition & 1 deletion src/standard/invoker/routines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ where

StaticGasometer::record_codedeposit(gasometer, retbuf.len())?;

handler.set_code(address, retbuf.clone());
handler.set_code(address, retbuf.clone())?;

Ok(())
}
Loading