Support XCM v1 (Companion to #2815) (#561)

* support for XCM v1

* Fixes

* Fix.

* Use `xcm::latest`

* Bump Polkadot

Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
Gavin Wood
2021-08-06 21:13:33 +02:00
committed by Bastian Köcher
parent fd80849dde
commit e36689ffc8
12 changed files with 225 additions and 207 deletions
+7 -5
View File
@@ -22,7 +22,7 @@
use sp_std::marker::PhantomData;
use codec::Encode;
use cumulus_primitives_core::UpwardMessageSender;
use xcm::{VersionedXcm, v0::{Xcm, MultiLocation, Junction, SendXcm, Error as XcmError}};
use xcm::{WrapVersion, latest::prelude::*};
/// Xcm router which recognises the `Parent` destination and handles it by sending the message into
/// the given UMP `UpwardMessageSender` implementation. Thus this essentially adapts an
@@ -31,13 +31,15 @@ use xcm::{VersionedXcm, v0::{Xcm, MultiLocation, Junction, SendXcm, Error as Xcm
/// NOTE: This is a pretty dumb "just send it" router; we will probably want to introduce queuing
/// to UMP eventually and when we do, the pallet which implements the queuing will be responsible
/// for the `SendXcm` implementation.
pub struct ParentAsUmp<T>(PhantomData<T>);
impl<T: UpwardMessageSender> SendXcm for ParentAsUmp<T> {
pub struct ParentAsUmp<T, W>(PhantomData<(T, W)>);
impl<T: UpwardMessageSender, W: WrapVersion> SendXcm for ParentAsUmp<T, W> {
fn send_xcm(dest: MultiLocation, msg: Xcm<()>) -> Result<(), XcmError> {
match &dest {
// An upward message for the relay chain.
MultiLocation::X1(Junction::Parent) => {
let data = VersionedXcm::<()>::from(msg).encode();
MultiLocation::X1(Parent) => {
let versioned_xcm = W::wrap_version(&dest, msg)
.map_err(|()| XcmError::DestinationUnsupported)?;
let data = versioned_xcm.encode();
T::send_upward_message(data)
.map_err(|e| XcmError::SendFailed(e.into()))?;