Skip to content

send_as_sovereign as versioned xcm #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ macro_rules! benchmark_backend {
// Every variant must implement [`BenchmarkingSetup`].
//
// ```nocompile
//
// struct Transfer;
// impl BenchmarkingSetup for Transfer { ... }
//
Expand Down
22 changes: 15 additions & 7 deletions xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

use frame_support::{pallet_prelude::*, traits::EnsureOrigin};
use frame_system::pallet_prelude::*;
use sp_std::boxed::Box;

use xcm::latest::prelude::*;
use sp_std::{
boxed::Box,
convert::{TryFrom, TryInto},
};
use xcm::{latest::prelude::*, VersionedMultiLocation, VersionedXcm};

pub use module::*;

Expand Down Expand Up @@ -43,6 +45,9 @@ pub mod module {
/// The message and destination was recognized as being reachable but
/// the operation could not be completed.
SendFailure,
/// The version of the `Versioned` value used is not able to be
/// interpreted.
BadVersion,
}

#[pallet::call]
Expand All @@ -51,15 +56,18 @@ pub mod module {
#[pallet::weight(100_000_000)]
pub fn send_as_sovereign(
origin: OriginFor<T>,
dest: Box<MultiLocation>,
message: Box<Xcm<()>>,
dest: Box<VersionedMultiLocation>,
message: Box<VersionedXcm<()>>,
) -> DispatchResult {
let _ = T::SovereignOrigin::ensure_origin(origin)?;
pallet_xcm::Pallet::<T>::send_xcm(Here, *dest.clone(), *message.clone()).map_err(|e| match e {
let dest = MultiLocation::try_from(*dest).map_err(|()| Error::<T>::BadVersion)?;
let message: Xcm<()> = (*message).try_into().map_err(|()| Error::<T>::BadVersion)?;

pallet_xcm::Pallet::<T>::send_xcm(Here, dest.clone(), message.clone()).map_err(|e| match e {
SendError::CannotReachDestination(..) => Error::<T>::Unreachable,
_ => Error::<T>::SendFailure,
})?;
Self::deposit_event(Event::Sent(*dest, *message));
Self::deposit_event(Event::Sent(dest, message));
Ok(())
}
}
Expand Down
12 changes: 6 additions & 6 deletions xtokens/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ fn send_as_sovereign() {
let assets: MultiAsset = (Here, 1_000_000_000_000).into();
assert_ok!(para::OrmlXcm::send_as_sovereign(
para::Origin::root(),
Box::new(MultiLocation::parent()),
Box::new(Xcm(vec![
Box::new(Parent.into()),
Box::new(VersionedXcm::from(Xcm(vec![
WithdrawAsset(assets.clone().into()),
BuyExecution {
fees: assets,
Expand All @@ -381,7 +381,7 @@ fn send_as_sovereign() {
require_weight_at_most: 1_000_000_000,
call: call.encode().into(),
}
]))
])))
));
});

Expand Down Expand Up @@ -412,8 +412,8 @@ fn send_as_sovereign_fails_if_bad_origin() {
assert_err!(
para::OrmlXcm::send_as_sovereign(
para::Origin::signed(ALICE),
Box::new(MultiLocation::parent()),
Box::new(Xcm(vec![
Box::new(Parent.into()),
Box::new(VersionedXcm::from(Xcm(vec![
WithdrawAsset(assets.clone().into()),
BuyExecution {
fees: assets,
Expand All @@ -424,7 +424,7 @@ fn send_as_sovereign_fails_if_bad_origin() {
require_weight_at_most: 1_000_000_000,
call: call.encode().into(),
}
]))
])))
),
DispatchError::BadOrigin,
);
Expand Down