Hardfork Utility Functions For Addresses

Introduction

Address specific functions used in this tangerine whistle version of specification.

Module Contents

Functions

to_address

Convert a Uint or U256 value to a valid address (20 bytes).

compute_contract_address

Computes address of the new account that needs to be created.

Module Details

to_address

to_address(data: Union[ethereum.base_types.Uint, ethereum.base_types.U256])ethereum.tangerine_whistle.fork_types.Address

Convert a Uint or U256 value to a valid address (20 bytes).

Parameters

data – The string to be converted to bytes.

Returns

address – The obtained address.

Return type

Address

def to_address(data: Union[Uint, U256]) -> Address:
    return Address(data.to_be_bytes32()[-20:])

compute_contract_address

compute_contract_address(address: ethereum.tangerine_whistle.fork_types.Address, nonce: ethereum.base_types.Uint)ethereum.tangerine_whistle.fork_types.Address

Computes address of the new account that needs to be created.

Parameters
  • address – The address of the account that wants to create the new account.

  • nonce – The transaction count of the account that wants to create the new account.

Returns

address – The computed address of the new account.

Return type

ethereum.tangerine_whistle.fork_types.Address

def compute_contract_address(address: Address, nonce: Uint) -> Address:
    computed_address = keccak256(rlp.encode([address, nonce]))
    canonical_address = computed_address[-20:]
    padded_address = left_pad_zero_bytes(canonical_address, 20)
    return Address(padded_address)