ethereum.muir_glacier.utils.message

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

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

Introduction

Message specific functions used in this muir_glacier version of specification.

 1"""
 2Hardfork Utility Functions For The Message Data-structure
 3^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 4
 5.. contents:: Table of Contents
 6    :backlinks: none
 7    :local:
 8
 9Introduction
10------------
11
12Message specific functions used in this muir_glacier version of
13specification.
14"""
15from typing import Optional, Union
16
17from ethereum.base_types import U256, Bytes, Bytes0, Uint
18
19from ..fork_types import Address
20from ..state import get_account
21from ..vm import Environment, Message
22from .address import compute_contract_address
23
24
25def prepare_message(
26    caller: Address,
27    target: Union[Bytes0, Address],
28    value: U256,
29    data: Bytes,
30    gas: Uint,
31    env: Environment,
32    code_address: Optional[Address] = None,
33    should_transfer_value: bool = True,
34    is_static: bool = False,
35) -> 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    is_static:
60        if True then it prevents all state-changing operations from being
61        executed.
62
63    Returns
64    -------
65    message: `ethereum.muir_glacier.vm.Message`
66        Items containing contract creation or message call specific data.
67    """
68    if isinstance(target, Bytes0):
69        current_target = compute_contract_address(
70            caller,
71            get_account(env.state, caller).nonce - U256(1),
72        )
73        msg_data = Bytes(b"")
74        code = data
75    elif isinstance(target, Address):
76        current_target = target
77        msg_data = data
78        code = get_account(env.state, target).code
79        if code_address is None:
80            code_address = target
81    else:
82        raise AssertionError("Target must be address or empty bytes")
83
84    return Message(
85        caller=caller,
86        target=target,
87        gas=gas,
88        value=value,
89        data=msg_data,
90        code=code,
91        depth=Uint(0),
92        current_target=current_target,
93        code_address=code_address,
94        should_transfer_value=should_transfer_value,
95        is_static=is_static,
96        parent_evm=None,
97    )
def prepare_message( caller: ethereum.base_types.Bytes20, target: Union[ethereum.base_types.Bytes0, ethereum.base_types.Bytes20], value: ethereum.base_types.U256, data: bytes, gas: ethereum.base_types.Uint, env: ethereum.muir_glacier.vm.Environment, code_address: Optional[ethereum.base_types.Bytes20] = None, should_transfer_value: bool = True, is_static: bool = False) -> ethereum.muir_glacier.vm.Message:
26def prepare_message(
27    caller: Address,
28    target: Union[Bytes0, Address],
29    value: U256,
30    data: Bytes,
31    gas: Uint,
32    env: Environment,
33    code_address: Optional[Address] = None,
34    should_transfer_value: bool = True,
35    is_static: bool = False,
36) -> 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.muir_glacier.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 - U256(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    )

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.muir_glacier.vm.Message Items containing contract creation or message call specific data.