pub struct EvmState {
pub accounts: HashMap<[u8; 20], AccountState>,
pub codes: HashMap<[u8; 32], Vec<u8>>,
pub logs: Vec<Log>,
pub static_mode: bool,
pub provider: Option<Provider<Http>>,
}
Expand description
Represents the state of the Ethereum Virtual Machine (EVM).
Fields§
§accounts: HashMap<[u8; 20], AccountState>
A mapping of account addresses to their respective account states.
codes: HashMap<[u8; 32], Vec<u8>>
A mapping of code hashes to their respective code.
logs: Vec<Log>
A vector of logs generated during the execution of the EVM.
static_mode: bool
A flag indicating whether the EVM is in static mode or not.
provider: Option<Provider<Http>>
An optional provider for interacting with the Ethereum network.
Implementations§
Source§impl EvmState
Implementation of the EVM state.
impl EvmState
Implementation of the EVM state.
Sourcepub fn transfer(
&mut self,
from: [u8; 20],
to: [u8; 20],
value: [u8; 32],
) -> Result<(), ExecutionError>
pub fn transfer( &mut self, from: [u8; 20], to: [u8; 20], value: [u8; 32], ) -> Result<(), ExecutionError>
Transfers a given value from one account to another.
§Arguments
from
- An array of 20 bytes representing the address of the account to transfer from.to
- An array of 20 bytes representing the address of the account to transfer to.value
- An array of 32 bytes representing the value to transfer.
§Errors
Returns an ExecutionError
if:
- The static mode is enabled (static call).
- The account to transfer from does not exist.
- The account to transfer to does not exist.
- The balance of the account to transfer from is insufficient.
§Returns
Returns Ok(())
if the transfer was successful.
Sourcepub fn sload(
&mut self,
account: [u8; 20],
slot: [u8; 32],
) -> Result<[u8; 32], ExecutionError>
pub fn sload( &mut self, account: [u8; 20], slot: [u8; 32], ) -> Result<[u8; 32], ExecutionError>
Loads a 256-bit value from the storage of the given account at the given slot. If the account is not found in the emulator’s local state, the storage value is fetched from the provider. If the provider is not set, or if the storage fetch fails, the function returns a zero-filled 256-bit value.
§Arguments
account
- An array of 20 bytes representing the address of the account to load from.slot
- An array of 32 bytes representing the slot to load from.
§Errors
Never return an error, but returns a 32-byte array of zero instead.
§Returns
Returns a 32-byte array representing the value at the given slot.
Sourcepub fn sstore(
&mut self,
account: [u8; 20],
slot: [u8; 32],
value: [u8; 32],
) -> Result<(), ExecutionError>
pub fn sstore( &mut self, account: [u8; 20], slot: [u8; 32], value: [u8; 32], ) -> Result<(), ExecutionError>
Stores a value in the storage of an account.
§Arguments
account
- The address of the account to store the value in.slot
- The slot in the storage to store the value in.value
- The value to store in the specified slot.
§Errors
Returns an ExecutionError
if the static mode is enabled or if the account is not found.
Sourcepub fn get_code_at(
&mut self,
address: [u8; 20],
) -> Result<&Vec<u8>, ExecutionError>
pub fn get_code_at( &mut self, address: [u8; 20], ) -> Result<&Vec<u8>, ExecutionError>
Returns the code at the given address. If the code is not already in the state, it will be fetched from the blockchain using the provider.
§Arguments
address
- The address of the contract to get the code for.
§Errors
Returns an ExecutionError
if the code is not found.
§Returns
Returns a reference to the Vec
Sourcepub fn put_code_at(
&mut self,
address: [u8; 20],
code: Vec<u8>,
) -> Result<(), ExecutionError>
pub fn put_code_at( &mut self, address: [u8; 20], code: Vec<u8>, ) -> Result<(), ExecutionError>
Stores the code of an account at the given address.
§Arguments
address
- A 20-byte array representing the address of the account.code
- A vector of bytes representing the code to be stored.
§Errors
Returns an ExecutionError
if the account is not found.
§Returns
Returns Ok(())
if the code is successfully stored.
Sourcepub fn debug_state(&mut self)
pub fn debug_state(&mut self)
Print the state of the EVM This function is used for debugging purposes.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for EvmState
impl !RefUnwindSafe for EvmState
impl Send for EvmState
impl Sync for EvmState
impl Unpin for EvmState
impl !UnwindSafe for EvmState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.