add accountkey20 conversion impls (#2576)

This commit is contained in:
Amar Singh
2021-03-07 13:54:30 -08:00
committed by GitHub
parent 1251a7187c
commit 5b3fa6f7f6
3 changed files with 47 additions and 2 deletions
@@ -124,3 +124,27 @@ impl<
Ok(Junction::AccountId32 { id: who.into(), network: Network::get() }.into())
}
}
pub struct AccountKey20Aliases<Network, AccountId>(PhantomData<(Network, AccountId)>);
impl<
Network: Get<NetworkId>,
AccountId: From<[u8; 20]> + Into<[u8; 20]>
> LocationConversion<AccountId> for AccountKey20Aliases<Network, AccountId> {
fn from_location(location: &MultiLocation) -> Option<AccountId> {
if let MultiLocation::X1(Junction::AccountKey20 { key, network }) = location {
if matches!(network, NetworkId::Any) || network == &Network::get() {
return Some((*key).into());
}
}
None
}
fn try_into_location(who: AccountId) -> Result<MultiLocation, AccountId> {
Ok(Junction::AccountKey20 {
key: who.into(),
network: Network::get(),
}
.into())
}
}