evm v0.1.14 EVM.Operation.System
Link to this section Summary
Functions
Message-call into an account. Transfer value
wei from callers account to callees account then run the code in that account
Create a new account with associated code
Halt execution returning output data,
Halt execution and register account for later deletion
Link to this section Functions
Link to this function
call(list, map)
call(Operation.stack_args, Operation.vm_map) :: Operation.op_result
Message-call into an account. Transfer value
wei from callers account to callees account then run the code in that account.
## Examples
iex> account_map = %{
...> <<0::160>> => %{balance: 100, nonce: 5, code: <<>>},
...> <<1::160>> => %{balance: 100, nonce: 5, code: <<>>},
...> <<2::160>> => %{balance: 100, nonce: 5, code: <<>>},
...> }
iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(account_map)
iex> exec_env = %EVM.ExecEnv{
...> account_interface: account_interface,
...> sender: <<0::160>>,
...> address: <<0::160>>
...> }
iex> machine_state = %EVM.MachineState{gas: 1000}
iex> %{machine_state: machine_state, exec_env: exec_env} =
...> EVM.Operation.System.call([10, 1, 1, 0, 0, 0, 0],
...> %{exec_env: exec_env, machine_state: machine_state})
iex> EVM.Stack.peek(machine_state.stack)
1
iex> exec_env.account_interface
...> |> EVM.Interface.AccountInterface.get_account_balance(<<0::160>>)
99
iex> exec_env.account_interface
...> |> EVM.Interface.AccountInterface.get_account_balance(<<1::160>>)
101
Link to this function
create(list, map)
create(Operation.stack_args, Operation.vm_map) :: Operation.op_result
Create a new account with associated code.
Examples
iex> block_interface = EVM.Interface.Mock.MockBlockInterface.new(%Block.Header{})
iex> account_map = %{<<100::160>> => %{balance: 5_000, nonce: 5}}
iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(account_map, %{gas: 500, sub_state: nil, output: "output"})
iex> exec_env = %EVM.ExecEnv{stack_depth: 0, address: <<100::160>>, account_interface: account_interface, block_interface: block_interface}
iex> machine_state = %EVM.MachineState{gas: 300, stack: [1], memory: "________" <> "input"}
iex> %{machine_state: n_machine_state} =
...> EVM.Operation.System.create(
...> [1_000, 5, 5],
...> %{exec_env: exec_env, machine_state: machine_state})
iex> n_machine_state
%EVM.MachineState{gas: 800, stack: [0x601bcc2189b7096d8dfaa6f74efeebef20486d0d, 1], active_words: 1, memory: "________input"}
Link to this function
return(list, map)
return(Operation.stack_args, Operation.vm_map) :: Operation.op_result
Halt execution returning output data,
Examples
iex> EVM.Operation.System.return([5, 33], %{machine_state: %EVM.MachineState{active_words: 0}})
%EVM.MachineState{active_words: 2}
iex> EVM.Operation.System.return([5, 33], %{machine_state: %EVM.MachineState{active_words: 5}})
%EVM.MachineState{active_words: 5}
Link to this function
suicide(list, map)
suicide(Operation.stack_args, Operation.vm_map) :: Operation.op_result
Halt execution and register account for later deletion.
Examples
iex> address = 0x0000000000000000000000000000000000000001
iex> suicide_address = 0x0000000000000000000000000000000000000001
iex> account_map = %{address => %{balance: 5_000, nonce: 5}}
iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(account_map)
iex> account_interface = EVM.Operation.System.suicide([suicide_address], %{stack: [], exec_env: %EVM.ExecEnv{address: address, account_interface: account_interface} })[:exec_env].account_interface
iex> account_interface |> EVM.Interface.AccountInterface.dump_storage |> Map.get(address)
nil