referrerpolicy=no-referrer-when-downgrade

Trait pallet_revive::AddressMapper

source ·
pub trait AddressMapper<T: Config>: Sealed {
    // Required methods
    fn to_address(account_id: &T::AccountId) -> H160;
    fn to_account_id(address: &H160) -> T::AccountId;
    fn to_fallback_account_id(address: &H160) -> T::AccountId;
    fn map(account_id: &T::AccountId) -> DispatchResult;
    fn unmap(account_id: &T::AccountId) -> DispatchResult;
    fn is_mapped(account_id: &T::AccountId) -> bool;
}
Expand description

Map between the native chain account id T and an Ethereum H160.

This trait exists only to emulate specialization for different concrete native account ids. Not to make the mapping user configurable. Hence the trait is Sealed and depending on your runtime configuration you need to pick either AccountId32Mapper or [H160Mapper]. Picking the wrong one will result in a compilation error. No footguns here.

Please note that we assume that the native account is at least 20 bytes and only implement this type for a T where this is the case. Luckily, this is the case for all existing runtimes as of right now. Reasoning is that this will allow us to reverse an address -> account_id mapping by just stripping the prefix.

We require the mapping to be reversible. Since we are potentially dealing with types of different sizes one direction of the mapping is necessarily lossy. This requires the mapping to make use of the [AddressSuffix] storage item to reverse the mapping.

Required Methods§

source

fn to_address(account_id: &T::AccountId) -> H160

Convert an account id to an ethereum adress.

source

fn to_account_id(address: &H160) -> T::AccountId

Convert an ethereum address to a native account id.

source

fn to_fallback_account_id(address: &H160) -> T::AccountId

Same as Self::to_account_id but always returns the fallback account.

This skips the query into [AddressSuffix] and always returns the stateless fallback account. This is useful when we know for a fact that the address in question is originally a H160. This is usually only the case when we generated a new contract address.

source

fn map(account_id: &T::AccountId) -> DispatchResult

Create a stateful mapping for account_id

This will enable to_account_id to map back to the original account_id instead of the fallback account id.

source

fn unmap(account_id: &T::AccountId) -> DispatchResult

Remove the mapping in order to reclaim the deposit.

There is no reason why one would unmap their account_id except for reclaiming the deposit.

source

fn is_mapped(account_id: &T::AccountId) -> bool

Returns true if the account_id is useable as an origin.

This means either the account_id doesn’t require a stateful mapping or a stateful mapping exists.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> AddressMapper<T> for AccountId32Mapper<T>
where T: Config<AccountId = AccountId32>,