EEVM.WorldState (eevm v0.1.0)

Copy Markdown View Source

Minimal world/account state used for external account lookups (EXTCODESIZE, EXTCODECOPY, EXTCODEHASH).

Each account can include :balance, :nonce, :code, and :storage. Missing accounts behave like non-existent EVM accounts: no code and zero balance.

Summary

Types

account()

@type account() :: %{
  optional(:balance) => non_neg_integer(),
  optional(:nonce) => non_neg_integer(),
  optional(:code) => binary(),
  optional(:storage) => EEVM.Storage.t()
}

t()

@type t() :: %EEVM.WorldState{accounts: %{required(non_neg_integer()) => account()}}

Functions

account_exists?(world_state, address)

@spec account_exists?(t(), non_neg_integer()) :: boolean()

delete_account(world_state, address)

@spec delete_account(t(), non_neg_integer()) :: t()

Removes an account entirely from the world state.

Used by SELFDESTRUCT under EIP-6780: when a contract is created and self-destructed within the same transaction, the account is fully deleted (balance, nonce, code, and storage are all removed).

get_account(world_state, address)

@spec get_account(t(), non_neg_integer()) :: account() | nil

get_balance(world_state, address)

@spec get_balance(t(), non_neg_integer()) :: non_neg_integer()

get_code(world_state, address)

@spec get_code(t(), non_neg_integer()) :: binary()

get_nonce(world_state, address)

@spec get_nonce(t(), non_neg_integer()) :: non_neg_integer()

increment_nonce(world_state, address)

@spec increment_nonce(t(), non_neg_integer()) :: t()

new()

@spec new() :: t()

new(accounts)

@spec new(%{optional(non_neg_integer()) => account()}) :: t()

put_account(world_state, address, account)

@spec put_account(t(), non_neg_integer(), account()) :: t()

put_code(world_state, address, code)

@spec put_code(t(), non_neg_integer(), binary()) :: t()

set_balance(world_state, address, balance)

@spec set_balance(t(), non_neg_integer(), non_neg_integer()) :: t()

set_nonce(world_state, address, nonce)

@spec set_nonce(t(), non_neg_integer(), non_neg_integer()) :: t()

transfer(world_state, from, to, amount)

@spec transfer(t(), non_neg_integer(), non_neg_integer(), non_neg_integer()) ::
  {:ok, t()} | {:error, :insufficient_balance}

update_account(world_state, address, updater)

@spec update_account(t(), non_neg_integer(), (account() -> account())) :: t()