ethereum.dao_fork.utils.message
Hardfork Utility Functions For The Message Data-structure ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Message specific functions used in this Dao Fork 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.dao_fork.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:
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.dao_fork.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 | ) |