ethereum.forks.frontier.utils.addressethereum.forks.homestead.utils.address
Hardfork Utility Functions For Addresses.
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Address specific functions used in this frontier version of specification.Address specific functions used in this homestead version of specification.
to_address_masked
Convert a Uint or U256 value to a valid address (20 bytes).
Parameters
data : The numeric value to be converted to address.
Returns
address : Address
The obtained address.
def to_address_masked(data: Uint | U256) -> Address:
| 24 | """ |
|---|---|
| 25 | Convert a Uint or U256 value to a valid address (20 bytes). |
| 26 | |
| 27 | Parameters |
| 28 | ---------- |
| 29 | data : |
| 30 | The numeric value to be converted to address. |
| 31 | |
| 32 | Returns |
| 33 | ------- |
| 34 | address : `Address` |
| 35 | The obtained address. |
| 36 | |
| 37 | """ |
| 38 | 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:
The computed address of the new account.ethereum.forks.frontier.fork_types.Addressethereum.forks.homestead.fork_types.Address
def compute_contract_address(address: Address, nonce: Uint) -> Address:
| 42 | """ |
|---|---|
| 43 | Computes address of the new account that needs to be created. |
| 44 | |
| 45 | Parameters |
| 46 | ---------- |
| 47 | address : |
| 48 | The address of the account that wants to create the new account. |
| 49 | nonce : |
| 50 | The transaction count of the account that wants to create the new |
| 51 | account. |
| 52 | |
| 53 | Returns |
| 54 | ------- |
| 55 | address: `ethereum.forks.frontier.fork_types.Address` |
| 55 | address: `ethereum.forks.homestead.fork_types.Address` |
| 56 | The computed address of the new account. |
| 57 | |
| 58 | """ |
| 59 | computed_address = keccak256(rlp.encode([address, nonce])) |
| 60 | canonical_address = computed_address[-20:] |
| 61 | padded_address = left_pad_zero_bytes(canonical_address, 20) |
| 62 | return Address(padded_address) |