ethereum.tangerine_whistle.utils.addressethereum.spurious_dragon.utils.address

Hardfork Utility Functions For Addresses ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. contents:: Table of Contents :backlinks: none :local:

Introduction

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

to_address

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

Parameters

data : The string to be converted to bytes.

Returns

address : Address The obtained address.

def to_address(data: Union[Uint, U256]) -> Address:
27
    """
28
    Convert a Uint or U256 value to a valid address (20 bytes).
29
30
    Parameters
31
    ----------
32
    data :
33
        The string to be converted to bytes.
34
35
    Returns
36
    -------
37
    address : `Address`
38
        The obtained address.
39
    """
40
    return Address(data.to_be_bytes32()[-20:])

compute_contract_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: ethereum.tangerine_whistle.fork_types.Addressethereum.spurious_dragon.fork_types.Address The computed address of the new account.

def compute_contract_address(address: Address, ​​nonce: Uint) -> Address:
44
    """
45
    Computes address of the new account that needs to be created.
46
47
    Parameters
48
    ----------
49
    address :
50
        The address of the account that wants to create the new account.
51
    nonce :
52
        The transaction count of the account that wants to create the new
53
        account.
54
55
    Returns
56
    -------
57
    address: `ethereum.tangerine_whistle.fork_types.Address`
57
    address: `ethereum.spurious_dragon.fork_types.Address`
58
        The computed address of the new account.
59
    """
60
    computed_address = keccak256(rlp.encode([address, nonce]))
61
    canonical_address = computed_address[-20:]
62
    padded_address = left_pad_zero_bytes(canonical_address, 20)
63
    return Address(padded_address)