ethereum.tangerine_whistle.utils.message

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

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

Introduction

Message specific functions used in this tangerine whistle 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.

Returns

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