Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change(kreivo-runtime): add AccountId32FromRelay convert location structure #377

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
}
}