Skip to content

Commit d92792d

Browse files
committed
small place changes
1 parent f6c128b commit d92792d

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

crates/e2e/src/lib.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,27 @@ pub fn address<E: Environment>(account: Sr25519Keyring) -> Address {
153153
AccountIdMapper::to_address(account.to_account_id().as_ref())
154154
}
155155

156-
/// Extension trait for converting various types to Address (H160).
157-
pub trait IntoAddress {
158-
/// Convert to an Address (H160).
159-
fn address(&self) -> Address;
160-
}
161-
162-
impl IntoAddress for Keypair {
163-
fn address(&self) -> Address {
164-
AccountIdMapper::to_address(&self.public_key().0)
165-
}
156+
/// Returns the [`ink::Address`] for a given account id.
157+
///
158+
/// # Developer Note
159+
///
160+
/// We take the `AccountId` and return only the first twenty bytes, this
161+
/// is what `pallet-revive` does as well.
162+
pub fn address_from_account_id<AccountId: AsRef<[u8]>>(account_id: AccountId) -> Address {
163+
AccountIdMapper::to_address(account_id.as_ref())
166164
}
167165

168-
impl IntoAddress for ink_primitives::AccountId {
169-
fn address(&self) -> Address {
170-
let bytes = *AsRef::<[u8; 32]>::as_ref(self);
171-
AccountIdMapper::to_address(&bytes)
172-
}
166+
/// Returns the [`ink::Address`] for a given `Keypair`.
167+
///
168+
/// # Developer Note
169+
///
170+
/// We take the `AccountId` and return only the first twenty bytes, this
171+
/// is what `pallet-revive` does as well.
172+
pub fn address_from_keypair<AccountId: From<[u8; 32]> + AsRef<[u8]>>(
173+
keypair: &Keypair,
174+
) -> Address {
175+
let account_id: AccountId = keypair_to_account(keypair);
176+
address_from_account_id(account_id)
173177
}
174178

175179
/// Transforms a `Keypair` into an account id.

0 commit comments

Comments
 (0)