ethereum.frontier.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.

prepare_message

Execute a transaction against the provided environment.

Parameters

caller : Address which initiated the transaction target : Address whose code will be executed value : Value to be transferred. data : Array of bytes provided to the code in target. gas : Gas provided for the code in target. env : Environment for the Ethereum Virtual Machine. code_address : This is usually same as the target address except when an alternative accounts code needs to be executed. eg. CALLCODE calling a precompile.

Returns

message: ethereum.frontier.vm.Message Items containing contract creation or message call specific data.

def prepare_message(caller: Address, ​​target: Union[Bytes0, Address], ​​value: U256, ​​data: Bytes, ​​gas: Uint, ​​env: Environment, ​​code_address: Optional[Address]) -> Message:
33
    """
34
    Execute a transaction against the provided environment.
35
36
    Parameters
37
    ----------
38
    caller :
39
        Address which initiated the transaction
40
    target :
41
        Address whose code will be executed
42
    value :
43
        Value to be transferred.
44
    data :
45
        Array of bytes provided to the code in `target`.
46
    gas :
47
        Gas provided for the code in `target`.
48
    env :
49
        Environment for the Ethereum Virtual Machine.
50
    code_address :
51
        This is usually same as the `target` address except when an alternative
52
        accounts code needs to be executed.
53
        eg. `CALLCODE` calling a precompile.
54
55
    Returns
56
    -------
57
    message: `ethereum.frontier.vm.Message`
58
        Items containing contract creation or message call specific data.
59
    """
60
    if isinstance(target, Bytes0):
61
        current_target = compute_contract_address(
62
            caller,
63
            get_account(env.state, caller).nonce - U256(1),
64
        )
65
        msg_data = Bytes(b"")
66
        code = data
67
    elif isinstance(target, Address):
68
        current_target = target
69
        msg_data = data
70
        code = get_account(env.state, target).code
71
        if code_address is None:
72
            code_address = target
73
    else:
74
        raise AssertionError("Target must be address or empty bytes")
75
76
    return Message(
77
        caller=caller,
78
        target=target,
79
        gas=gas,
80
        value=value,
81
        data=msg_data,
82
        code=code,
83
        depth=Uint(0),
84
        current_target=current_target,
85
        code_address=code_address,
86
        parent_evm=None,
87
    )