Skip to content

Commit

Permalink
Make Backend::set_code able to fail (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas authored Nov 23, 2023
1 parent d58d203 commit 227260f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
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(())
}

0 comments on commit 227260f

Please sign in to comment.