git.delta.rocks / unique-network / refs/commits / de0fd484c6ec

difftreelog

fix cargo clippy

PraetorP2023-09-29parent: #668280b.patch.diff
in: master

2 files changed

modifiedruntime/common/config/xcm/mod.rsdiffbeforeafterboth
before · runtime/common/config/xcm/mod.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18	traits::{Everything, Nothing, Get, ConstU32, ProcessMessageError, Contains},19	parameter_types,20};21use frame_system::EnsureRoot;22use pallet_xcm::XcmPassthrough;23use polkadot_parachain::primitives::Sibling;24use xcm::latest::{prelude::*, Weight, MultiLocation};25use xcm::v3::Instruction;26use xcm_builder::{27	AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentAsSuperuser, RelayChainAsNative,28	SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,29	SignedToAccountId32, SovereignSignedViaLocation, ParentIsPreset,30};31use xcm_executor::{XcmExecutor, traits::ShouldExecute};32use sp_std::marker::PhantomData;33use crate::{34	Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, ParachainInfo, ParachainSystem, PolkadotXcm,35	XcmpQueue, xcm_barrier::Barrier, RelayNetwork, AllPalletsWithSystem, Balances,36};3738use up_common::types::AccountId;3940#[cfg(feature = "foreign-assets")]41pub mod foreignassets;4243#[cfg(not(feature = "foreign-assets"))]44pub mod nativeassets;4546#[cfg(feature = "foreign-assets")]47pub use foreignassets as xcm_assets;4849#[cfg(not(feature = "foreign-assets"))]50pub use nativeassets as xcm_assets;5152#[cfg(feature = "governance")]53use crate::runtime_common::config::governance;5455use xcm_assets::{AssetTransactor, IsReserve, Trader};5657parameter_types! {58	pub const RelayLocation: MultiLocation = MultiLocation::parent();59	pub RelayOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();60	pub UniversalLocation: InteriorMultiLocation = (61		GlobalConsensus(crate::RelayNetwork::get()),62		Parachain(ParachainInfo::get().into()),63	).into();64	pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));6566	// One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.67	pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1000); // ?68	pub const MaxInstructions: u32 = 100;69}7071/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used72/// when determining ownership of accounts for asset transacting and when attempting to use XCM73/// `Transact` in order to determine the dispatch Origin.74pub type LocationToAccountId = (75	// The parent (Relay-chain) origin converts to the default `AccountId`.76	ParentIsPreset<AccountId>,77	// Sibling parachain origins convert to AccountId via the `ParaId::into`.78	SiblingParachainConvertsVia<Sibling, AccountId>,79	// Straight up local `AccountId32` origins just alias directly to `AccountId`.80	AccountId32Aliases<RelayNetwork, AccountId>,81);8283/// No local origins on this chain are allowed to dispatch XCM sends/executions.84pub type LocalOriginToLocation = (SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,);8586/// The means for routing XCM messages which are not for local execution into the right message87/// queues.88pub type XcmRouter = (89	// Two routers - use UMP to communicate with the relay chain:90	cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,91	// ..and XCMP to communicate with the sibling chains.92	XcmpQueue,93);9495/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,96/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can97/// biases the kind of local `Origin` it will become.98pub type XcmOriginToTransactDispatchOrigin = (99	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location100	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for101	// foreign chains who want to have a local sovereign account on this chain which they control.102	SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,103	// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when104	// recognised.105	RelayChainAsNative<RelayOrigin, RuntimeOrigin>,106	// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when107	// recognised.108	SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,109	// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a110	// transaction from the Root origin.111	ParentAsSuperuser<RuntimeOrigin>,112	// Native signed account converter; this just converts an `AccountId32` origin into a normal113	// `Origin::Signed` origin of the same 32-byte value.114	SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,115	// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.116	XcmPassthrough<RuntimeOrigin>,117);118119pub trait TryPass {120	fn try_pass<Call>(121		origin: &MultiLocation,122		message: &mut [Instruction<Call>],123	) -> Result<(), ProcessMessageError>;124}125126#[impl_trait_for_tuples::impl_for_tuples(30)]127impl TryPass for Tuple {128	fn try_pass<Call>(129		origin: &MultiLocation,130		message: &mut [Instruction<Call>],131	) -> Result<(), ProcessMessageError> {132		for_tuples!( #(133			Tuple::try_pass(origin, message)?;134		)* );135136		Ok(())137	}138}139140/// Deny executing the XCM if it matches any of the Deny filter regardless of anything else.141/// If it passes the Deny, and matches one of the Allow cases then it is let through.142pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)143where144	Deny: TryPass,145	Allow: ShouldExecute;146147impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>148where149	Deny: TryPass,150	Allow: ShouldExecute,151{152	fn should_execute<Call>(153		origin: &MultiLocation,154		message: &mut [Instruction<Call>],155		max_weight: Weight,156		weight_credit: &mut Weight,157	) -> Result<(), ProcessMessageError> {158		Deny::try_pass(origin, message)?;159		Allow::should_execute(origin, message, max_weight, weight_credit)160	}161}162163pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;164165pub struct XcmCallFilter;166impl XcmCallFilter {167	fn allow_gov_and_sys_call(call: &RuntimeCall) -> bool {168		match call {169			RuntimeCall::System(..) => true,170171			#[cfg(feature = "governance")]172			RuntimeCall::Identity(..)173			| RuntimeCall::Preimage(..)174			| RuntimeCall::Democracy(..)175			| RuntimeCall::Council(..)176			| RuntimeCall::TechnicalCommittee(..)177			| RuntimeCall::CouncilMembership(..)178			| RuntimeCall::TechnicalCommitteeMembership(..)179			| RuntimeCall::FellowshipCollective(..)180			| RuntimeCall::FellowshipReferenda(..) => true,181			_ => false,182		}183	}184185	fn allow_utility_call(call: &RuntimeCall) -> bool {186		match call {187			RuntimeCall::Utility(pallet_utility::Call::batch { calls, .. }) => {188				calls.iter().all(|call| Self::allow_gov_and_sys_call(call))189			}190			RuntimeCall::Utility(pallet_utility::Call::batch_all { calls, .. }) => {191				calls.iter().all(|call| Self::allow_gov_and_sys_call(call))192			}193			RuntimeCall::Utility(pallet_utility::Call::as_derivative { call, .. }) => {194				Self::allow_gov_and_sys_call(call)195			}196			RuntimeCall::Utility(pallet_utility::Call::dispatch_as { call, .. }) => {197				Self::allow_gov_and_sys_call(call)198			}199			RuntimeCall::Utility(pallet_utility::Call::force_batch { calls, .. }) => {200				calls.iter().all(|call| Self::allow_gov_and_sys_call(call))201			}202			_ => false,203		}204	}205}206207impl Contains<RuntimeCall> for XcmCallFilter {208	fn contains(call: &RuntimeCall) -> bool {209		Self::allow_gov_and_sys_call(call) || Self::allow_utility_call(call)210	}211}212213pub struct XcmExecutorConfig<T>(PhantomData<T>);214impl<T> xcm_executor::Config for XcmExecutorConfig<T>215where216	T: pallet_configuration::Config,217{218	type RuntimeCall = RuntimeCall;219	type XcmSender = XcmRouter;220	// How to withdraw and deposit an asset.221	type AssetTransactor = AssetTransactor;222	type OriginConverter = XcmOriginToTransactDispatchOrigin;223	type IsReserve = IsReserve;224	type IsTeleporter = (); // Teleportation is disabled225	type UniversalLocation = UniversalLocation;226	type Barrier = Barrier;227	type Weigher = Weigher;228	type Trader = Trader<T>;229	type ResponseHandler = PolkadotXcm;230	type SubscriptionService = PolkadotXcm;231	type PalletInstancesInfo = AllPalletsWithSystem;232	type MaxAssetsIntoHolding = ConstU32<8>;233234	type AssetTrap = PolkadotXcm;235	type AssetClaims = PolkadotXcm;236	type AssetLocker = ();237	type AssetExchanger = ();238	type FeeManager = ();239	type MessageExporter = ();240	type UniversalAliases = Nothing;241	type CallDispatcher = RuntimeCall;242	type SafeCallFilter = XcmCallFilter;243}244245#[cfg(feature = "runtime-benchmarks")]246parameter_types! {247	pub ReachableDest: Option<MultiLocation> = Some(Parent.into());248}249250impl pallet_xcm::Config for Runtime {251	type RuntimeEvent = RuntimeEvent;252	type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;253	type XcmRouter = XcmRouter;254	type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;255	type XcmExecuteFilter = Everything;256	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;257	type XcmTeleportFilter = Everything;258	type XcmReserveTransferFilter = Everything;259	type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;260	type RuntimeOrigin = RuntimeOrigin;261	type RuntimeCall = RuntimeCall;262	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;263	type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;264	type UniversalLocation = UniversalLocation;265	type Currency = Balances;266	type CurrencyMatcher = ();267	type TrustedLockers = ();268	type SovereignAccountOf = LocationToAccountId;269	type MaxLockers = ConstU32<8>;270	type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;271	type AdminOrigin = EnsureRoot<AccountId>;272	type MaxRemoteLockConsumers = ConstU32<0>;273	type RemoteLockConsumerIdentifier = ();274	#[cfg(feature = "runtime-benchmarks")]275	type ReachableDest = ReachableDest;276}277278impl cumulus_pallet_xcm::Config for Runtime {279	type RuntimeEvent = RuntimeEvent;280	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;281}282283impl cumulus_pallet_xcmp_queue::Config for Runtime {284	type WeightInfo = ();285	type RuntimeEvent = RuntimeEvent;286	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;287	type ChannelInfo = ParachainSystem;288	type VersionWrapper = PolkadotXcm;289	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;290291	#[cfg(feature = "governance")]292	type ControllerOrigin = governance::RootOrTechnicalCommitteeMember;293294	#[cfg(not(feature = "governance"))]295	type ControllerOrigin = frame_system::EnsureRoot<AccountId>;296297	type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;298	type PriceForSiblingDelivery = ();299}300301impl cumulus_pallet_dmp_queue::Config for Runtime {302	type RuntimeEvent = RuntimeEvent;303	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;304	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;305}
addedvendor/baedeker-librarydiffbeforeafterboth

binary blob — no preview