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