Skip to content
Snippets Groups Projects
Commit 5b3fa6f7 authored by Amar Singh's avatar Amar Singh Committed by GitHub
Browse files

add accountkey20 conversion impls (#2576)

parent 1251a718
No related merge requests found
......@@ -18,13 +18,13 @@
mod location_conversion;
pub use location_conversion::{
Account32Hash, ParentIsDefault, ChildParachainConvertsVia, SiblingParachainConvertsVia, AccountId32Aliases
Account32Hash, ParentIsDefault, ChildParachainConvertsVia, SiblingParachainConvertsVia, AccountId32Aliases, AccountKey20Aliases,
};
mod origin_conversion;
pub use origin_conversion::{
SovereignSignedViaLocation, ParentAsSuperuser, ChildSystemParachainAsSuperuser, SiblingSystemParachainAsSuperuser,
ChildParachainAsNative, SiblingParachainAsNative, RelayChainAsNative, SignedAccountId32AsNative
ChildParachainAsNative, SiblingParachainAsNative, RelayChainAsNative, SignedAccountId32AsNative, SignedAccountKey20AsNative,
};
mod currency_adapter;
......
......@@ -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())
}
}
......@@ -148,3 +148,24 @@ impl<
}
}
}
pub struct SignedAccountKey20AsNative<Network, Origin>(
PhantomData<(Network, Origin)>
);
impl<
Network: Get<NetworkId>,
Origin: OriginTrait
> ConvertOrigin<Origin> for SignedAccountKey20AsNative<Network, Origin> where
Origin::AccountId: From<[u8; 20]>,
{
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
match (kind, origin) {
(OriginKind::Native, MultiLocation::X1(Junction::AccountKey20 { key, network }))
if matches!(network, NetworkId::Any) || network == Network::get() =>
{
Ok(Origin::signed(key.into()))
}
(_, origin) => Err(origin),
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment