Struct evm::Machine
[−]
[src]
pub struct Machine<M, P: Patch> { /* fields omitted */ }
A VM state with PC.
Methods
impl<M: Memory + Default, P: Patch> Machine<M, P>
[src]
Lifecycle of a Machine
When a new non-invoked transaction is created, initialize_call
or initialize_create
should be called. After this, the machine
can be stepped as normal. When the machine meets a CALL/CALLCODE
or CREATE instruction, a sub-machine will be created. This
submachine should first call invoke_call
or
invoke_create
. After the submachine is finished, it should call
apply_sub
. When the non-invoked transaction is finished, it
should first call code_deposit
if it is a contract creation
transaction. After that, it should call finalize
.
fn initialize_call(&mut self, preclaimed_value: U256)
[src]
Initialize a MessageCall transaction.
fn invoke_call(&mut self)
[src]
Initialize the runtime as a call from a CALL or CALLCODE opcode.
fn initialize_create(
&mut self,
preclaimed_value: U256
) -> Result<(), RequireError>
[src]
&mut self,
preclaimed_value: U256
) -> Result<(), RequireError>
Initialize a ContractCreation transaction.
fn invoke_create(&mut self) -> Result<(), RequireError>
[src]
Initialize the runtime as a call from a CREATE opcode.
fn code_deposit(&mut self)
[src]
Deposit code for a ContractCreation transaction or a CREATE opcode.
fn finalize(
&mut self,
real_used_gas: Gas,
preclaimed_value: U256,
fresh_account_state: &AccountState
) -> Result<(), RequireError>
[src]
&mut self,
real_used_gas: Gas,
preclaimed_value: U256,
fresh_account_state: &AccountState
) -> Result<(), RequireError>
Finalize a transaction. This should not be used when invoked by an opcode.
fn apply_sub(&mut self, sub: Machine<M, P>)
[src]
Apply a sub runtime into the current runtime. This sub runtime
should have been created by the current runtime's derive
function. Depending whether the current runtime is invoking a
ContractCreation or MessageCall instruction, it will apply
various states back.
impl<M: Memory + Default, P: Patch> Machine<M, P>
[src]
fn new(context: Context, block: HeaderParams, depth: usize) -> Self
[src]
Create a new runtime.
fn with_states(
context: Context,
block: HeaderParams,
depth: usize,
account_state: AccountState,
blockhash_state: BlockhashState
) -> Self
[src]
context: Context,
block: HeaderParams,
depth: usize,
account_state: AccountState,
blockhash_state: BlockhashState
) -> Self
Create a new runtime with the given states.
fn derive(&self, context: Context) -> Self
[src]
Derive this runtime to create a sub runtime. This will not modify the current runtime, and it will have a chance to review whether it wants to accept the result of this sub runtime afterwards.
fn commit_account(
&mut self,
commitment: AccountCommitment
) -> Result<(), CommitError>
[src]
&mut self,
commitment: AccountCommitment
) -> Result<(), CommitError>
Commit a new account into this runtime.
fn commit_blockhash(
&mut self,
number: U256,
hash: H256
) -> Result<(), CommitError>
[src]
&mut self,
number: U256,
hash: H256
) -> Result<(), CommitError>
Commit a new blockhash into this runtime.
fn check(&self) -> Result<(), EvalError>
[src]
Check the next instruction about whether it will return errors.
fn step_precompiled(&mut self) -> bool
[src]
Step a precompiled runtime. This function returns true if the runtime is indeed a precompiled address. Otherwise return false with state unchanged.
fn step(&mut self) -> Result<(), RequireError>
[src]
Step an instruction in the PC. The eval result is refected by the runtime status, and it will only return an error if there're accounts or blockhashes to be committed to this runtime for it to run. In that case, the state of the current runtime will not be affected.
fn state(&self) -> &State<M>
[src]
Get the runtime state.
fn status(&self) -> MachineStatus
[src]
Get the current runtime status.