From b0b17de2a54cb6a93a014c29bd00f09c2e2e278a Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Fri, 21 Oct 2022 14:31:52 +0300 Subject: [PATCH] remove xcm-copy module --- bin/runtime-common/src/messages.rs | 107 ----------------------------- 1 file changed, 107 deletions(-) diff --git a/bin/runtime-common/src/messages.rs b/bin/runtime-common/src/messages.rs index 14d505f51b..3744d7153e 100644 --- a/bin/runtime-common/src/messages.rs +++ b/bin/runtime-common/src/messages.rs @@ -1015,113 +1015,6 @@ pub mod target { } } -pub use xcm_copy::*; - -// copy of private types from xcm-builder/src/universal_exports.rs -pub mod xcm_copy { - use codec::{Decode, Encode}; - use frame_support::{ensure, traits::Get}; - use sp_std::{convert::TryInto, marker::PhantomData, prelude::*}; - use xcm::prelude::*; - use xcm_executor::traits::ExportXcm; - - pub trait DispatchBlob { - /// Dispatches an incoming blob and returns the unexpectable weight consumed by the - /// dispatch. - fn dispatch_blob(blob: Vec) -> Result<(), DispatchBlobError>; - } - - pub trait HaulBlob { - /// Sends a blob over some point-to-point link. This will generally be implemented by a - /// bridge. - fn haul_blob(blob: Vec); - } - - #[derive(Clone, Encode, Decode)] - pub struct BridgeMessage { - /// The message destination as a *Universal Location*. This means it begins with a - /// `GlobalConsensus` junction describing the network under which global consensus happens. - /// If this does not match our global consensus then it's a fatal error. - universal_dest: VersionedInteriorMultiLocation, - message: VersionedXcm<()>, - } - - pub enum DispatchBlobError { - Unbridgable, - InvalidEncoding, - UnsupportedLocationVersion, - UnsupportedXcmVersion, - RoutingError, - NonUniversalDestination, - WrongGlobal, - } - - pub struct BridgeBlobDispatcher(PhantomData<(Router, OurPlace)>); - impl> DispatchBlob - for BridgeBlobDispatcher - { - fn dispatch_blob(blob: Vec) -> Result<(), DispatchBlobError> { - let our_universal = OurPlace::get(); - let our_global = - our_universal.global_consensus().map_err(|()| DispatchBlobError::Unbridgable)?; - let BridgeMessage { universal_dest, message } = - Decode::decode(&mut &blob[..]).map_err(|_| DispatchBlobError::InvalidEncoding)?; - let universal_dest: InteriorMultiLocation = universal_dest - .try_into() - .map_err(|_| DispatchBlobError::UnsupportedLocationVersion)?; - // `universal_dest` is the desired destination within the universe: first we need to - // check we're in the right global consensus. - let intended_global = universal_dest - .global_consensus() - .map_err(|()| DispatchBlobError::NonUniversalDestination)?; - ensure!(intended_global == our_global, DispatchBlobError::WrongGlobal); - let dest = universal_dest.relative_to(&our_universal); - let message: Xcm<()> = - message.try_into().map_err(|_| DispatchBlobError::UnsupportedXcmVersion)?; - send_xcm::(dest, message).map_err(|_| DispatchBlobError::RoutingError)?; - Ok(()) - } - } - - pub struct HaulBlobExporter( - PhantomData<(Bridge, BridgedNetwork, Price)>, - ); - impl, Price: Get> ExportXcm - for HaulBlobExporter - { - type Ticket = (Vec, XcmHash); - - fn validate( - network: NetworkId, - _channel: u32, - _universal_source: &mut Option, - destination: &mut Option, - message: &mut Option>, - ) -> Result<((Vec, XcmHash), MultiAssets), SendError> { - let bridged_network = BridgedNetwork::get(); - ensure!(network == bridged_network, SendError::NotApplicable); - // We don't/can't use the `channel` for this adapter. - let dest = destination.take().ok_or(SendError::MissingArgument)?; - let universal_dest = match dest.pushed_front_with(GlobalConsensus(bridged_network)) { - Ok(d) => d.into(), - Err((dest, _)) => { - *destination = Some(dest); - return Err(SendError::NotApplicable) - }, - }; - let message = VersionedXcm::from(message.take().ok_or(SendError::MissingArgument)?); - let hash = message.using_encoded(sp_io::hashing::blake2_256); - let blob = BridgeMessage { universal_dest, message }.encode(); - Ok(((blob, hash), Price::get())) - } - - fn deliver((blob, hash): (Vec, XcmHash)) -> Result { - Bridge::haul_blob(blob); - Ok(hash) - } - } -} - #[cfg(test)] mod tests { use super::*;