ethereum.byzantium.utils.messageethereum.constantinople.utils.message

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

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

Introduction

Message specific functions used in this byzantium version ofMessage specific functions used in this constantinople 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. should_transfer_value : if True ETH should be transferred while executing a message call. is_static: if True then it prevents all state-changing operations from being executed.

Returns

message: ethereum.byzantium.vm.Messageethereum.constantinople.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], ​​should_transfer_value: bool, ​​is_static: bool) -> Message:
37
    """
38
    Execute a transaction against the provided environment.
39
40
    Parameters
41
    ----------
42
    caller :
43
        Address which initiated the transaction
44
    target :
45
        Address whose code will be executed
46
    value :
47
        Value to be transferred.
48
    data :
49
        Array of bytes provided to the code in `target`.
50
    gas :
51
        Gas provided for the code in `target`.
52
    env :
53
        Environment for the Ethereum Virtual Machine.
54
    code_address :
55
        This is usually same as the `target` address except when an alternative
56
        accounts code needs to be executed.
57
        eg. `CALLCODE` calling a precompile.
58
    should_transfer_value :
59
        if True ETH should be transferred while executing a message call.
60
    is_static:
61
        if True then it prevents all state-changing operations from being
62
        executed.
63
64
    Returns
65
    -------
66
    message: `ethereum.byzantium.vm.Message`
66
    message: `ethereum.constantinople.vm.Message`
67
        Items containing contract creation or message call specific data.
68
    """
69
    if isinstance(target, Bytes0):
70
        current_target = compute_contract_address(
71
            caller,
72
            get_account(env.state, caller).nonce - Uint(1),
73
        )
74
        msg_data = Bytes(b"")
75
        code = data
76
    elif isinstance(target, Address):
77
        current_target = target
78
        msg_data = data
79
        code = get_account(env.state, target).code
80
        if code_address is None:
81
            code_address = target
82
    else:
83
        raise AssertionError("Target must be address or empty bytes")
84
85
    return Message(
86
        caller=caller,
87
        target=target,
88
        gas=gas,
89
        value=value,
90
        data=msg_data,
91
        code=code,
92
        depth=Uint(0),
93
        current_target=current_target,
94
        code_address=code_address,
95
        should_transfer_value=should_transfer_value,
96
        is_static=is_static,
97
        parent_evm=None,
98
    )