ethereum.frontier.utils.messageethereum.homestead.utils.message

Hardfork Utility Functions For The Message Data-structure ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

Introduction

Message specific functions used in this frontier version of specification.Message specific functions used in this homestead 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.frontier.vm.Messageethereum.homestead.vm.Message Items containing contract creation or message call specific data.

def prepare_message(block_env: BlockEnvironment, ​​tx_env: TransactionEnvironment, ​​tx: Transaction) -> Message:
29
    """
30
    Execute a transaction against the provided environment.
31
32
    Parameters
33
    ----------
34
    block_env :
35
        Environment for the Ethereum Virtual Machine.
36
    tx_env :
37
        Environment for the transaction.
38
    tx :
39
        Transaction to be executed.
40
41
    Returns
42
    -------
43
    message: `ethereum.frontier.vm.Message`
43
    message: `ethereum.homestead.vm.Message`
44
        Items containing contract creation or message call specific data.
45
    """
46
    if isinstance(tx.to, Bytes0):
47
        current_target = compute_contract_address(
48
            tx_env.origin,
49
            get_account(block_env.state, tx_env.origin).nonce - Uint(1),
50
        )
51
        msg_data = Bytes(b"")
52
        code = tx.data
53
        code_address = None
54
    elif isinstance(tx.to, Address):
55
        current_target = tx.to
56
        msg_data = tx.data
57
        code = get_account(block_env.state, tx.to).code
58
59
        code_address = tx.to
60
    else:
61
        raise AssertionError("Target must be address or empty bytes")
62
63
    return Message(
64
        block_env=block_env,
65
        tx_env=tx_env,
66
        caller=tx_env.origin,
67
        target=tx.to,
68
        gas=tx_env.gas,
69
        value=tx.value,
70
        data=msg_data,
71
        code=code,
72
        depth=Uint(0),
73
        current_target=current_target,
74
        code_address=code_address,
75
        should_transfer_value=True,
76
        parent_evm=None,
77
    )