From 20f815b56d6395c0825b4deeed68d1e2056c05c4 Mon Sep 17 00:00:00 2001 From: Daniel Olano Date: Fri, 12 Apr 2024 22:01:46 +0200 Subject: [PATCH] Allow communities to send XCM --- pallets/communities/src/origin.rs | 18 +++++++++++++++++- runtime/kreivo/src/xcm_config.rs | 15 +++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/pallets/communities/src/origin.rs b/pallets/communities/src/origin.rs index 8acc1447..10120f1b 100644 --- a/pallets/communities/src/origin.rs +++ b/pallets/communities/src/origin.rs @@ -8,7 +8,7 @@ use frame_support::{ pallet_prelude::*, traits::{membership::GenericRank, EnsureOriginWithArg, OriginTrait}, }; -use sp_runtime::Permill; +use sp_runtime::{traits::TryConvert, Permill}; pub struct EnsureCommunity(PhantomData); @@ -117,6 +117,22 @@ pub enum DecisionMethod { Rank, } +#[cfg(feature = "xcm")] +impl TryConvert for RawOrigin +where + T: Config, + T::RuntimeOrigin: Into, T::RuntimeOrigin>>, + xcm::v3::Junction: TryFrom>, +{ + fn try_convert(o: T::RuntimeOrigin) -> Result { + let Ok(community @ RawOrigin { .. }) = o.clone().into() else { + return Err(o); + }; + let j = xcm::v3::Junction::try_from(community).map_err(|_| o)?; + Ok(j.into()) + } +} + #[cfg(feature = "xcm")] impl TryFrom> for xcm::v3::Junction where diff --git a/runtime/kreivo/src/xcm_config.rs b/runtime/kreivo/src/xcm_config.rs index 99590d41..97507175 100644 --- a/runtime/kreivo/src/xcm_config.rs +++ b/runtime/kreivo/src/xcm_config.rs @@ -1,10 +1,9 @@ -use virto_common::AsFungibleAssetLocation; - use super::{ AccountId, AllPalletsWithSystem, Assets, Balance, Balances, FungibleAssetLocation, KreivoAssetsInstance, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Treasury, WeightToFee, XcmpQueue, }; +use virto_common::AsFungibleAssetLocation; use crate::constants::locations::STATEMINE_PARA_ID; use frame_support::{ @@ -24,8 +23,8 @@ use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete, LocalMint, MintLocation, NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, StartsWith, TakeWeightCredit, - UsingComponents, WeightInfoBounds, WithComputedOrigin, + SignedAccountId32AsNative, SovereignSignedViaLocation, StartsWith, TakeWeightCredit, UsingComponents, + WeightInfoBounds, WithComputedOrigin, }; use xcm_executor::traits::JustTry; use xcm_executor::XcmExecutor; @@ -230,8 +229,8 @@ impl xcm_executor::Config for XcmConfig { type Aliasers = Nothing; } -/// No local origins on this chain are allowed to dispatch XCM sends/executions. -pub type LocalOriginToLocation = SignedToAccountId32; +/// Only communities are allowed to dispatch xcm messages +pub type ConvertCommunityOrigin = pallet_communities::Origin; /// The means for routing XCM messages which are not for local execution into /// the right message queues. @@ -244,9 +243,9 @@ pub type XcmRouter = ( impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type SendXcmOrigin = EnsureXcmOrigin; + type SendXcmOrigin = EnsureXcmOrigin; type XcmRouter = XcmRouter; - type ExecuteXcmOrigin = EnsureXcmOrigin; + type ExecuteXcmOrigin = EnsureXcmOrigin; type XcmExecuteFilter = Nothing; // ^ Disable dispatchable execute on the XCM pallet. type XcmExecutor = XcmExecutor;