mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Make most XCM APIs accept an Into<MultiLocation> where MultiLocation is accepted (#3627)
* Change send_xcm MultiLocation argument to be generic * Change pallet_xcm::send_xcm MultiLocation and Junctions argument to be generic * Change convert_origin MultiLocation argument to be generic * Change OnResponse MultiLocation arguments to be generic * Change UniversalWeigher MultiLocation argumente to be generic * Change ExecuteXcm MultiLocation argument to be generic * Remove usages of into for the MultiLocation argument in execute_xcm * Make use of generic MultiLocation arguments in rustdocs * Cargo fmt * Remove unused import in tests * Resolve conflicts * cargo fmt * Appease spellcheck * impl Into<MultiLocation> in more places
This commit is contained in:
@@ -27,7 +27,8 @@ pub struct ChildParachainRouter<T, W>(PhantomData<(T, W)>);
|
|||||||
impl<T: configuration::Config + dmp::Config, W: xcm::WrapVersion> SendXcm
|
impl<T: configuration::Config + dmp::Config, W: xcm::WrapVersion> SendXcm
|
||||||
for ChildParachainRouter<T, W>
|
for ChildParachainRouter<T, W>
|
||||||
{
|
{
|
||||||
fn send_xcm(dest: MultiLocation, msg: Xcm<()>) -> SendResult {
|
fn send_xcm(dest: impl Into<MultiLocation>, msg: Xcm<()>) -> SendResult {
|
||||||
|
let dest = dest.into();
|
||||||
match dest {
|
match dest {
|
||||||
MultiLocation { parents: 0, interior: X1(Parachain(id)) } => {
|
MultiLocation { parents: 0, interior: X1(Parachain(id)) } => {
|
||||||
// Downward message passing.
|
// Downward message passing.
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ impl<XcmExecutor: xcm::latest::ExecuteXcm<C::Call>, C: Config> UmpSink for XcmSi
|
|||||||
) -> Result<Weight, (MessageId, Weight)> {
|
) -> Result<Weight, (MessageId, Weight)> {
|
||||||
use parity_scale_codec::DecodeLimit;
|
use parity_scale_codec::DecodeLimit;
|
||||||
use xcm::{
|
use xcm::{
|
||||||
latest::{Error as XcmError, Junction, MultiLocation, Xcm},
|
latest::{Error as XcmError, Junction, Xcm},
|
||||||
VersionedXcm,
|
VersionedXcm,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -111,9 +111,8 @@ impl<XcmExecutor: xcm::latest::ExecuteXcm<C::Call>, C: Config> UmpSink for XcmSi
|
|||||||
Ok(0)
|
Ok(0)
|
||||||
},
|
},
|
||||||
Ok(Ok(xcm_message)) => {
|
Ok(Ok(xcm_message)) => {
|
||||||
let xcm_junction: Junction = Junction::Parachain(origin.into());
|
let xcm_junction = Junction::Parachain(origin.into());
|
||||||
let xcm_location: MultiLocation = xcm_junction.into();
|
let outcome = XcmExecutor::execute_xcm(xcm_junction, xcm_message, max_weight);
|
||||||
let outcome = XcmExecutor::execute_xcm(xcm_location, xcm_message, max_weight);
|
|
||||||
match outcome {
|
match outcome {
|
||||||
Outcome::Error(XcmError::WeightLimitReached(required)) => Err((id, required)),
|
Outcome::Error(XcmError::WeightLimitReached(required)) => Err((id, required)),
|
||||||
outcome => {
|
outcome => {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ pub type LocalOriginToLocation = (
|
|||||||
|
|
||||||
pub struct DoNothingRouter;
|
pub struct DoNothingRouter;
|
||||||
impl SendXcm for DoNothingRouter {
|
impl SendXcm for DoNothingRouter {
|
||||||
fn send_xcm(_dest: MultiLocation, _msg: Xcm<()>) -> SendResult {
|
fn send_xcm(_dest: impl Into<MultiLocation>, _msg: Xcm<()>) -> SendResult {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -426,7 +426,7 @@ pub mod pallet {
|
|||||||
weight_used += T::DbWeight::get().read + T::DbWeight::get().write;
|
weight_used += T::DbWeight::get().read + T::DbWeight::get().write;
|
||||||
q.sort_by_key(|i| i.1);
|
q.sort_by_key(|i| i.1);
|
||||||
while let Some((versioned_dest, _)) = q.pop() {
|
while let Some((versioned_dest, _)) = q.pop() {
|
||||||
if let Ok(dest) = versioned_dest.try_into() {
|
if let Ok(dest) = MultiLocation::try_from(versioned_dest) {
|
||||||
if Self::request_version_notify(dest).is_ok() {
|
if Self::request_version_notify(dest).is_ok() {
|
||||||
// TODO: correct weights.
|
// TODO: correct weights.
|
||||||
weight_used += T::DbWeight::get().read + T::DbWeight::get().write;
|
weight_used += T::DbWeight::get().read + T::DbWeight::get().write;
|
||||||
@@ -458,7 +458,7 @@ pub mod pallet {
|
|||||||
message: Box<VersionedXcm<()>>,
|
message: Box<VersionedXcm<()>>,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
let origin_location = T::SendXcmOrigin::ensure_origin(origin)?;
|
let origin_location = T::SendXcmOrigin::ensure_origin(origin)?;
|
||||||
let interior =
|
let interior: Junctions =
|
||||||
origin_location.clone().try_into().map_err(|_| Error::<T>::InvalidOrigin)?;
|
origin_location.clone().try_into().map_err(|_| Error::<T>::InvalidOrigin)?;
|
||||||
let dest = MultiLocation::try_from(*dest).map_err(|()| Error::<T>::BadVersion)?;
|
let dest = MultiLocation::try_from(*dest).map_err(|()| Error::<T>::BadVersion)?;
|
||||||
let message: Xcm<()> = (*message).try_into().map_err(|()| Error::<T>::BadVersion)?;
|
let message: Xcm<()> = (*message).try_into().map_err(|()| Error::<T>::BadVersion)?;
|
||||||
@@ -688,7 +688,8 @@ pub mod pallet {
|
|||||||
location: Box<VersionedMultiLocation>,
|
location: Box<VersionedMultiLocation>,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
let location = (*location).try_into().map_err(|()| Error::<T>::BadLocation)?;
|
let location: MultiLocation =
|
||||||
|
(*location).try_into().map_err(|()| Error::<T>::BadLocation)?;
|
||||||
Self::request_version_notify(location).map_err(|e| {
|
Self::request_version_notify(location).map_err(|e| {
|
||||||
match e {
|
match e {
|
||||||
XcmError::InvalidLocation => Error::<T>::AlreadySubscribed,
|
XcmError::InvalidLocation => Error::<T>::AlreadySubscribed,
|
||||||
@@ -710,7 +711,8 @@ pub mod pallet {
|
|||||||
location: Box<VersionedMultiLocation>,
|
location: Box<VersionedMultiLocation>,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
let location = (*location).try_into().map_err(|()| Error::<T>::BadLocation)?;
|
let location: MultiLocation =
|
||||||
|
(*location).try_into().map_err(|()| Error::<T>::BadLocation)?;
|
||||||
Self::unrequest_version_notify(location).map_err(|e| {
|
Self::unrequest_version_notify(location).map_err(|e| {
|
||||||
match e {
|
match e {
|
||||||
XcmError::InvalidLocation => Error::<T>::NoSubscription,
|
XcmError::InvalidLocation => Error::<T>::NoSubscription,
|
||||||
@@ -867,7 +869,8 @@ pub mod pallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Request that `dest` informs us of its version.
|
/// Request that `dest` informs us of its version.
|
||||||
pub fn request_version_notify(dest: MultiLocation) -> XcmResult {
|
pub fn request_version_notify(dest: impl Into<MultiLocation>) -> XcmResult {
|
||||||
|
let dest = dest.into();
|
||||||
let versioned_dest = VersionedMultiLocation::from(dest.clone());
|
let versioned_dest = VersionedMultiLocation::from(dest.clone());
|
||||||
let already = VersionNotifiers::<T>::contains_key(XCM_VERSION, &versioned_dest);
|
let already = VersionNotifiers::<T>::contains_key(XCM_VERSION, &versioned_dest);
|
||||||
ensure!(!already, XcmError::InvalidLocation);
|
ensure!(!already, XcmError::InvalidLocation);
|
||||||
@@ -887,7 +890,8 @@ pub mod pallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Request that `dest` ceases informing us of its version.
|
/// Request that `dest` ceases informing us of its version.
|
||||||
pub fn unrequest_version_notify(dest: MultiLocation) -> XcmResult {
|
pub fn unrequest_version_notify(dest: impl Into<MultiLocation>) -> XcmResult {
|
||||||
|
let dest = dest.into();
|
||||||
let versioned_dest = LatestVersionedMultiLocation(&dest);
|
let versioned_dest = LatestVersionedMultiLocation(&dest);
|
||||||
let query_id = VersionNotifiers::<T>::take(XCM_VERSION, versioned_dest)
|
let query_id = VersionNotifiers::<T>::take(XCM_VERSION, versioned_dest)
|
||||||
.ok_or(XcmError::InvalidLocation)?;
|
.ok_or(XcmError::InvalidLocation)?;
|
||||||
@@ -899,10 +903,12 @@ pub mod pallet {
|
|||||||
/// Relay an XCM `message` from a given `interior` location in this context to a given `dest`
|
/// Relay an XCM `message` from a given `interior` location in this context to a given `dest`
|
||||||
/// location. A null `dest` is not handled.
|
/// location. A null `dest` is not handled.
|
||||||
pub fn send_xcm(
|
pub fn send_xcm(
|
||||||
interior: Junctions,
|
interior: impl Into<Junctions>,
|
||||||
dest: MultiLocation,
|
dest: impl Into<MultiLocation>,
|
||||||
mut message: Xcm<()>,
|
mut message: Xcm<()>,
|
||||||
) -> Result<(), SendError> {
|
) -> Result<(), SendError> {
|
||||||
|
let interior = interior.into();
|
||||||
|
let dest = dest.into();
|
||||||
if interior != Junctions::Here {
|
if interior != Junctions::Here {
|
||||||
message.0.insert(0, DescendOrigin(interior))
|
message.0.insert(0, DescendOrigin(interior))
|
||||||
};
|
};
|
||||||
@@ -916,7 +922,7 @@ pub mod pallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn do_new_query(
|
fn do_new_query(
|
||||||
responder: MultiLocation,
|
responder: impl Into<MultiLocation>,
|
||||||
maybe_notify: Option<(u8, u8)>,
|
maybe_notify: Option<(u8, u8)>,
|
||||||
timeout: T::BlockNumber,
|
timeout: T::BlockNumber,
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
@@ -925,7 +931,11 @@ pub mod pallet {
|
|||||||
q.saturating_inc();
|
q.saturating_inc();
|
||||||
Queries::<T>::insert(
|
Queries::<T>::insert(
|
||||||
r,
|
r,
|
||||||
QueryStatus::Pending { responder: responder.into(), maybe_notify, timeout },
|
QueryStatus::Pending {
|
||||||
|
responder: responder.into().into(),
|
||||||
|
maybe_notify,
|
||||||
|
timeout,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
r
|
r
|
||||||
})
|
})
|
||||||
@@ -945,9 +955,10 @@ pub mod pallet {
|
|||||||
/// value.
|
/// value.
|
||||||
pub fn report_outcome(
|
pub fn report_outcome(
|
||||||
message: &mut Xcm<()>,
|
message: &mut Xcm<()>,
|
||||||
responder: MultiLocation,
|
responder: impl Into<MultiLocation>,
|
||||||
timeout: T::BlockNumber,
|
timeout: T::BlockNumber,
|
||||||
) -> Result<QueryId, XcmError> {
|
) -> Result<QueryId, XcmError> {
|
||||||
|
let responder = responder.into();
|
||||||
let dest = T::LocationInverter::invert_location(&responder)
|
let dest = T::LocationInverter::invert_location(&responder)
|
||||||
.map_err(|()| XcmError::MultiLocationNotInvertible)?;
|
.map_err(|()| XcmError::MultiLocationNotInvertible)?;
|
||||||
let query_id = Self::new_query(responder, timeout);
|
let query_id = Self::new_query(responder, timeout);
|
||||||
@@ -978,10 +989,11 @@ pub mod pallet {
|
|||||||
/// may be put in the overweight queue and need to be manually executed.
|
/// may be put in the overweight queue and need to be manually executed.
|
||||||
pub fn report_outcome_notify(
|
pub fn report_outcome_notify(
|
||||||
message: &mut Xcm<()>,
|
message: &mut Xcm<()>,
|
||||||
responder: MultiLocation,
|
responder: impl Into<MultiLocation>,
|
||||||
notify: impl Into<<T as Config>::Call>,
|
notify: impl Into<<T as Config>::Call>,
|
||||||
timeout: T::BlockNumber,
|
timeout: T::BlockNumber,
|
||||||
) -> Result<(), XcmError> {
|
) -> Result<(), XcmError> {
|
||||||
|
let responder = responder.into();
|
||||||
let dest = T::LocationInverter::invert_location(&responder)
|
let dest = T::LocationInverter::invert_location(&responder)
|
||||||
.map_err(|()| XcmError::MultiLocationNotInvertible)?;
|
.map_err(|()| XcmError::MultiLocationNotInvertible)?;
|
||||||
let notify: <T as Config>::Call = notify.into();
|
let notify: <T as Config>::Call = notify.into();
|
||||||
@@ -993,14 +1005,14 @@ pub mod pallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Attempt to create a new query ID and register it as a query that is yet to respond.
|
/// Attempt to create a new query ID and register it as a query that is yet to respond.
|
||||||
pub fn new_query(responder: MultiLocation, timeout: T::BlockNumber) -> u64 {
|
pub fn new_query(responder: impl Into<MultiLocation>, timeout: T::BlockNumber) -> u64 {
|
||||||
Self::do_new_query(responder, None, timeout)
|
Self::do_new_query(responder, None, timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempt to create a new query ID and register it as a query that is yet to respond, and
|
/// Attempt to create a new query ID and register it as a query that is yet to respond, and
|
||||||
/// which will call a dispatchable when a response happens.
|
/// which will call a dispatchable when a response happens.
|
||||||
pub fn new_notify_query(
|
pub fn new_notify_query(
|
||||||
responder: MultiLocation,
|
responder: impl Into<MultiLocation>,
|
||||||
notify: impl Into<<T as Config>::Call>,
|
notify: impl Into<<T as Config>::Call>,
|
||||||
timeout: T::BlockNumber,
|
timeout: T::BlockNumber,
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
@@ -1368,7 +1380,11 @@ where
|
|||||||
/// this crate's `Origin::Xcm` value.
|
/// this crate's `Origin::Xcm` value.
|
||||||
pub struct XcmPassthrough<Origin>(PhantomData<Origin>);
|
pub struct XcmPassthrough<Origin>(PhantomData<Origin>);
|
||||||
impl<Origin: From<crate::Origin>> ConvertOrigin<Origin> for XcmPassthrough<Origin> {
|
impl<Origin: From<crate::Origin>> ConvertOrigin<Origin> for XcmPassthrough<Origin> {
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
fn convert_origin(
|
||||||
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<Origin, MultiLocation> {
|
||||||
|
let origin = origin.into();
|
||||||
match kind {
|
match kind {
|
||||||
OriginKind::Xcm => Ok(crate::Origin::Xcm(origin).into()),
|
OriginKind::Xcm => Ok(crate::Origin::Xcm(origin).into()),
|
||||||
_ => Err(origin),
|
_ => Err(origin),
|
||||||
|
|||||||
@@ -147,15 +147,16 @@ pub(crate) fn take_sent_xcm() -> Vec<(MultiLocation, Xcm<()>)> {
|
|||||||
/// Sender that never returns error, always sends
|
/// Sender that never returns error, always sends
|
||||||
pub struct TestSendXcm;
|
pub struct TestSendXcm;
|
||||||
impl SendXcm for TestSendXcm {
|
impl SendXcm for TestSendXcm {
|
||||||
fn send_xcm(dest: MultiLocation, msg: Xcm<()>) -> SendResult {
|
fn send_xcm(dest: impl Into<MultiLocation>, msg: Xcm<()>) -> SendResult {
|
||||||
SENT_XCM.with(|q| q.borrow_mut().push((dest, msg)));
|
SENT_XCM.with(|q| q.borrow_mut().push((dest.into(), msg)));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Sender that returns error if `X8` junction and stops routing
|
/// Sender that returns error if `X8` junction and stops routing
|
||||||
pub struct TestSendXcmErrX8;
|
pub struct TestSendXcmErrX8;
|
||||||
impl SendXcm for TestSendXcmErrX8 {
|
impl SendXcm for TestSendXcmErrX8 {
|
||||||
fn send_xcm(dest: MultiLocation, msg: Xcm<()>) -> SendResult {
|
fn send_xcm(dest: impl Into<MultiLocation>, msg: Xcm<()>) -> SendResult {
|
||||||
|
let dest = dest.into();
|
||||||
if dest.len() == 8 {
|
if dest.len() == 8 {
|
||||||
Err(SendError::Transport("Destination location full"))
|
Err(SendError::Transport("Destination location full"))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -338,8 +338,8 @@ impl From<Parent> for MultiLocation {
|
|||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||||
pub struct ParentThen(Junctions);
|
pub struct ParentThen(Junctions);
|
||||||
impl From<ParentThen> for MultiLocation {
|
impl From<ParentThen> for MultiLocation {
|
||||||
fn from(x: ParentThen) -> Self {
|
fn from(ParentThen(interior): ParentThen) -> Self {
|
||||||
MultiLocation { parents: 1, interior: x.0 }
|
MultiLocation { parents: 1, interior }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,8 +347,8 @@ impl From<ParentThen> for MultiLocation {
|
|||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||||
pub struct Ancestor(u8);
|
pub struct Ancestor(u8);
|
||||||
impl From<Ancestor> for MultiLocation {
|
impl From<Ancestor> for MultiLocation {
|
||||||
fn from(x: Ancestor) -> Self {
|
fn from(Ancestor(parents): Ancestor) -> Self {
|
||||||
MultiLocation { parents: x.0, interior: Junctions::Here }
|
MultiLocation { parents, interior: Junctions::Here }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,8 +356,8 @@ impl From<Ancestor> for MultiLocation {
|
|||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||||
pub struct AncestorThen(u8, Junctions);
|
pub struct AncestorThen(u8, Junctions);
|
||||||
impl From<AncestorThen> for MultiLocation {
|
impl From<AncestorThen> for MultiLocation {
|
||||||
fn from(x: AncestorThen) -> Self {
|
fn from(AncestorThen(parents, interior): AncestorThen) -> Self {
|
||||||
MultiLocation { parents: x.0, interior: x.1 }
|
MultiLocation { parents, interior }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,12 @@ pub trait ExecuteXcm<Call> {
|
|||||||
/// Execute some XCM `message` from `origin` using no more than `weight_limit` weight. The weight limit is
|
/// Execute some XCM `message` from `origin` using no more than `weight_limit` weight. The weight limit is
|
||||||
/// a basic hard-limit and the implementation may place further restrictions or requirements on weight and
|
/// a basic hard-limit and the implementation may place further restrictions or requirements on weight and
|
||||||
/// other aspects.
|
/// other aspects.
|
||||||
fn execute_xcm(origin: MultiLocation, message: Xcm<Call>, weight_limit: Weight) -> Outcome {
|
fn execute_xcm(
|
||||||
|
origin: impl Into<MultiLocation>,
|
||||||
|
message: Xcm<Call>,
|
||||||
|
weight_limit: Weight,
|
||||||
|
) -> Outcome {
|
||||||
|
let origin = origin.into();
|
||||||
log::debug!(
|
log::debug!(
|
||||||
target: "xcm::execute_xcm",
|
target: "xcm::execute_xcm",
|
||||||
"origin: {:?}, message: {:?}, weight_limit: {:?}",
|
"origin: {:?}, message: {:?}, weight_limit: {:?}",
|
||||||
@@ -162,7 +167,7 @@ pub trait ExecuteXcm<Call> {
|
|||||||
/// Some amount of `weight_credit` may be provided which, depending on the implementation, may allow
|
/// Some amount of `weight_credit` may be provided which, depending on the implementation, may allow
|
||||||
/// execution without associated payment.
|
/// execution without associated payment.
|
||||||
fn execute_xcm_in_credit(
|
fn execute_xcm_in_credit(
|
||||||
origin: MultiLocation,
|
origin: impl Into<MultiLocation>,
|
||||||
message: Xcm<Call>,
|
message: Xcm<Call>,
|
||||||
weight_limit: Weight,
|
weight_limit: Weight,
|
||||||
weight_credit: Weight,
|
weight_credit: Weight,
|
||||||
@@ -171,7 +176,7 @@ pub trait ExecuteXcm<Call> {
|
|||||||
|
|
||||||
impl<C> ExecuteXcm<C> for () {
|
impl<C> ExecuteXcm<C> for () {
|
||||||
fn execute_xcm_in_credit(
|
fn execute_xcm_in_credit(
|
||||||
_origin: MultiLocation,
|
_origin: impl Into<MultiLocation>,
|
||||||
_message: Xcm<C>,
|
_message: Xcm<C>,
|
||||||
_weight_limit: Weight,
|
_weight_limit: Weight,
|
||||||
_weight_credit: Weight,
|
_weight_credit: Weight,
|
||||||
@@ -195,15 +200,16 @@ impl<C> ExecuteXcm<C> for () {
|
|||||||
/// /// A sender that only passes the message through and does nothing.
|
/// /// A sender that only passes the message through and does nothing.
|
||||||
/// struct Sender1;
|
/// struct Sender1;
|
||||||
/// impl SendXcm for Sender1 {
|
/// impl SendXcm for Sender1 {
|
||||||
/// fn send_xcm(destination: MultiLocation, message: Xcm<()>) -> Result {
|
/// fn send_xcm(destination: impl Into<MultiLocation>, message: Xcm<()>) -> Result {
|
||||||
/// return Err(Error::CannotReachDestination(destination, message))
|
/// return Err(Error::CannotReachDestination(destination.into(), message))
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// /// A sender that accepts a message that has an X2 junction, otherwise stops the routing.
|
/// /// A sender that accepts a message that has an X2 junction, otherwise stops the routing.
|
||||||
/// struct Sender2;
|
/// struct Sender2;
|
||||||
/// impl SendXcm for Sender2 {
|
/// impl SendXcm for Sender2 {
|
||||||
/// fn send_xcm(destination: MultiLocation, message: Xcm<()>) -> Result {
|
/// fn send_xcm(destination: impl Into<MultiLocation>, message: Xcm<()>) -> Result {
|
||||||
|
/// let destination = destination.into();
|
||||||
/// if matches!(destination.interior(), Junctions::X2(j1, j2))
|
/// if matches!(destination.interior(), Junctions::X2(j1, j2))
|
||||||
/// && destination.parent_count() == 0
|
/// && destination.parent_count() == 0
|
||||||
/// {
|
/// {
|
||||||
@@ -217,7 +223,8 @@ impl<C> ExecuteXcm<C> for () {
|
|||||||
/// /// A sender that accepts a message from an X1 parent junction, passing through otherwise.
|
/// /// A sender that accepts a message from an X1 parent junction, passing through otherwise.
|
||||||
/// struct Sender3;
|
/// struct Sender3;
|
||||||
/// impl SendXcm for Sender3 {
|
/// impl SendXcm for Sender3 {
|
||||||
/// fn send_xcm(destination: MultiLocation, message: Xcm<()>) -> Result {
|
/// fn send_xcm(destination: impl Into<MultiLocation>, message: Xcm<()>) -> Result {
|
||||||
|
/// let destination = destination.into();
|
||||||
/// if matches!(destination.interior(), Junctions::Here)
|
/// if matches!(destination.interior(), Junctions::Here)
|
||||||
/// && destination.parent_count() == 1
|
/// && destination.parent_count() == 1
|
||||||
/// {
|
/// {
|
||||||
@@ -232,17 +239,16 @@ impl<C> ExecuteXcm<C> for () {
|
|||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
/// let call: Vec<u8> = ().encode();
|
/// let call: Vec<u8> = ().encode();
|
||||||
/// let message = Xcm::Transact { origin_type: OriginKind::Superuser, require_weight_at_most: 0, call: call.into() };
|
/// let message = Xcm::Transact { origin_type: OriginKind::Superuser, require_weight_at_most: 0, call: call.into() };
|
||||||
/// let destination: MultiLocation = Parent.into();
|
|
||||||
///
|
///
|
||||||
/// assert!(
|
/// assert!(
|
||||||
/// // Sender2 will block this.
|
/// // Sender2 will block this.
|
||||||
/// <(Sender1, Sender2, Sender3) as SendXcm>::send_xcm(destination.clone(), message.clone())
|
/// <(Sender1, Sender2, Sender3) as SendXcm>::send_xcm(Parent, message.clone())
|
||||||
/// .is_err()
|
/// .is_err()
|
||||||
/// );
|
/// );
|
||||||
///
|
///
|
||||||
/// assert!(
|
/// assert!(
|
||||||
/// // Sender3 will catch this.
|
/// // Sender3 will catch this.
|
||||||
/// <(Sender1, Sender3) as SendXcm>::send_xcm(destination.clone(), message.clone())
|
/// <(Sender1, Sender3) as SendXcm>::send_xcm(Parent, message.clone())
|
||||||
/// .is_ok()
|
/// .is_ok()
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
/// # }
|
||||||
@@ -253,12 +259,12 @@ pub trait SendXcm {
|
|||||||
/// If it is not a destination which can be reached with this type but possibly could by others, then it *MUST*
|
/// If it is not a destination which can be reached with this type but possibly could by others, then it *MUST*
|
||||||
/// return `CannotReachDestination`. Any other error will cause the tuple implementation to exit early without
|
/// return `CannotReachDestination`. Any other error will cause the tuple implementation to exit early without
|
||||||
/// trying other type fields.
|
/// trying other type fields.
|
||||||
fn send_xcm(destination: MultiLocation, message: Xcm<()>) -> Result;
|
fn send_xcm(destination: impl Into<MultiLocation>, message: Xcm<()>) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||||
impl SendXcm for Tuple {
|
impl SendXcm for Tuple {
|
||||||
fn send_xcm(destination: MultiLocation, message: Xcm<()>) -> Result {
|
fn send_xcm(destination: impl Into<MultiLocation>, message: Xcm<()>) -> Result {
|
||||||
for_tuples!( #(
|
for_tuples!( #(
|
||||||
// we shadow `destination` and `message` in each expansion for the next one.
|
// we shadow `destination` and `message` in each expansion for the next one.
|
||||||
let (destination, message) = match Tuple::send_xcm(destination, message) {
|
let (destination, message) = match Tuple::send_xcm(destination, message) {
|
||||||
@@ -266,6 +272,6 @@ impl SendXcm for Tuple {
|
|||||||
o @ _ => return o,
|
o @ _ => return o,
|
||||||
};
|
};
|
||||||
)* );
|
)* );
|
||||||
Err(Error::CannotReachDestination(destination, message))
|
Err(Error::CannotReachDestination(destination.into(), message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,7 +167,12 @@ pub trait ExecuteXcm<Call> {
|
|||||||
/// Execute some XCM `message` from `origin` using no more than `weight_limit` weight. The weight limit is
|
/// Execute some XCM `message` from `origin` using no more than `weight_limit` weight. The weight limit is
|
||||||
/// a basic hard-limit and the implementation may place further restrictions or requirements on weight and
|
/// a basic hard-limit and the implementation may place further restrictions or requirements on weight and
|
||||||
/// other aspects.
|
/// other aspects.
|
||||||
fn execute_xcm(origin: MultiLocation, message: Xcm<Call>, weight_limit: Weight) -> Outcome {
|
fn execute_xcm(
|
||||||
|
origin: impl Into<MultiLocation>,
|
||||||
|
message: Xcm<Call>,
|
||||||
|
weight_limit: Weight,
|
||||||
|
) -> Outcome {
|
||||||
|
let origin = origin.into();
|
||||||
log::debug!(
|
log::debug!(
|
||||||
target: "xcm::execute_xcm",
|
target: "xcm::execute_xcm",
|
||||||
"origin: {:?}, message: {:?}, weight_limit: {:?}",
|
"origin: {:?}, message: {:?}, weight_limit: {:?}",
|
||||||
@@ -183,7 +188,7 @@ pub trait ExecuteXcm<Call> {
|
|||||||
/// Some amount of `weight_credit` may be provided which, depending on the implementation, may allow
|
/// Some amount of `weight_credit` may be provided which, depending on the implementation, may allow
|
||||||
/// execution without associated payment.
|
/// execution without associated payment.
|
||||||
fn execute_xcm_in_credit(
|
fn execute_xcm_in_credit(
|
||||||
origin: MultiLocation,
|
origin: impl Into<MultiLocation>,
|
||||||
message: Xcm<Call>,
|
message: Xcm<Call>,
|
||||||
weight_limit: Weight,
|
weight_limit: Weight,
|
||||||
weight_credit: Weight,
|
weight_credit: Weight,
|
||||||
@@ -192,7 +197,7 @@ pub trait ExecuteXcm<Call> {
|
|||||||
|
|
||||||
impl<C> ExecuteXcm<C> for () {
|
impl<C> ExecuteXcm<C> for () {
|
||||||
fn execute_xcm_in_credit(
|
fn execute_xcm_in_credit(
|
||||||
_origin: MultiLocation,
|
_origin: impl Into<MultiLocation>,
|
||||||
_message: Xcm<C>,
|
_message: Xcm<C>,
|
||||||
_weight_limit: Weight,
|
_weight_limit: Weight,
|
||||||
_weight_credit: Weight,
|
_weight_credit: Weight,
|
||||||
@@ -241,16 +246,16 @@ pub type SendResult = result::Result<(), SendError>;
|
|||||||
/// /// A sender that only passes the message through and does nothing.
|
/// /// A sender that only passes the message through and does nothing.
|
||||||
/// struct Sender1;
|
/// struct Sender1;
|
||||||
/// impl SendXcm for Sender1 {
|
/// impl SendXcm for Sender1 {
|
||||||
/// fn send_xcm(destination: MultiLocation, message: Xcm<()>) -> SendResult {
|
/// fn send_xcm(destination: impl Into<MultiLocation>, message: Xcm<()>) -> SendResult {
|
||||||
/// return Err(SendError::CannotReachDestination(destination, message))
|
/// return Err(SendError::CannotReachDestination(destination.into(), message))
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// /// A sender that accepts a message that has an X2 junction, otherwise stops the routing.
|
/// /// A sender that accepts a message that has an X2 junction, otherwise stops the routing.
|
||||||
/// struct Sender2;
|
/// struct Sender2;
|
||||||
/// impl SendXcm for Sender2 {
|
/// impl SendXcm for Sender2 {
|
||||||
/// fn send_xcm(destination: MultiLocation, message: Xcm<()>) -> SendResult {
|
/// fn send_xcm(destination: impl Into<MultiLocation>, message: Xcm<()>) -> SendResult {
|
||||||
/// if let MultiLocation { parents: 0, interior: X2(j1, j2) } = destination {
|
/// if let MultiLocation { parents: 0, interior: X2(j1, j2) } = destination.into() {
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// } else {
|
/// } else {
|
||||||
/// Err(SendError::Unroutable)
|
/// Err(SendError::Unroutable)
|
||||||
@@ -261,7 +266,8 @@ pub type SendResult = result::Result<(), SendError>;
|
|||||||
/// /// A sender that accepts a message from a parent, passing through otherwise.
|
/// /// A sender that accepts a message from a parent, passing through otherwise.
|
||||||
/// struct Sender3;
|
/// struct Sender3;
|
||||||
/// impl SendXcm for Sender3 {
|
/// impl SendXcm for Sender3 {
|
||||||
/// fn send_xcm(destination: MultiLocation, message: Xcm<()>) -> SendResult {
|
/// fn send_xcm(destination: impl Into<MultiLocation>, message: Xcm<()>) -> SendResult {
|
||||||
|
/// let destination = destination.into();
|
||||||
/// match destination {
|
/// match destination {
|
||||||
/// MultiLocation { parents: 1, interior: Here } => Ok(()),
|
/// MultiLocation { parents: 1, interior: Here } => Ok(()),
|
||||||
/// _ => Err(SendError::CannotReachDestination(destination, message)),
|
/// _ => Err(SendError::CannotReachDestination(destination, message)),
|
||||||
@@ -277,17 +283,16 @@ pub type SendResult = result::Result<(), SendError>;
|
|||||||
/// require_weight_at_most: 0,
|
/// require_weight_at_most: 0,
|
||||||
/// call: call.into(),
|
/// call: call.into(),
|
||||||
/// }]);
|
/// }]);
|
||||||
/// let destination = MultiLocation::parent();
|
|
||||||
///
|
///
|
||||||
/// assert!(
|
/// assert!(
|
||||||
/// // Sender2 will block this.
|
/// // Sender2 will block this.
|
||||||
/// <(Sender1, Sender2, Sender3) as SendXcm>::send_xcm(destination.clone(), message.clone())
|
/// <(Sender1, Sender2, Sender3) as SendXcm>::send_xcm(Parent, message.clone())
|
||||||
/// .is_err()
|
/// .is_err()
|
||||||
/// );
|
/// );
|
||||||
///
|
///
|
||||||
/// assert!(
|
/// assert!(
|
||||||
/// // Sender3 will catch this.
|
/// // Sender3 will catch this.
|
||||||
/// <(Sender1, Sender3) as SendXcm>::send_xcm(destination.clone(), message.clone())
|
/// <(Sender1, Sender3) as SendXcm>::send_xcm(Parent, message.clone())
|
||||||
/// .is_ok()
|
/// .is_ok()
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
/// # }
|
||||||
@@ -298,12 +303,12 @@ pub trait SendXcm {
|
|||||||
/// If it is not a destination which can be reached with this type but possibly could by others, then it *MUST*
|
/// If it is not a destination which can be reached with this type but possibly could by others, then it *MUST*
|
||||||
/// return `CannotReachDestination`. Any other error will cause the tuple implementation to exit early without
|
/// return `CannotReachDestination`. Any other error will cause the tuple implementation to exit early without
|
||||||
/// trying other type fields.
|
/// trying other type fields.
|
||||||
fn send_xcm(destination: MultiLocation, message: Xcm<()>) -> SendResult;
|
fn send_xcm(destination: impl Into<MultiLocation>, message: Xcm<()>) -> SendResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||||
impl SendXcm for Tuple {
|
impl SendXcm for Tuple {
|
||||||
fn send_xcm(destination: MultiLocation, message: Xcm<()>) -> SendResult {
|
fn send_xcm(destination: impl Into<MultiLocation>, message: Xcm<()>) -> SendResult {
|
||||||
for_tuples!( #(
|
for_tuples!( #(
|
||||||
// we shadow `destination` and `message` in each expansion for the next one.
|
// we shadow `destination` and `message` in each expansion for the next one.
|
||||||
let (destination, message) = match Tuple::send_xcm(destination, message) {
|
let (destination, message) = match Tuple::send_xcm(destination, message) {
|
||||||
@@ -311,7 +316,7 @@ impl SendXcm for Tuple {
|
|||||||
o @ _ => return o,
|
o @ _ => return o,
|
||||||
};
|
};
|
||||||
)* );
|
)* );
|
||||||
Err(SendError::CannotReachDestination(destination, message))
|
Err(SendError::CannotReachDestination(destination.into(), message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,8 +109,8 @@ pub fn sent_xcm() -> Vec<(MultiLocation, opaque::Xcm)> {
|
|||||||
}
|
}
|
||||||
pub struct TestSendXcm;
|
pub struct TestSendXcm;
|
||||||
impl SendXcm for TestSendXcm {
|
impl SendXcm for TestSendXcm {
|
||||||
fn send_xcm(dest: MultiLocation, msg: opaque::Xcm) -> SendResult {
|
fn send_xcm(dest: impl Into<MultiLocation>, msg: opaque::Xcm) -> SendResult {
|
||||||
SENT_XCM.with(|q| q.borrow_mut().push((dest, msg)));
|
SENT_XCM.with(|q| q.borrow_mut().push((dest.into(), msg)));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,11 +164,11 @@ pub fn to_account(l: MultiLocation) -> Result<u64, MultiLocation> {
|
|||||||
pub struct TestOriginConverter;
|
pub struct TestOriginConverter;
|
||||||
impl ConvertOrigin<TestOrigin> for TestOriginConverter {
|
impl ConvertOrigin<TestOrigin> for TestOriginConverter {
|
||||||
fn convert_origin(
|
fn convert_origin(
|
||||||
origin: MultiLocation,
|
origin: impl Into<MultiLocation>,
|
||||||
kind: OriginKind,
|
kind: OriginKind,
|
||||||
) -> Result<TestOrigin, MultiLocation> {
|
) -> Result<TestOrigin, MultiLocation> {
|
||||||
use OriginKind::*;
|
use OriginKind::*;
|
||||||
match (kind, origin) {
|
match (kind, origin.into()) {
|
||||||
(Superuser, _) => Ok(TestOrigin::Root),
|
(Superuser, _) => Ok(TestOrigin::Root),
|
||||||
(SovereignAccount, l) => Ok(TestOrigin::Signed(to_account(l)?)),
|
(SovereignAccount, l) => Ok(TestOrigin::Signed(to_account(l)?)),
|
||||||
(Native, MultiLocation { parents: 0, interior: X1(Parachain(id)) }) =>
|
(Native, MultiLocation { parents: 0, interior: X1(Parachain(id)) }) =>
|
||||||
|
|||||||
@@ -32,7 +32,11 @@ impl<LocationConverter: Convert<MultiLocation, Origin::AccountId>, Origin: Origi
|
|||||||
where
|
where
|
||||||
Origin::AccountId: Clone,
|
Origin::AccountId: Clone,
|
||||||
{
|
{
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
fn convert_origin(
|
||||||
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<Origin, MultiLocation> {
|
||||||
|
let origin = origin.into();
|
||||||
if let OriginKind::SovereignAccount = kind {
|
if let OriginKind::SovereignAccount = kind {
|
||||||
let location = LocationConverter::convert(origin)?;
|
let location = LocationConverter::convert(origin)?;
|
||||||
Ok(Origin::signed(location).into())
|
Ok(Origin::signed(location).into())
|
||||||
@@ -44,7 +48,11 @@ where
|
|||||||
|
|
||||||
pub struct ParentAsSuperuser<Origin>(PhantomData<Origin>);
|
pub struct ParentAsSuperuser<Origin>(PhantomData<Origin>);
|
||||||
impl<Origin: OriginTrait> ConvertOrigin<Origin> for ParentAsSuperuser<Origin> {
|
impl<Origin: OriginTrait> ConvertOrigin<Origin> for ParentAsSuperuser<Origin> {
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
fn convert_origin(
|
||||||
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<Origin, MultiLocation> {
|
||||||
|
let origin = origin.into();
|
||||||
if kind == OriginKind::Superuser && origin.contains_parents_only(1) {
|
if kind == OriginKind::Superuser && origin.contains_parents_only(1) {
|
||||||
Ok(Origin::root())
|
Ok(Origin::root())
|
||||||
} else {
|
} else {
|
||||||
@@ -57,8 +65,11 @@ pub struct ChildSystemParachainAsSuperuser<ParaId, Origin>(PhantomData<(ParaId,
|
|||||||
impl<ParaId: IsSystem + From<u32>, Origin: OriginTrait> ConvertOrigin<Origin>
|
impl<ParaId: IsSystem + From<u32>, Origin: OriginTrait> ConvertOrigin<Origin>
|
||||||
for ChildSystemParachainAsSuperuser<ParaId, Origin>
|
for ChildSystemParachainAsSuperuser<ParaId, Origin>
|
||||||
{
|
{
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
fn convert_origin(
|
||||||
match (kind, origin) {
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<Origin, MultiLocation> {
|
||||||
|
match (kind, origin.into()) {
|
||||||
(
|
(
|
||||||
OriginKind::Superuser,
|
OriginKind::Superuser,
|
||||||
MultiLocation { parents: 0, interior: X1(Junction::Parachain(id)) },
|
MultiLocation { parents: 0, interior: X1(Junction::Parachain(id)) },
|
||||||
@@ -72,8 +83,11 @@ pub struct SiblingSystemParachainAsSuperuser<ParaId, Origin>(PhantomData<(ParaId
|
|||||||
impl<ParaId: IsSystem + From<u32>, Origin: OriginTrait> ConvertOrigin<Origin>
|
impl<ParaId: IsSystem + From<u32>, Origin: OriginTrait> ConvertOrigin<Origin>
|
||||||
for SiblingSystemParachainAsSuperuser<ParaId, Origin>
|
for SiblingSystemParachainAsSuperuser<ParaId, Origin>
|
||||||
{
|
{
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
fn convert_origin(
|
||||||
match (kind, origin) {
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<Origin, MultiLocation> {
|
||||||
|
match (kind, origin.into()) {
|
||||||
(
|
(
|
||||||
OriginKind::Superuser,
|
OriginKind::Superuser,
|
||||||
MultiLocation { parents: 1, interior: X1(Junction::Parachain(id)) },
|
MultiLocation { parents: 1, interior: X1(Junction::Parachain(id)) },
|
||||||
@@ -87,8 +101,11 @@ pub struct ChildParachainAsNative<ParachainOrigin, Origin>(PhantomData<(Parachai
|
|||||||
impl<ParachainOrigin: From<u32>, Origin: From<ParachainOrigin>> ConvertOrigin<Origin>
|
impl<ParachainOrigin: From<u32>, Origin: From<ParachainOrigin>> ConvertOrigin<Origin>
|
||||||
for ChildParachainAsNative<ParachainOrigin, Origin>
|
for ChildParachainAsNative<ParachainOrigin, Origin>
|
||||||
{
|
{
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
fn convert_origin(
|
||||||
match (kind, origin) {
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<Origin, MultiLocation> {
|
||||||
|
match (kind, origin.into()) {
|
||||||
(
|
(
|
||||||
OriginKind::Native,
|
OriginKind::Native,
|
||||||
MultiLocation { parents: 0, interior: X1(Junction::Parachain(id)) },
|
MultiLocation { parents: 0, interior: X1(Junction::Parachain(id)) },
|
||||||
@@ -104,8 +121,11 @@ pub struct SiblingParachainAsNative<ParachainOrigin, Origin>(
|
|||||||
impl<ParachainOrigin: From<u32>, Origin: From<ParachainOrigin>> ConvertOrigin<Origin>
|
impl<ParachainOrigin: From<u32>, Origin: From<ParachainOrigin>> ConvertOrigin<Origin>
|
||||||
for SiblingParachainAsNative<ParachainOrigin, Origin>
|
for SiblingParachainAsNative<ParachainOrigin, Origin>
|
||||||
{
|
{
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
fn convert_origin(
|
||||||
match (kind, origin) {
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<Origin, MultiLocation> {
|
||||||
|
match (kind, origin.into()) {
|
||||||
(
|
(
|
||||||
OriginKind::Native,
|
OriginKind::Native,
|
||||||
MultiLocation { parents: 1, interior: X1(Junction::Parachain(id)) },
|
MultiLocation { parents: 1, interior: X1(Junction::Parachain(id)) },
|
||||||
@@ -120,7 +140,11 @@ pub struct RelayChainAsNative<RelayOrigin, Origin>(PhantomData<(RelayOrigin, Ori
|
|||||||
impl<RelayOrigin: Get<Origin>, Origin> ConvertOrigin<Origin>
|
impl<RelayOrigin: Get<Origin>, Origin> ConvertOrigin<Origin>
|
||||||
for RelayChainAsNative<RelayOrigin, Origin>
|
for RelayChainAsNative<RelayOrigin, Origin>
|
||||||
{
|
{
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
fn convert_origin(
|
||||||
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<Origin, MultiLocation> {
|
||||||
|
let origin = origin.into();
|
||||||
if kind == OriginKind::Native && origin.contains_parents_only(1) {
|
if kind == OriginKind::Native && origin.contains_parents_only(1) {
|
||||||
Ok(RelayOrigin::get())
|
Ok(RelayOrigin::get())
|
||||||
} else {
|
} else {
|
||||||
@@ -135,8 +159,11 @@ impl<Network: Get<NetworkId>, Origin: OriginTrait> ConvertOrigin<Origin>
|
|||||||
where
|
where
|
||||||
Origin::AccountId: From<[u8; 32]>,
|
Origin::AccountId: From<[u8; 32]>,
|
||||||
{
|
{
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
fn convert_origin(
|
||||||
match (kind, origin) {
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<Origin, MultiLocation> {
|
||||||
|
match (kind, origin.into()) {
|
||||||
(
|
(
|
||||||
OriginKind::Native,
|
OriginKind::Native,
|
||||||
MultiLocation { parents: 0, interior: X1(Junction::AccountId32 { id, network }) },
|
MultiLocation { parents: 0, interior: X1(Junction::AccountId32 { id, network }) },
|
||||||
@@ -153,8 +180,11 @@ impl<Network: Get<NetworkId>, Origin: OriginTrait> ConvertOrigin<Origin>
|
|||||||
where
|
where
|
||||||
Origin::AccountId: From<[u8; 20]>,
|
Origin::AccountId: From<[u8; 20]>,
|
||||||
{
|
{
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
fn convert_origin(
|
||||||
match (kind, origin) {
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<Origin, MultiLocation> {
|
||||||
|
match (kind, origin.into()) {
|
||||||
(
|
(
|
||||||
OriginKind::Native,
|
OriginKind::Native,
|
||||||
MultiLocation { parents: 0, interior: X1(Junction::AccountKey20 { key, network }) },
|
MultiLocation { parents: 0, interior: X1(Junction::AccountKey20 { key, network }) },
|
||||||
|
|||||||
@@ -150,7 +150,6 @@ fn paying_reserve_deposit_should_work() {
|
|||||||
add_reserve(Parent.into(), (Parent, WildFungible).into());
|
add_reserve(Parent.into(), (Parent, WildFungible).into());
|
||||||
WeightPrice::set((Parent.into(), 1_000_000_000_000));
|
WeightPrice::set((Parent.into(), 1_000_000_000_000));
|
||||||
|
|
||||||
let origin = Parent.into();
|
|
||||||
let fees = (Parent, 30).into();
|
let fees = (Parent, 30).into();
|
||||||
let message = Xcm(vec![
|
let message = Xcm(vec![
|
||||||
ReserveAssetDeposited((Parent, 100).into()),
|
ReserveAssetDeposited((Parent, 100).into()),
|
||||||
@@ -158,7 +157,7 @@ fn paying_reserve_deposit_should_work() {
|
|||||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() },
|
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() },
|
||||||
]);
|
]);
|
||||||
let weight_limit = 50;
|
let weight_limit = 50;
|
||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||||
assert_eq!(r, Outcome::Complete(30));
|
assert_eq!(r, Outcome::Complete(30));
|
||||||
assert_eq!(assets(3000), vec![(Parent, 70).into()]);
|
assert_eq!(assets(3000), vec![(Parent, 70).into()]);
|
||||||
}
|
}
|
||||||
@@ -171,7 +170,7 @@ fn transfer_should_work() {
|
|||||||
add_asset(1001, (Here, 1000));
|
add_asset(1001, (Here, 1000));
|
||||||
// They want to transfer 100 of them to their sibling parachain #2
|
// They want to transfer 100 of them to their sibling parachain #2
|
||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(
|
let r = XcmExecutor::<TestConfig>::execute_xcm(
|
||||||
Parachain(1).into(),
|
Parachain(1),
|
||||||
Xcm(vec![TransferAsset {
|
Xcm(vec![TransferAsset {
|
||||||
assets: (Here, 100).into(),
|
assets: (Here, 100).into(),
|
||||||
beneficiary: X1(AccountIndex64 { index: 3, network: Any }).into(),
|
beneficiary: X1(AccountIndex64 { index: 3, network: Any }).into(),
|
||||||
@@ -434,7 +433,7 @@ fn reserve_transfer_should_work() {
|
|||||||
// They want to transfer 100 of our native asset from sovereign account of parachain #1 into #2
|
// 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.
|
// and let them know to hand it to account #3.
|
||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(
|
let r = XcmExecutor::<TestConfig>::execute_xcm(
|
||||||
Parachain(1).into(),
|
Parachain(1),
|
||||||
Xcm(vec![TransferReserveAsset {
|
Xcm(vec![TransferReserveAsset {
|
||||||
assets: (Here, 100).into(),
|
assets: (Here, 100).into(),
|
||||||
dest: Parachain(2).into(),
|
dest: Parachain(2).into(),
|
||||||
@@ -482,8 +481,7 @@ fn simple_version_subscriptions_should_work() {
|
|||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message.clone(), weight_limit);
|
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message.clone(), weight_limit);
|
||||||
assert_eq!(r, Outcome::Error(XcmError::Barrier));
|
assert_eq!(r, Outcome::Error(XcmError::Barrier));
|
||||||
|
|
||||||
let origin = Parent.into();
|
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
|
||||||
assert_eq!(r, Outcome::Complete(10));
|
assert_eq!(r, Outcome::Complete(10));
|
||||||
|
|
||||||
assert_eq!(SubscriptionRequests::get(), vec![(Parent.into(), Some((42, 5000)))]);
|
assert_eq!(SubscriptionRequests::get(), vec![(Parent.into(), Some((42, 5000)))]);
|
||||||
@@ -536,8 +534,7 @@ fn simple_version_unsubscriptions_should_work() {
|
|||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message.clone(), weight_limit);
|
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message.clone(), weight_limit);
|
||||||
assert_eq!(r, Outcome::Error(XcmError::Barrier));
|
assert_eq!(r, Outcome::Error(XcmError::Barrier));
|
||||||
|
|
||||||
let origin = Parent.into();
|
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
|
||||||
assert_eq!(r, Outcome::Complete(10));
|
assert_eq!(r, Outcome::Complete(10));
|
||||||
|
|
||||||
assert_eq!(SubscriptionRequests::get(), vec![(Parent.into(), None)]);
|
assert_eq!(SubscriptionRequests::get(), vec![(Parent.into(), None)]);
|
||||||
@@ -580,14 +577,13 @@ fn version_unsubscription_instruction_should_work() {
|
|||||||
fn transacting_should_work() {
|
fn transacting_should_work() {
|
||||||
AllowUnpaidFrom::set(vec![Parent.into()]);
|
AllowUnpaidFrom::set(vec![Parent.into()]);
|
||||||
|
|
||||||
let origin = Parent.into();
|
|
||||||
let message = Xcm::<TestCall>(vec![Transact {
|
let message = Xcm::<TestCall>(vec![Transact {
|
||||||
origin_type: OriginKind::Native,
|
origin_type: OriginKind::Native,
|
||||||
require_weight_at_most: 50,
|
require_weight_at_most: 50,
|
||||||
call: TestCall::Any(50, None).encode().into(),
|
call: TestCall::Any(50, None).encode().into(),
|
||||||
}]);
|
}]);
|
||||||
let weight_limit = 60;
|
let weight_limit = 60;
|
||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||||
assert_eq!(r, Outcome::Complete(60));
|
assert_eq!(r, Outcome::Complete(60));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -595,14 +591,13 @@ fn transacting_should_work() {
|
|||||||
fn transacting_should_respect_max_weight_requirement() {
|
fn transacting_should_respect_max_weight_requirement() {
|
||||||
AllowUnpaidFrom::set(vec![Parent.into()]);
|
AllowUnpaidFrom::set(vec![Parent.into()]);
|
||||||
|
|
||||||
let origin = Parent.into();
|
|
||||||
let message = Xcm::<TestCall>(vec![Transact {
|
let message = Xcm::<TestCall>(vec![Transact {
|
||||||
origin_type: OriginKind::Native,
|
origin_type: OriginKind::Native,
|
||||||
require_weight_at_most: 40,
|
require_weight_at_most: 40,
|
||||||
call: TestCall::Any(50, None).encode().into(),
|
call: TestCall::Any(50, None).encode().into(),
|
||||||
}]);
|
}]);
|
||||||
let weight_limit = 60;
|
let weight_limit = 60;
|
||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||||
assert_eq!(r, Outcome::Incomplete(50, XcmError::TooMuchWeightRequired));
|
assert_eq!(r, Outcome::Incomplete(50, XcmError::TooMuchWeightRequired));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,14 +605,13 @@ fn transacting_should_respect_max_weight_requirement() {
|
|||||||
fn transacting_should_refund_weight() {
|
fn transacting_should_refund_weight() {
|
||||||
AllowUnpaidFrom::set(vec![Parent.into()]);
|
AllowUnpaidFrom::set(vec![Parent.into()]);
|
||||||
|
|
||||||
let origin = Parent.into();
|
|
||||||
let message = Xcm::<TestCall>(vec![Transact {
|
let message = Xcm::<TestCall>(vec![Transact {
|
||||||
origin_type: OriginKind::Native,
|
origin_type: OriginKind::Native,
|
||||||
require_weight_at_most: 50,
|
require_weight_at_most: 50,
|
||||||
call: TestCall::Any(50, Some(30)).encode().into(),
|
call: TestCall::Any(50, Some(30)).encode().into(),
|
||||||
}]);
|
}]);
|
||||||
let weight_limit = 60;
|
let weight_limit = 60;
|
||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||||
assert_eq!(r, Outcome::Complete(40));
|
assert_eq!(r, Outcome::Complete(40));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -651,9 +645,8 @@ fn paid_transacting_should_refund_payment_for_unused_weight() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn prepaid_result_of_query_should_get_free_execution() {
|
fn prepaid_result_of_query_should_get_free_execution() {
|
||||||
let query_id = 33;
|
let query_id = 33;
|
||||||
let origin: MultiLocation = Parent.into();
|
|
||||||
// We put this in manually here, but normally this would be done at the point of crafting the message.
|
// We put this in manually here, but normally this would be done at the point of crafting the message.
|
||||||
expect_response(query_id, origin.clone());
|
expect_response(query_id, Parent.into());
|
||||||
|
|
||||||
let the_response = Response::Assets((Parent, 100).into());
|
let the_response = Response::Assets((Parent, 100).into());
|
||||||
let message = Xcm::<TestCall>(vec![QueryResponse {
|
let message = Xcm::<TestCall>(vec![QueryResponse {
|
||||||
@@ -664,12 +657,12 @@ fn prepaid_result_of_query_should_get_free_execution() {
|
|||||||
let weight_limit = 10;
|
let weight_limit = 10;
|
||||||
|
|
||||||
// First time the response gets through since we're expecting it...
|
// First time the response gets through since we're expecting it...
|
||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin.clone(), message.clone(), weight_limit);
|
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message.clone(), weight_limit);
|
||||||
assert_eq!(r, Outcome::Complete(10));
|
assert_eq!(r, Outcome::Complete(10));
|
||||||
assert_eq!(response(query_id).unwrap(), the_response);
|
assert_eq!(response(query_id).unwrap(), the_response);
|
||||||
|
|
||||||
// Second time it doesn't, since we're not.
|
// Second time it doesn't, since we're not.
|
||||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin.clone(), message.clone(), weight_limit);
|
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message.clone(), weight_limit);
|
||||||
assert_eq!(r, Outcome::Error(XcmError::Barrier));
|
assert_eq!(r, Outcome::Error(XcmError::Barrier));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ pub fn sent_xcm() -> Vec<(MultiLocation, opaque::Xcm)> {
|
|||||||
}
|
}
|
||||||
pub struct TestSendXcm;
|
pub struct TestSendXcm;
|
||||||
impl SendXcm for TestSendXcm {
|
impl SendXcm for TestSendXcm {
|
||||||
fn send_xcm(dest: MultiLocation, msg: opaque::Xcm) -> SendResult {
|
fn send_xcm(dest: impl Into<MultiLocation>, msg: opaque::Xcm) -> SendResult {
|
||||||
SENT_XCM.with(|q| q.borrow_mut().push((dest, msg)));
|
SENT_XCM.with(|q| q.borrow_mut().push((dest.into(), msg)));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,11 +67,12 @@ pub const MAX_RECURSION_LIMIT: u32 = 8;
|
|||||||
|
|
||||||
impl<Config: config::Config> ExecuteXcm<Config::Call> for XcmExecutor<Config> {
|
impl<Config: config::Config> ExecuteXcm<Config::Call> for XcmExecutor<Config> {
|
||||||
fn execute_xcm_in_credit(
|
fn execute_xcm_in_credit(
|
||||||
origin: MultiLocation,
|
origin: impl Into<MultiLocation>,
|
||||||
mut message: Xcm<Config::Call>,
|
mut message: Xcm<Config::Call>,
|
||||||
weight_limit: Weight,
|
weight_limit: Weight,
|
||||||
mut weight_credit: Weight,
|
mut weight_credit: Weight,
|
||||||
) -> Outcome {
|
) -> Outcome {
|
||||||
|
let origin = origin.into();
|
||||||
log::trace!(
|
log::trace!(
|
||||||
target: "xcm::execute_xcm_in_credit",
|
target: "xcm::execute_xcm_in_credit",
|
||||||
"origin: {:?}, message: {:?}, weight_limit: {:?}, weight_credit: {:?}",
|
"origin: {:?}, message: {:?}, weight_limit: {:?}, weight_credit: {:?}",
|
||||||
@@ -149,7 +150,8 @@ impl From<ExecutorError> for frame_benchmarking::BenchmarkError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Config: config::Config> XcmExecutor<Config> {
|
impl<Config: config::Config> XcmExecutor<Config> {
|
||||||
pub fn new(origin: MultiLocation) -> Self {
|
pub fn new(origin: impl Into<MultiLocation>) -> Self {
|
||||||
|
let origin = origin.into();
|
||||||
Self {
|
Self {
|
||||||
holding: Assets::new(),
|
holding: Assets::new(),
|
||||||
origin: Some(origin.clone()),
|
origin: Some(origin.clone()),
|
||||||
|
|||||||
@@ -144,9 +144,9 @@ impl<T: Clone + Encode + Decode> Convert<Vec<u8>, T> for Decoded {
|
|||||||
/// // A convertor that will bump the para id and pass it to the next one.
|
/// // A convertor that will bump the para id and pass it to the next one.
|
||||||
/// struct BumpParaId;
|
/// struct BumpParaId;
|
||||||
/// impl ConvertOrigin<u32> for BumpParaId {
|
/// impl ConvertOrigin<u32> for BumpParaId {
|
||||||
/// fn convert_origin(origin: MultiLocation, _: OriginKind) -> Result<u32, MultiLocation> {
|
/// fn convert_origin(origin: impl Into<MultiLocation>, _: OriginKind) -> Result<u32, MultiLocation> {
|
||||||
/// match origin.interior() {
|
/// match origin.into() {
|
||||||
/// Junctions::X1(Junction::Parachain(id)) if origin.parent_count() == 0 => {
|
/// MultiLocation { parents: 0, interior: Junctions::X1(Junction::Parachain(id)) } => {
|
||||||
/// Err(Junctions::X1(Junction::Parachain(id + 1)).into())
|
/// Err(Junctions::X1(Junction::Parachain(id + 1)).into())
|
||||||
/// }
|
/// }
|
||||||
/// _ => unreachable!()
|
/// _ => unreachable!()
|
||||||
@@ -156,12 +156,12 @@ impl<T: Clone + Encode + Decode> Convert<Vec<u8>, T> for Decoded {
|
|||||||
///
|
///
|
||||||
/// struct AcceptPara7;
|
/// struct AcceptPara7;
|
||||||
/// impl ConvertOrigin<u32> for AcceptPara7 {
|
/// impl ConvertOrigin<u32> for AcceptPara7 {
|
||||||
/// fn convert_origin(origin: MultiLocation, _: OriginKind) -> Result<u32, MultiLocation> {
|
/// fn convert_origin(origin: impl Into<MultiLocation>, _: OriginKind) -> Result<u32, MultiLocation> {
|
||||||
/// match origin.interior() {
|
/// match origin.into() {
|
||||||
/// Junctions::X1(Junction::Parachain(id)) if id == &7 && origin.parent_count() == 0 => {
|
/// MultiLocation { parents: 0, interior: Junctions::X1(Junction::Parachain(id)) } if id == 7 => {
|
||||||
/// Ok(7)
|
/// Ok(7)
|
||||||
/// }
|
/// }
|
||||||
/// _ => Err(origin)
|
/// o => Err(o)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
@@ -175,18 +175,25 @@ impl<T: Clone + Encode + Decode> Convert<Vec<u8>, T> for Decoded {
|
|||||||
/// ```
|
/// ```
|
||||||
pub trait ConvertOrigin<Origin> {
|
pub trait ConvertOrigin<Origin> {
|
||||||
/// Attempt to convert `origin` to the generic `Origin` whilst consuming it.
|
/// Attempt to convert `origin` to the generic `Origin` whilst consuming it.
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation>;
|
fn convert_origin(
|
||||||
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<Origin, MultiLocation>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||||
impl<O> ConvertOrigin<O> for Tuple {
|
impl<O> ConvertOrigin<O> for Tuple {
|
||||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<O, MultiLocation> {
|
fn convert_origin(
|
||||||
|
origin: impl Into<MultiLocation>,
|
||||||
|
kind: OriginKind,
|
||||||
|
) -> Result<O, MultiLocation> {
|
||||||
for_tuples!( #(
|
for_tuples!( #(
|
||||||
let origin = match Tuple::convert_origin(origin, kind) {
|
let origin = match Tuple::convert_origin(origin, kind) {
|
||||||
Err(o) => o,
|
Err(o) => o,
|
||||||
r => return r
|
r => return r
|
||||||
};
|
};
|
||||||
)* );
|
)* );
|
||||||
|
let origin = origin.into();
|
||||||
log::trace!(
|
log::trace!(
|
||||||
target: "xcm::convert_origin",
|
target: "xcm::convert_origin",
|
||||||
"could not convert: origin: {:?}, kind: {:?}",
|
"could not convert: origin: {:?}, kind: {:?}",
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ pub trait WeightBounds<Call> {
|
|||||||
/// message.
|
/// message.
|
||||||
pub trait UniversalWeigher {
|
pub trait UniversalWeigher {
|
||||||
/// Get the upper limit of weight required for `dest` to execute `message`.
|
/// Get the upper limit of weight required for `dest` to execute `message`.
|
||||||
fn weigh(dest: MultiLocation, message: Xcm<()>) -> Result<Weight, ()>;
|
fn weigh(dest: impl Into<MultiLocation>, message: Xcm<()>) -> Result<Weight, ()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Charge for weight in order to execute XCM.
|
/// Charge for weight in order to execute XCM.
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ mod tests {
|
|||||||
Relay::execute_with(|| {
|
Relay::execute_with(|| {
|
||||||
assert_ok!(RelayChainPalletXcm::send_xcm(
|
assert_ok!(RelayChainPalletXcm::send_xcm(
|
||||||
Here,
|
Here,
|
||||||
Parachain(1).into(),
|
Parachain(1),
|
||||||
Xcm(vec![Transact {
|
Xcm(vec![Transact {
|
||||||
origin_type: OriginKind::SovereignAccount,
|
origin_type: OriginKind::SovereignAccount,
|
||||||
require_weight_at_most: INITIAL_BALANCE as u64,
|
require_weight_at_most: INITIAL_BALANCE as u64,
|
||||||
@@ -152,7 +152,7 @@ mod tests {
|
|||||||
ParaA::execute_with(|| {
|
ParaA::execute_with(|| {
|
||||||
assert_ok!(ParachainPalletXcm::send_xcm(
|
assert_ok!(ParachainPalletXcm::send_xcm(
|
||||||
Here,
|
Here,
|
||||||
Parent.into(),
|
Parent,
|
||||||
Xcm(vec![Transact {
|
Xcm(vec![Transact {
|
||||||
origin_type: OriginKind::SovereignAccount,
|
origin_type: OriginKind::SovereignAccount,
|
||||||
require_weight_at_most: INITIAL_BALANCE as u64,
|
require_weight_at_most: INITIAL_BALANCE as u64,
|
||||||
@@ -180,7 +180,7 @@ mod tests {
|
|||||||
ParaA::execute_with(|| {
|
ParaA::execute_with(|| {
|
||||||
assert_ok!(ParachainPalletXcm::send_xcm(
|
assert_ok!(ParachainPalletXcm::send_xcm(
|
||||||
Here,
|
Here,
|
||||||
MultiLocation::new(1, X1(Parachain(2))),
|
(Parent, Parachain(2)),
|
||||||
Xcm(vec![Transact {
|
Xcm(vec![Transact {
|
||||||
origin_type: OriginKind::SovereignAccount,
|
origin_type: OriginKind::SovereignAccount,
|
||||||
require_weight_at_most: INITIAL_BALANCE as u64,
|
require_weight_at_most: INITIAL_BALANCE as u64,
|
||||||
@@ -247,7 +247,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
// Send withdraw and deposit
|
// Send withdraw and deposit
|
||||||
assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent.into(), message.clone()));
|
assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone()));
|
||||||
});
|
});
|
||||||
|
|
||||||
Relay::execute_with(|| {
|
Relay::execute_with(|| {
|
||||||
@@ -289,7 +289,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
// Send withdraw and deposit with query holding
|
// Send withdraw and deposit with query holding
|
||||||
assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent.into(), message.clone(),));
|
assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone(),));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check that transfer was executed
|
// Check that transfer was executed
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ pub mod mock_msg_queue {
|
|||||||
let hash = Encode::using_encoded(&xcm, T::Hashing::hash);
|
let hash = Encode::using_encoded(&xcm, T::Hashing::hash);
|
||||||
let (result, event) = match Xcm::<T::Call>::try_from(xcm) {
|
let (result, event) = match Xcm::<T::Call>::try_from(xcm) {
|
||||||
Ok(xcm) => {
|
Ok(xcm) => {
|
||||||
let location = MultiLocation::new(1, X1(Parachain(sender.into())));
|
let location = (1, Parachain(sender.into()));
|
||||||
match T::XcmExecutor::execute_xcm(location, xcm, max_weight) {
|
match T::XcmExecutor::execute_xcm(location, xcm, max_weight) {
|
||||||
Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)),
|
Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)),
|
||||||
Outcome::Complete(w) => (Ok(w), Event::Success(Some(hash))),
|
Outcome::Complete(w) => (Ok(w), Event::Success(Some(hash))),
|
||||||
@@ -275,7 +275,7 @@ pub mod mock_msg_queue {
|
|||||||
Self::deposit_event(Event::UnsupportedVersion(id));
|
Self::deposit_event(Event::UnsupportedVersion(id));
|
||||||
},
|
},
|
||||||
Ok(Ok(x)) => {
|
Ok(Ok(x)) => {
|
||||||
let outcome = T::XcmExecutor::execute_xcm(Parent.into(), x.clone(), limit);
|
let outcome = T::XcmExecutor::execute_xcm(Parent, x.clone(), limit);
|
||||||
<ReceivedDmp<T>>::append(x);
|
<ReceivedDmp<T>>::append(x);
|
||||||
Self::deposit_event(Event::ExecutedDownward(id, outcome));
|
Self::deposit_event(Event::ExecutedDownward(id, outcome));
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -296,9 +296,10 @@ macro_rules! decl_test_network {
|
|||||||
pub struct ParachainXcmRouter<T>($crate::PhantomData<T>);
|
pub struct ParachainXcmRouter<T>($crate::PhantomData<T>);
|
||||||
|
|
||||||
impl<T: $crate::Get<$crate::ParaId>> $crate::SendXcm for ParachainXcmRouter<T> {
|
impl<T: $crate::Get<$crate::ParaId>> $crate::SendXcm for ParachainXcmRouter<T> {
|
||||||
fn send_xcm(destination: $crate::MultiLocation, message: $crate::Xcm<()>) -> $crate::SendResult {
|
fn send_xcm(destination: impl Into<$crate::MultiLocation>, message: $crate::Xcm<()>) -> $crate::SendResult {
|
||||||
use $crate::{UmpSink, XcmpMessageHandlerT};
|
use $crate::{UmpSink, XcmpMessageHandlerT};
|
||||||
|
|
||||||
|
let destination = destination.into();
|
||||||
match destination.interior() {
|
match destination.interior() {
|
||||||
$crate::Junctions::Here if destination.parent_count() == 1 => {
|
$crate::Junctions::Here if destination.parent_count() == 1 => {
|
||||||
$crate::PARA_MESSAGE_BUS.with(
|
$crate::PARA_MESSAGE_BUS.with(
|
||||||
@@ -320,9 +321,10 @@ macro_rules! decl_test_network {
|
|||||||
/// XCM router for relay chain.
|
/// XCM router for relay chain.
|
||||||
pub struct RelayChainXcmRouter;
|
pub struct RelayChainXcmRouter;
|
||||||
impl $crate::SendXcm for RelayChainXcmRouter {
|
impl $crate::SendXcm for RelayChainXcmRouter {
|
||||||
fn send_xcm(destination: $crate::MultiLocation, message: $crate::Xcm<()>) -> $crate::SendResult {
|
fn send_xcm(destination: impl Into<$crate::MultiLocation>, message: $crate::Xcm<()>) -> $crate::SendResult {
|
||||||
use $crate::DmpMessageHandlerT;
|
use $crate::DmpMessageHandlerT;
|
||||||
|
|
||||||
|
let destination = destination.into();
|
||||||
match destination.interior() {
|
match destination.interior() {
|
||||||
$(
|
$(
|
||||||
$crate::X1($crate::Parachain(id)) if *id == $para_id && destination.parent_count() == 0 => {
|
$crate::X1($crate::Parachain(id)) if *id == $para_id && destination.parent_count() == 0 => {
|
||||||
|
|||||||
Reference in New Issue
Block a user