EEVM.Database.InMemory (eevm v0.1.0)

Copy Markdown View Source

In-memory EEVM.Database backend backed by plain maps.

The state is a map with two keys:

  • :accounts — %{address => account_map} (balances, nonces, code)
  • :storage — %{address => %{slot => value}} (per-contract storage)

Suitable for testing and single-transaction execution. For persistent state, implement the EEVM.Database behaviour against a disk-backed store.

Summary

Functions

Creates a new in-memory database state.

Convenience: creates a fully wrapped %Database{} with InMemory backend.

Types

state()

@type state() :: %{
  accounts: %{required(non_neg_integer()) => EEVM.Database.account()},
  storage: %{
    required(non_neg_integer()) => %{
      required(non_neg_integer()) => non_neg_integer()
    }
  }
}

Functions

init(opts \\ [])

@spec init(keyword()) :: state()

Creates a new in-memory database state.

Options

  • :accounts — initial account map (default: %{})
  • :storage — initial per-address storage map (default: %{})

Examples

iex> state = EEVM.Database.InMemory.init()
iex> EEVM.Database.InMemory.get_balance(state, 0x1234)
0

iex> state = EEVM.Database.InMemory.init(accounts: %{1 => %{balance: 100}})
iex> EEVM.Database.InMemory.get_balance(state, 1)
100

new(opts \\ [])

@spec new(keyword()) :: EEVM.Database.t()

Convenience: creates a fully wrapped %Database{} with InMemory backend.

This is the most common way to create a database for execution.

Examples

iex> db = EEVM.Database.InMemory.new()
iex> EEVM.Database.get_balance(db, 0x1234)
0