diff --git a/runtime/common/src/xcm_sender.rs b/runtime/common/src/xcm_sender.rs index 4ccd9074d87b..0b817a237fb9 100644 --- a/runtime/common/src/xcm_sender.rs +++ b/runtime/common/src/xcm_sender.rs @@ -27,7 +27,7 @@ pub struct ChildParachainRouter(PhantomData); impl SendXcm for ChildParachainRouter { fn send_xcm(dest: MultiLocation, msg: Xcm) -> Result { match dest { - MultiLocation::X1(Junction::Parachain { id }) => { + MultiLocation::X1(Junction::Parachain(id)) => { // Downward message passing. let config = >::config(); >::queue_downward_message( diff --git a/runtime/parachains/src/ump.rs b/runtime/parachains/src/ump.rs index f1998ba7ddf6..bc9fa4d7905e 100644 --- a/runtime/parachains/src/ump.rs +++ b/runtime/parachains/src/ump.rs @@ -69,7 +69,7 @@ impl, Call> UmpSink for XcmSink { - let xcm_junction: Junction = Junction::Parachain { id: origin.into() }; + let xcm_junction: Junction = Junction::Parachain(origin.into()); let xcm_location: MultiLocation = xcm_junction.into(); match XcmExecutor::execute_xcm(xcm_location, xcm_message, max_weight) { Outcome::Complete(w) | Outcome::Incomplete(w, _) => Some(w), diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 2ef95f3820b8..951afb4a2a09 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -603,13 +603,13 @@ pub type XcmRouter = ( use xcm::v0::{MultiAsset, MultiAsset::AllConcreteFungible, MultiLocation::{Null, X1}, Junction::Parachain}; parameter_types! { pub const RococoForTick: (MultiAsset, MultiLocation) = - (AllConcreteFungible { id: Null }, X1(Parachain{id: 100})); + (AllConcreteFungible { id: Null }, X1(Parachain(100))); pub const RococoForTrick: (MultiAsset, MultiLocation) = - (AllConcreteFungible { id: Null }, X1(Parachain{id: 110})); + (AllConcreteFungible { id: Null }, X1(Parachain(110))); pub const RococoForTrack: (MultiAsset, MultiLocation) = - (AllConcreteFungible { id: Null }, X1(Parachain{id: 120})); + (AllConcreteFungible { id: Null }, X1(Parachain(120))); pub const RococoForStatemint: (MultiAsset, MultiLocation) = - (AllConcreteFungible { id: Null }, X1(Parachain{id: 1})); + (AllConcreteFungible { id: Null }, X1(Parachain(1))); } pub type TrustedTeleporters = ( xcm_builder::Case, @@ -621,10 +621,10 @@ pub type TrustedTeleporters = ( parameter_types! { pub AllowUnpaidFrom: Vec = vec![ - X1(Parachain{id: 100}), - X1(Parachain{id: 110}), - X1(Parachain{id: 120}), - X1(Parachain{id: 1}) + X1(Parachain(100)), + X1(Parachain(110)), + X1(Parachain(120)), + X1(Parachain(1)) ]; } diff --git a/xcm/src/v0/junction.rs b/xcm/src/v0/junction.rs index 1cde3cf86430..2f3af556b462 100644 --- a/xcm/src/v0/junction.rs +++ b/xcm/src/v0/junction.rs @@ -94,11 +94,7 @@ pub enum Junction { /// An indexed parachain belonging to and operated by the context. /// /// Generally used when the context is a Polkadot Relay-chain. - /// - /// There is also `Parachain` which can be used in tests to avoid the faffy `{ id: ... }` syntax. Production - /// code should use this. - // TODO: parity-scale-codec#262: Change to be `Parachain(#[codec(compact)] u32)` - Parachain { #[codec(compact)] id: u32 }, + Parachain(#[codec(compact)] u32), /// A 32-byte identifier for an account of a specific network that is respected as a sovereign endpoint within /// the context. /// @@ -148,7 +144,7 @@ impl Junction { match self { Junction::Parent => false, - Junction::Parachain { .. } + Junction::Parachain(..) | Junction::AccountId32 { .. } | Junction::AccountIndex64 { .. } | Junction::AccountKey20 { .. } diff --git a/xcm/xcm-builder/src/location_conversion.rs b/xcm/xcm-builder/src/location_conversion.rs index 938ebc66730d..44b25e1358bc 100644 --- a/xcm/xcm-builder/src/location_conversion.rs +++ b/xcm/xcm-builder/src/location_conversion.rs @@ -64,7 +64,7 @@ impl< AccountId: Clone, > Convert for ChildParachainConvertsVia { fn convert_ref(location: impl Borrow) -> Result { - if let &MultiLocation::X1(Junction::Parachain { id }) = location.borrow() { + if let &MultiLocation::X1(Junction::Parachain(id)) = location.borrow() { Ok(ParaId::from(id).into_account()) } else { Err(()) @@ -73,7 +73,7 @@ impl< fn reverse_ref(who: impl Borrow) -> Result { if let Some(id) = ParaId::try_from_account(who.borrow()) { - Ok(Junction::Parachain { id: id.into() }.into()) + Ok(Junction::Parachain(id.into()).into()) } else { Err(()) } @@ -87,7 +87,7 @@ impl< AccountId: Clone, > Convert for SiblingParachainConvertsVia { fn convert_ref(location: impl Borrow) -> Result { - if let &MultiLocation::X2(Junction::Parent, Junction::Parachain { id }) = location.borrow() { + if let &MultiLocation::X2(Junction::Parent, Junction::Parachain(id)) = location.borrow() { Ok(ParaId::from(id).into_account()) } else { Err(()) @@ -96,7 +96,7 @@ impl< fn reverse_ref(who: impl Borrow) -> Result { if let Some(id) = ParaId::try_from_account(who.borrow()) { - Ok([Junction::Parent, Junction::Parachain { id: id.into() }].into()) + Ok([Junction::Parent, Junction::Parachain(id.into())].into()) } else { Err(()) } diff --git a/xcm/xcm-builder/src/mock.rs b/xcm/xcm-builder/src/mock.rs index 599fdbfcd2ee..348cf0b94449 100644 --- a/xcm/xcm-builder/src/mock.rs +++ b/xcm/xcm-builder/src/mock.rs @@ -144,11 +144,11 @@ impl TransactAsset for TestAssetTransactor { pub fn to_account(l: MultiLocation) -> Result { Ok(match l { // Siblings at 2000+id - X2(Parent, Parachain { id }) => 2000 + id as u64, + X2(Parent, Parachain(id)) => 2000 + id as u64, // Accounts are their number X1(AccountIndex64 { index, .. }) => index, // Children at 1000+id - X1(Parachain { id }) => 1000 + id as u64, + X1(Parachain(id)) => 1000 + id as u64, // Self at 3000 Null => 3000, // Parent at 3000 @@ -160,11 +160,11 @@ pub fn to_account(l: MultiLocation) -> Result { pub struct TestOriginConverter; impl ConvertOrigin for TestOriginConverter { fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result { - use {OriginKind::*}; + use OriginKind::*; match (kind, origin) { (Superuser, _) => Ok(TestOrigin::Root), (SovereignAccount, l) => Ok(TestOrigin::Signed(to_account(l)?)), - (Native, X1(Parachain { id })) => Ok(TestOrigin::Parachain(id)), + (Native, X1(Parachain(id))) => Ok(TestOrigin::Parachain(id)), (Native, X1(Parent)) => Ok(TestOrigin::Relay), (Native, X1(AccountIndex64 {index, ..})) => Ok(TestOrigin::Signed(index)), (_, origin) => Err(origin), @@ -243,7 +243,7 @@ pub fn response(query_id: u64) -> Option { } parameter_types! { - pub TestAncestry: MultiLocation = X1(Parachain{id: 42}); + pub TestAncestry: MultiLocation = X1(Parachain(42)); pub UnitWeightCost: Weight = 10; } parameter_types! { diff --git a/xcm/xcm-builder/src/origin_conversion.rs b/xcm/xcm-builder/src/origin_conversion.rs index 37037171ba4d..134dfc30821f 100644 --- a/xcm/xcm-builder/src/origin_conversion.rs +++ b/xcm/xcm-builder/src/origin_conversion.rs @@ -60,7 +60,7 @@ impl< > ConvertOrigin for ChildSystemParachainAsSuperuser { fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result { match (kind, origin) { - (OriginKind::Superuser, MultiLocation::X1(Junction::Parachain { id })) + (OriginKind::Superuser, MultiLocation::X1(Junction::Parachain(id))) if ParaId::from(id).is_system() => Ok(Origin::root()), (_, origin) => Err(origin), @@ -75,7 +75,7 @@ impl< > ConvertOrigin for SiblingSystemParachainAsSuperuser { fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result { match (kind, origin) { - (OriginKind::Superuser, MultiLocation::X2(Junction::Parent, Junction::Parachain { id })) + (OriginKind::Superuser, MultiLocation::X2(Junction::Parent, Junction::Parachain(id))) if ParaId::from(id).is_system() => Ok(Origin::root()), (_, origin) => Err(origin), @@ -92,7 +92,7 @@ impl< > ConvertOrigin for ChildParachainAsNative { fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result { match (kind, origin) { - (OriginKind::Native, MultiLocation::X1(Junction::Parachain { id })) + (OriginKind::Native, MultiLocation::X1(Junction::Parachain(id))) => Ok(Origin::from(ParachainOrigin::from(id))), (_, origin) => Err(origin), } @@ -108,7 +108,7 @@ impl< > ConvertOrigin for SiblingParachainAsNative { fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result { match (kind, origin) { - (OriginKind::Native, MultiLocation::X2(Junction::Parent, Junction::Parachain { id })) + (OriginKind::Native, MultiLocation::X2(Junction::Parent, Junction::Parachain(id))) => Ok(Origin::from(ParachainOrigin::from(id))), (_, origin) => Err(origin), } diff --git a/xcm/xcm-builder/src/tests.rs b/xcm/xcm-builder/src/tests.rs index 09bce676491b..0f04b89285d1 100644 --- a/xcm/xcm-builder/src/tests.rs +++ b/xcm/xcm-builder/src/tests.rs @@ -28,10 +28,10 @@ fn basic_setup_works() { &X1(Parent), )); - assert_eq!(to_account(X1(Parachain{id:1})), Ok(1001)); - assert_eq!(to_account(X1(Parachain{id:50})), Ok(1050)); - assert_eq!(to_account(X2(Parent, Parachain{id:1})), Ok(2001)); - assert_eq!(to_account(X2(Parent, Parachain{id:50})), Ok(2050)); + assert_eq!(to_account(X1(Parachain(1))), Ok(1001)); + assert_eq!(to_account(X1(Parachain(50))), Ok(1050)); + assert_eq!(to_account(X2(Parent, Parachain(1))), Ok(2001)); + assert_eq!(to_account(X2(Parent, Parachain(50))), Ok(2050)); assert_eq!(to_account(X1(AccountIndex64{index:1, network:Any})), Ok(1)); assert_eq!(to_account(X1(AccountIndex64{index:42, network:Any})), Ok(42)); assert_eq!(to_account(Null), Ok(3000)); @@ -88,7 +88,7 @@ fn allow_unpaid_should_work() { AllowUnpaidFrom::set(vec![ X1(Parent) ]); let r = AllowUnpaidExecutionFrom::>::should_execute( - &X1(Parachain { id: 1 }), + &X1(Parachain(1)), true, &mut message, 10, @@ -116,7 +116,7 @@ fn allow_paid_should_work() { }; let r = AllowTopLevelPaidExecutionFrom::>::should_execute( - &X1(Parachain { id: 1 }), + &X1(Parachain(1)), true, &mut message, 10, @@ -150,7 +150,7 @@ fn allow_paid_should_work() { }; let r = AllowTopLevelPaidExecutionFrom::>::should_execute( - &X1(Parachain { id: 1 }), + &X1(Parachain(1)), true, &mut paying_message, 30, @@ -191,12 +191,12 @@ fn paying_reserve_deposit_should_work() { #[test] fn transfer_should_work() { // we'll let them have message execution for free. - AllowUnpaidFrom::set(vec![ X1(Parachain{id:1}) ]); + AllowUnpaidFrom::set(vec![ X1(Parachain(1)) ]); // Child parachain #1 owns 1000 tokens held by us in reserve. add_asset(1001, ConcreteFungible { id: Null, amount: 1000 }); // They want to transfer 100 of them to their sibling parachain #2 let r = XcmExecutor::::execute_xcm( - X1(Parachain{id:1}), + X1(Parachain(1)), Xcm::TransferAsset { assets: vec![ ConcreteFungible { id: Null, amount: 100 } ], dest: X1(AccountIndex64{index:3, network:Any}), @@ -211,7 +211,7 @@ fn transfer_should_work() { #[test] fn reserve_transfer_should_work() { - AllowUnpaidFrom::set(vec![ X1(Parachain{id:1}) ]); + AllowUnpaidFrom::set(vec![ X1(Parachain(1)) ]); // Child parachain #1 owns 1000 tokens held by us in reserve. add_asset(1001, ConcreteFungible { id: Null, amount: 1000 }); // The remote account owned by gav. @@ -220,10 +220,10 @@ fn reserve_transfer_should_work() { // They want to transfer 100 of our native asset from sovereign account of parachain #1 into #2 // and let them know to hand it to account #3. let r = XcmExecutor::::execute_xcm( - X1(Parachain{id:1}), + X1(Parachain(1)), Xcm::TransferReserveAsset { assets: vec![ ConcreteFungible { id: Null, amount: 100 } ], - dest: X1(Parachain{id:2}), + dest: X1(Parachain(2)), effects: vec![ Order::DepositAsset { assets: vec![ All ], dest: three.clone() } ], }, 50, @@ -232,7 +232,7 @@ fn reserve_transfer_should_work() { assert_eq!(assets(1002), vec![ ConcreteFungible { id: Null, amount: 100 } ]); assert_eq!(sent_xcm(), vec![( - X1(Parachain { id: 2 }), + X1(Parachain(2)), Xcm::ReserveAssetDeposit { assets: vec![ ConcreteFungible { id: X1(Parent), amount: 100 } ], effects: vec![ Order::DepositAsset { assets: vec![ All ], dest: three } ],