mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 04:41:03 +00:00
Enable Pallet XCM for Kusama & Westend (#2970)
* Enable Pallet XCM for Kusama & Westend * Fixes Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -68,6 +68,7 @@ pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/parityt
|
||||
pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-vesting = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-xcm = { path = "../../xcm/pallet-xcm", default-features = false }
|
||||
|
||||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
|
||||
frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
|
||||
@@ -146,6 +147,7 @@ std = [
|
||||
"pallet-treasury/std",
|
||||
"pallet-utility/std",
|
||||
"pallet-vesting/std",
|
||||
"pallet-xcm/std",
|
||||
"pallet-babe/std",
|
||||
"pallet-randomness-collective-flip/std",
|
||||
"frame-executive/std",
|
||||
@@ -194,6 +196,7 @@ runtime-benchmarks = [
|
||||
"pallet-vesting/runtime-benchmarks",
|
||||
"pallet-offences-benchmarking",
|
||||
"pallet-session-benchmarking",
|
||||
"pallet-xcm/runtime-benchmarks",
|
||||
"frame-system-benchmarking",
|
||||
"hex-literal",
|
||||
"xcm-builder/runtime-benchmarks",
|
||||
|
||||
@@ -53,13 +53,13 @@ use runtime_parachains::scheduler as parachains_scheduler;
|
||||
use runtime_parachains::reward_points as parachains_reward_points;
|
||||
use runtime_parachains::runtime_api_impl::v1 as parachains_runtime_api_impl;
|
||||
|
||||
use xcm::v0::{MultiLocation, NetworkId};
|
||||
use xcm::v0::{MultiLocation, NetworkId, Xcm};
|
||||
use xcm_executor::XcmExecutor;
|
||||
use xcm_builder::{
|
||||
AccountId32Aliases, ChildParachainConvertsVia, SovereignSignedViaLocation, CurrencyAdapter as XcmCurrencyAdapter,
|
||||
ChildParachainAsNative, SignedAccountId32AsNative, ChildSystemParachainAsSuperuser, LocationInverter, IsConcrete,
|
||||
FixedWeightBounds, TakeWeightCredit, AllowTopLevelPaidExecutionFrom,
|
||||
AllowUnpaidExecutionFrom, IsChildSystemParachain, UsingComponents,
|
||||
FixedWeightBounds, TakeWeightCredit, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,
|
||||
IsChildSystemParachain, UsingComponents, SignedToAccountId32,
|
||||
};
|
||||
|
||||
use sp_runtime::{
|
||||
@@ -115,7 +115,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("westend"),
|
||||
impl_name: create_runtime_str!("parity-westend"),
|
||||
authoring_version: 2,
|
||||
spec_version: 900,
|
||||
spec_version: 9000,
|
||||
impl_version: 0,
|
||||
#[cfg(not(feature = "disable-runtime-api"))]
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
@@ -858,6 +858,72 @@ impl xcm_executor::Config for XcmConfig {
|
||||
type ResponseHandler = ();
|
||||
}
|
||||
|
||||
/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location
|
||||
/// of this chain.
|
||||
pub type LocalOriginToLocation = (
|
||||
// And a usual Signed origin to be used in XCM as a corresponding AccountId32
|
||||
SignedToAccountId32<Origin, AccountId, WestendNetwork>,
|
||||
);
|
||||
|
||||
pub struct OnlyWithdrawTeleportForAccounts;
|
||||
impl frame_support::traits::Contains<(MultiLocation, Xcm<Call>)> for OnlyWithdrawTeleportForAccounts {
|
||||
fn contains((ref origin, ref msg): &(MultiLocation, Xcm<Call>)) -> bool {
|
||||
use xcm::v0::{
|
||||
Xcm::WithdrawAsset, Order::{BuyExecution, InitiateTeleport, DepositAsset},
|
||||
MultiAsset::{All, ConcreteFungible}, Junction::{AccountId32, Parachain},
|
||||
MultiLocation::{Null, X1},
|
||||
};
|
||||
match origin {
|
||||
// Root is allowed to execute anything.
|
||||
Null => true,
|
||||
X1(AccountId32 { .. }) => {
|
||||
// An account ID trying to send a message. We ensure that it's sensible.
|
||||
// This checks that it's of the form:
|
||||
// WithdrawAsset {
|
||||
// assets: [ ConcreteFungible { id: Null } ],
|
||||
// effects: [ BuyExecution, InitiateTeleport {
|
||||
// assets: All,
|
||||
// dest: Parachain,
|
||||
// effects: [ BuyExecution, DepositAssets {
|
||||
// assets: All,
|
||||
// dest: AccountId32,
|
||||
// } ]
|
||||
// } ]
|
||||
// }
|
||||
matches!(msg, WithdrawAsset { ref assets, ref effects }
|
||||
if assets.len() == 1
|
||||
&& matches!(assets[0], ConcreteFungible { id: Null, .. })
|
||||
&& effects.len() == 2
|
||||
&& matches!(effects[0], BuyExecution { .. })
|
||||
&& matches!(effects[1], InitiateTeleport { ref assets, dest: X1(Parachain(..)), ref effects }
|
||||
if assets.len() == 1
|
||||
&& matches!(assets[0], All)
|
||||
&& effects.len() == 2
|
||||
&& matches!(effects[0], BuyExecution { .. })
|
||||
&& matches!(effects[1], DepositAsset { ref assets, dest: X1(AccountId32{..}) }
|
||||
if assets.len() == 1
|
||||
&& matches!(assets[0], All)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
// Nobody else is allowed to execute anything.
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_xcm::Config for Runtime {
|
||||
type Event = Event;
|
||||
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
|
||||
type XcmRouter = XcmRouter;
|
||||
// Anyone can execute XCM messages locally...
|
||||
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
|
||||
// ...but they must match our filter, which requires them to be a simple withdraw + teleport.
|
||||
type XcmExecuteFilter = OnlyWithdrawTeleportForAccounts;
|
||||
type XcmExecutor = XcmExecutor<XcmConfig>;
|
||||
}
|
||||
|
||||
construct_runtime! {
|
||||
pub enum Runtime where
|
||||
Block = Block,
|
||||
@@ -931,6 +997,9 @@ construct_runtime! {
|
||||
Registrar: paras_registrar::{Pallet, Call, Storage, Event<T>} = 60,
|
||||
Slots: slots::{Pallet, Call, Storage, Event<T>} = 61,
|
||||
ParasSudoWrapper: paras_sudo_wrapper::{Pallet, Call} = 62,
|
||||
|
||||
// Pallet for sending XCM.
|
||||
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>} = 99,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user