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.
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.
Returns
message: ethereum.frontier.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]) -> 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 - Uint(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 | ) |