Make RelayedFrom typesafe (#3617)

* Corrent type

* Fix build

* Fixes

* Fixes

* Formatting
This commit is contained in:
Gavin Wood
2021-08-11 12:40:10 +02:00
committed by GitHub
parent c40f080394
commit 0bb5434e08
8 changed files with 94 additions and 84 deletions
+10 -8
View File
@@ -106,6 +106,8 @@ pub mod pallet {
CannotReanchor,
/// Too many assets have been attempted for transfer.
TooManyAssets,
/// Origin is invalid for sending.
InvalidOrigin,
}
#[pallet::hooks]
@@ -120,12 +122,12 @@ pub mod pallet {
message: Box<Xcm<()>>,
) -> DispatchResult {
let origin_location = T::SendXcmOrigin::ensure_origin(origin)?;
Self::send_xcm(origin_location.clone(), *dest.clone(), *message.clone()).map_err(
|e| match e {
XcmError::CannotReachDestination(..) => Error::<T>::Unreachable,
_ => Error::<T>::SendFailure,
},
)?;
let interior =
origin_location.clone().try_into().map_err(|_| Error::<T>::InvalidOrigin)?;
Self::send_xcm(interior, *dest.clone(), *message.clone()).map_err(|e| match e {
XcmError::CannotReachDestination(..) => Error::<T>::Unreachable,
_ => Error::<T>::SendFailure,
})?;
Self::deposit_event(Event::Sent(origin_location, *dest, *message));
Ok(())
}
@@ -302,11 +304,11 @@ pub mod pallet {
/// Relay an XCM `message` from a given `interior` location in this context to a given `dest`
/// location. A null `dest` is not handled.
pub fn send_xcm(
interior: MultiLocation,
interior: Junctions,
dest: MultiLocation,
message: Xcm<()>,
) -> Result<(), XcmError> {
let message = if interior.is_here() {
let message = if let Junctions::Here = interior {
message
} else {
Xcm::<()>::RelayedFrom { who: interior, message: Box::new(message) }
+6 -5
View File
@@ -17,10 +17,8 @@
use crate::mock::*;
use frame_support::{assert_noop, assert_ok, traits::Currency};
use polkadot_parachain::primitives::{AccountIdConversion, Id as ParaId};
use xcm::{
opaque::v1::prelude::*,
v1::{Junction, Xcm},
};
use std::convert::TryInto;
use xcm::v1::prelude::*;
const ALICE: AccountId = AccountId::new([0u8; 32]);
const BOB: AccountId = AccountId::new([1u8; 32]);
@@ -55,7 +53,10 @@ fn send_works() {
sent_xcm(),
vec![(
Here.into(),
RelayedFrom { who: sender.clone(), message: Box::new(message.clone()) }
RelayedFrom {
who: sender.clone().try_into().unwrap(),
message: Box::new(message.clone()),
}
)]
);
assert_eq!(