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.
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 frontier 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) -> 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 )
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) -> 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 56 Returns 57 ------- 58 message: `ethereum.frontier.vm.Message` 59 Items containing contract creation or message call specific data. 60 """ 61 if isinstance(target, Bytes0): 62 current_target = compute_contract_address( 63 caller, 64 get_account(env.state, caller).nonce - U256(1), 65 ) 66 msg_data = Bytes(b"") 67 code = data 68 elif isinstance(target, Address): 69 current_target = target 70 msg_data = data 71 code = get_account(env.state, target).code 72 if code_address is None: 73 code_address = target 74 else: 75 raise AssertionError("Target must be address or empty bytes") 76 77 return Message( 78 caller=caller, 79 target=target, 80 gas=gas, 81 value=value, 82 data=msg_data, 83 code=code, 84 depth=Uint(0), 85 current_target=current_target, 86 code_address=code_address, 87 parent_evm=None, 88 )
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.