ethereum.forks.constantinople.utils.addressethereum.forks.istanbul.utils.address
Hardfork Utility Functions For Addresses.
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Address specific functions used in this constantinople version ofAddress specific functions used in this istanbul 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:
| 26 | """ |
|---|---|
| 27 | Convert a Uint or U256 value to a valid address (20 bytes). |
| 28 | |
| 29 | Parameters |
| 30 | ---------- |
| 31 | data : |
| 32 | The numeric value to be converted to address. |
| 33 | |
| 34 | Returns |
| 35 | ------- |
| 36 | address : `Address` |
| 37 | The obtained address. |
| 38 | |
| 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: 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: `Address` |
| 58 | The computed address of the new account. |
| 59 | |
| 60 | """ |
| 61 | computed_address = keccak256(rlp.encode([address, nonce])) |
| 62 | canonical_address = computed_address[-20:] |
| 63 | padded_address = left_pad_zero_bytes(canonical_address, 20) |
| 64 | return Address(padded_address) |
compute_create2_contract_address
Computes address of the new account that needs to be created, which is based on the sender address, salt and the call data as well.
Parameters
address : The address of the account that wants to create the new account. salt : Address generation salt. call_data : The code of the new account which is to be created.
Returns
address:
The computed address of the new account.ethereum.forks.constantinople.fork_types.Addressethereum.forks.istanbul.fork_types.Address
def compute_create2_contract_address(address: Address, salt: Bytes32, call_data: Bytes) -> Address:
| 70 | """ |
|---|---|
| 71 | Computes address of the new account that needs to be created, which is |
| 72 | based on the sender address, salt and the call data as well. |
| 73 | |
| 74 | Parameters |
| 75 | ---------- |
| 76 | address : |
| 77 | The address of the account that wants to create the new account. |
| 78 | salt : |
| 79 | Address generation salt. |
| 80 | call_data : |
| 81 | The code of the new account which is to be created. |
| 82 | |
| 83 | Returns |
| 84 | ------- |
| 85 | address: `ethereum.forks.constantinople.fork_types.Address` |
| 85 | address: `ethereum.forks.istanbul.fork_types.Address` |
| 86 | The computed address of the new account. |
| 87 | |
| 88 | """ |
| 89 | preimage = b"\xff" + address + salt + keccak256(call_data) |
| 90 | computed_address = keccak256(preimage) |
| 91 | canonical_address = computed_address[-20:] |
| 92 | padded_address = left_pad_zero_bytes(canonical_address, 20) |
| 93 | |
| 94 | return Address(padded_address) |