Hardfork Utility Functions For The Message Data-structure

Introduction

Message specific functions used in this muir_glacier version of specification.

Module Contents

Functions

prepare_message

Execute a transaction against the provided environment.

Module Details

prepare_message

prepare_message(caller: ethereum.muir_glacier.fork_types.Address, target: Union[ethereum.base_types.Bytes0, ethereum.muir_glacier.fork_types.Address], value: ethereum.base_types.U256, data: ethereum.base_types.Bytes, gas: ethereum.base_types.U256, env: ethereum.muir_glacier.vm.Environment, code_address: Optional[ethereum.muir_glacier.fork_types.Address] = None, should_transfer_value: bool = True, is_static: bool = False)ethereum.muir_glacier.vm.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.

  • is_static – if True then it prevents all state-changing operations from being executed.

Returns

message – Items containing contract creation or message call specific data.

Return type

ethereum.muir_glacier.vm.Message

def prepare_message(
    caller: Address,
    target: Union[Bytes0, Address],
    value: U256,
    data: Bytes,
    gas: U256,
    env: Environment,
    code_address: Optional[Address] = None,
    should_transfer_value: bool = True,
    is_static: bool = False,
) -> Message:
    if isinstance(target, Bytes0):
        current_target = compute_contract_address(
            caller,
            get_account(env.state, caller).nonce - U256(1),
        )
        msg_data = Bytes(b"")
        code = data
    elif isinstance(target, Address):
        current_target = target
        msg_data = data
        code = get_account(env.state, target).code
        if code_address is None:
            code_address = target
    else:
        raise AssertionError("Target must be address or empty bytes")

    return Message(
        caller=caller,
        target=target,
        gas=gas,
        value=value,
        data=msg_data,
        code=code,
        depth=Uint(0),
        current_target=current_target,
        code_address=code_address,
        should_transfer_value=should_transfer_value,
        is_static=is_static,
    )