Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix Backwards Compatability with v0 Response #3597

Merged
4 commits merged into from
Aug 9, 2021
Merged
Changes from 2 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
File renamed without changes.
48 changes: 45 additions & 3 deletions xcm/src/v0/mod.rs
Original file line number Diff line number Diff line change
@@ -25,11 +25,13 @@ use core::{
use derivative::Derivative;
use parity_scale_codec::{self, Decode, Encode};

mod junction;
mod multi_asset;
mod multi_location;
mod order;
mod traits;
use super::v1::Xcm as Xcm1;
use super::v1::{Response as Response1, Xcm as Xcm1};
pub use junction::{BodyId, BodyPart, Junction, NetworkId};
pub use multi_asset::{AssetInstance, MultiAsset};
pub use multi_location::MultiLocation;
pub use order::Order;
@@ -52,7 +54,38 @@ pub mod prelude {
};
}

pub use super::v1::{BodyId, BodyPart, Junction, NetworkId, OriginKind, Response};
// TODO: #2841 #XCMENCODE Efficient encodings for MultiAssets, Vec<Order>, using initial byte values 128+ to encode
// the number of items in the vector.

/// Basically just the XCM (more general) version of `ParachainDispatchOrigin`.
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, Debug)]
pub enum OriginKind {
/// Origin should just be the native dispatch origin representation for the sender in the
/// local runtime framework. For Cumulus/Frame chains this is the `Parachain` or `Relay` origin
/// if coming from a chain, though there may be others if the `MultiLocation` XCM origin has a
/// primary/native dispatch origin form.
Native,

/// Origin should just be the standard account-based origin with the sovereign account of
/// the sender. For Cumulus/Frame chains, this is the `Signed` origin.
SovereignAccount,

/// Origin should be the super-user. For Cumulus/Frame chains, this is the `Root` origin.
/// This will not usually be an available option.
Superuser,

/// Origin should be interpreted as an XCM native origin and the `MultiLocation` should be
/// encoded directly in the dispatch origin unchanged. For Cumulus/Frame chains, this will be
/// the `pallet_xcm::Origin::Xcm` type.
Xcm,
}

/// Response data to a query.
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)]
pub enum Response {
/// Some assets.
Assets(Vec<MultiAsset>),
}

/// Cross-Consensus Message: A message from one consensus system to another.
///
@@ -287,6 +320,15 @@ pub mod opaque {
pub use super::order::opaque::*;
}

// Convert from a v1 response to a v0 response
impl From<Response1> for Response {
fn from(new_response: Response1) -> Self {
match new_response {
Response1::Assets(assets) => Self::Assets(assets.into()),
}
}
}

impl<Call> TryFrom<Xcm1<Call>> for Xcm<Call> {
type Error = ();
fn try_from(x: Xcm1<Call>) -> result::Result<Xcm<Call>, ()> {
@@ -314,7 +356,7 @@ impl<Call> TryFrom<Xcm1<Call>> for Xcm<Call> {
.collect::<result::Result<_, _>>()?,
},
Xcm1::QueryResponse { query_id: u64, response } =>
QueryResponse { query_id: u64, response },
QueryResponse { query_id: u64, response: response.into() },
Xcm1::TransferAsset { assets, beneficiary } =>
TransferAsset { assets: assets.into(), dest: beneficiary.into() },
Xcm1::TransferReserveAsset { assets, dest, effects } => TransferReserveAsset {
44 changes: 14 additions & 30 deletions xcm/src/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@

//! Version 1 of the Cross-Consensus Message format data structures.
use super::v0::Xcm as Xcm0;
use super::v0::{Response as Response0, Xcm as Xcm0};
use crate::DoubleEncoded;
use alloc::vec::Vec;
use core::{
@@ -27,13 +27,11 @@ use core::{
use derivative::Derivative;
use parity_scale_codec::{self, Decode, Encode};

mod junction;
pub mod multiasset;
mod multilocation;
mod order;
mod traits; // the new multiasset.

pub use junction::{BodyId, BodyPart, Junction, NetworkId};
pub use multiasset::{
AssetId, AssetInstance, Fungibility, MultiAsset, MultiAssetFilter, MultiAssets,
WildFungibility, WildMultiAsset,
@@ -45,7 +43,7 @@ pub use traits::{Error, ExecuteXcm, Outcome, Result, SendXcm};
/// A prelude for importing all types typically used when interacting with XCM messages.
pub mod prelude {
pub use super::{
junction::{
super::v0::{
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
BodyId, BodyPart,
Junction::*,
NetworkId::{self, *},
@@ -69,31 +67,7 @@ pub mod prelude {
};
}

// TODO: #2841 #XCMENCODE Efficient encodings for MultiAssets, Vec<Order>, using initial byte values 128+ to encode
// the number of items in the vector.

/// Basically just the XCM (more general) version of `ParachainDispatchOrigin`.
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, Debug)]
pub enum OriginKind {
/// Origin should just be the native dispatch origin representation for the sender in the
/// local runtime framework. For Cumulus/Frame chains this is the `Parachain` or `Relay` origin
/// if coming from a chain, though there may be others if the `MultiLocation` XCM origin has a
/// primary/native dispatch origin form.
Native,

/// Origin should just be the standard account-based origin with the sovereign account of
/// the sender. For Cumulus/Frame chains, this is the `Signed` origin.
SovereignAccount,

/// Origin should be the super-user. For Cumulus/Frame chains, this is the `Root` origin.
/// This will not usually be an available option.
Superuser,

/// Origin should be interpreted as an XCM native origin and the `MultiLocation` should be
/// encoded directly in the dispatch origin unchanged. For Cumulus/Frame chains, this will be
/// the `pallet_xcm::Origin::Xcm` type.
Xcm,
}
pub use super::v0::{BodyId, BodyPart, Junction, NetworkId, OriginKind};

/// Response data to a query.
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)]
@@ -338,6 +312,16 @@ pub mod opaque {
pub use super::order::opaque::*;
}

// Convert from a v0 response to a v1 response
impl TryFrom<Response0> for Response {
type Error = ();
fn try_from(old_response: Response0) -> result::Result<Self, ()> {
match old_response {
Response0::Assets(assets) => Ok(Self::Assets(assets.try_into()?)),
}
}
}

impl<Call> TryFrom<Xcm0<Call>> for Xcm<Call> {
type Error = ();
fn try_from(old: Xcm0<Call>) -> result::Result<Xcm<Call>, ()> {
@@ -365,7 +349,7 @@ impl<Call> TryFrom<Xcm0<Call>> for Xcm<Call> {
.collect::<result::Result<_, _>>()?,
},
Xcm0::QueryResponse { query_id: u64, response } =>
QueryResponse { query_id: u64, response },
QueryResponse { query_id: u64, response: response.try_into()? },
Xcm0::TransferAsset { assets, dest } =>
TransferAsset { assets: assets.try_into()?, beneficiary: dest.into() },
Xcm0::TransferReserveAsset { assets, dest, effects } => TransferReserveAsset {