Skip to content

Commit

Permalink
change(kreivo-runtime): add AccountId32FromRelay convert location s…
Browse files Browse the repository at this point in the history
…tructure (#377)
  • Loading branch information
pandres95 authored Apr 30, 2024
1 parent bfe715b commit ce8b702
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 3 additions & 1 deletion runtime/kreivo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use plurality_community::*;

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
pub const RelayNetwork: Option<NetworkId> = None;
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::Kusama);
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub CheckAccount: (AccountId, MintLocation) = (PolkadotXcm::check_account(), MintLocation::Local);
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
Expand All @@ -58,6 +58,8 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<Sibling, AccountId>,
// Plurality origins convert to community AccountId via the `Communities::community_account`.
PluralityConvertsToCommunityAccountId,
// For incoming relay `Account32` origins, alias directly to `AccountId`.
AccountId32FromRelay<RelayNetwork, AccountId>,
// Straight up local `AccountId32` origins just alias directly to `AccountId`.
AccountId32Aliases<RelayNetwork, AccountId>,
);
Expand Down
22 changes: 21 additions & 1 deletion runtime/kreivo/src/xcm_config/plurality_community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use xcm_executor::traits::ConvertLocation;
pub struct PluralityConvertsToCommunityAccountId;
impl ConvertLocation<AccountId> for PluralityConvertsToCommunityAccountId {
fn convert_location(location: &MultiLocation) -> Option<AccountId> {
log::trace!("Attempting to convert {:?} into AccountId if plurality", location);
match location {
MultiLocation {
parents: 0,
Expand All @@ -20,3 +19,24 @@ impl ConvertLocation<AccountId> for PluralityConvertsToCommunityAccountId {
}
}
}

pub struct AccountId32FromRelay<Network, AccountId>(PhantomData<(Network, AccountId)>);
impl<Network: Get<Option<NetworkId>>, AccountId: From<[u8; 32]> + Into<[u8; 32]> + Clone> ConvertLocation<AccountId>
for AccountId32FromRelay<Network, AccountId>
{
fn convert_location(location: &MultiLocation) -> Option<AccountId> {
let id = match location {
MultiLocation {
parents: 1,
interior: X1(AccountId32 { id, network: None }),
} => id,
MultiLocation {
parents: 1,
interior: X1(AccountId32 { id, network }),
} if *network == Network::get() => id,
_ => return None,
};

Some((*id).into())
}
}

0 comments on commit ce8b702

Please sign in to comment.