Skip to content

Commit

Permalink
Allow communities to send XCM
Browse files Browse the repository at this point in the history
  • Loading branch information
olanod committed Apr 12, 2024
1 parent 631cb18 commit 20f815b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
18 changes: 17 additions & 1 deletion pallets/communities/src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(PhantomData<T>);

Expand Down Expand Up @@ -117,6 +117,22 @@ pub enum DecisionMethod<AssetId> {
Rank,
}

#[cfg(feature = "xcm")]
impl<T> TryConvert<T::RuntimeOrigin, xcm::v3::MultiLocation> for RawOrigin<T>
where
T: Config,
T::RuntimeOrigin: Into<Result<RawOrigin<T>, T::RuntimeOrigin>>,
xcm::v3::Junction: TryFrom<RawOrigin<T>>,
{
fn try_convert(o: T::RuntimeOrigin) -> Result<xcm::v3::MultiLocation, T::RuntimeOrigin> {
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<T> TryFrom<RawOrigin<T>> for xcm::v3::Junction
where
Expand Down
15 changes: 7 additions & 8 deletions runtime/kreivo/src/xcm_config.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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;
Expand Down Expand Up @@ -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<RuntimeOrigin, AccountId, RelayNetwork>;
/// Only communities are allowed to dispatch xcm messages
pub type ConvertCommunityOrigin = pallet_communities::Origin<Runtime>;

/// The means for routing XCM messages which are not for local execution into
/// the right message queues.
Expand All @@ -244,9 +243,9 @@ pub type XcmRouter = (

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ConvertCommunityOrigin>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ConvertCommunityOrigin>;
type XcmExecuteFilter = Nothing;
// ^ Disable dispatchable execute on the XCM pallet.
type XcmExecutor = XcmExecutor<XcmConfig>;
Expand Down

0 comments on commit 20f815b

Please sign in to comment.