ethereum.forks.bpo5.utils.messageethereum.forks.amsterdam.utils.message

Hardfork Utility Functions For The Message Data-structure.

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Message specific functions used in this bpo5 version ofMessage specific functions used in this amsterdam version of specification.

prepare_message

Execute a transaction against the provided environment.

Parameters

block_env : Environment for the Ethereum Virtual Machine. tx_env : Environment for the transaction. tx : Transaction to be executed.

Returns

message: ethereum.forks.bpo5.vm.Messageethereum.forks.amsterdam.vm.Message Items containing contract creation or message call specific data.

def prepare_message(block_env: BlockEnvironment, ​​tx_env: TransactionEnvironment, ​​tx: Transaction) -> Message:
32
    """
33
    Execute a transaction against the provided environment.
34
35
    Parameters
36
    ----------
37
    block_env :
38
        Environment for the Ethereum Virtual Machine.
39
    tx_env :
40
        Environment for the transaction.
41
    tx :
42
        Transaction to be executed.
43
44
    Returns
45
    -------
45
    message: `ethereum.forks.bpo5.vm.Message`
46
    message: `ethereum.forks.amsterdam.vm.Message`
47
        Items containing contract creation or message call specific data.
48
49
    """
50
    accessed_addresses = set()
51
    accessed_addresses.add(tx_env.origin)
52
    accessed_addresses.update(PRE_COMPILED_CONTRACTS.keys())
53
    accessed_addresses.update(tx_env.access_list_addresses)
54
55
    if isinstance(tx.to, Bytes0):
56
        current_target = compute_contract_address(
57
            tx_env.origin,
58
            get_account(block_env.state, tx_env.origin).nonce - Uint(1),
59
        )
60
        msg_data = Bytes(b"")
61
        code = tx.data
62
        code_address = None
63
    elif isinstance(tx.to, Address):
64
        current_target = tx.to
65
        msg_data = tx.data
66
        code = get_account(block_env.state, tx.to).code
67
        code_address = tx.to
68
    else:
69
        raise AssertionError("Target must be address or empty bytes")
70
71
    accessed_addresses.add(current_target)
72
73
    # Create call frame as child of transaction frame
74
    call_frame = create_child_frame(tx_env.state_changes)
75
76
    return Message(
77
        block_env=block_env,
78
        tx_env=tx_env,
79
        caller=tx_env.origin,
80
        target=tx.to,
81
        gas=tx_env.gas,
82
        value=tx.value,
83
        data=msg_data,
84
        code=code,
85
        depth=Uint(0),
86
        current_target=current_target,
87
        code_address=code_address,
88
        should_transfer_value=True,
89
        is_static=False,
90
        accessed_addresses=accessed_addresses,
91
        accessed_storage_keys=set(tx_env.access_list_storage_keys),
92
        disable_precompiles=False,
93
        parent_evm=None,
94
        is_create=isinstance(tx.to, Bytes0),
95
        state_changes=call_frame,
96
    )