Unverified Commit 12a3e03f authored by Gavin Wood's avatar Gavin Wood Committed by GitHub
Browse files

XCM revamp (#2836)



* Remove unused relaying XCM

* Aggregate HRMP (XCMP/HMP) messages. Payloads for spambot.

* Revert lock

* Fix

* Broken example

* Introduce fee payment mechanics into XCM.

* Weight limitations on XCM execution

* Mock environment for tests and the first test

* Tests for XCM and a few refactors.

* Remove code that's not ready

* Fix for an XCM and an additional test

* Query response system

* XCMP message dispatch system reimagining

- Moved most of the logic into xcm-handler pallet
- Altered the outgoing XCMP API from push to pull
- Changed underlying outgoing queue data structures to avoid multi-page read/writes
- Introduced queuing for incoming messages
- Introduced signal messages as a flow-control sub-stream
- Introduced flow-control with basic threshold back-pressure
- Introduced overall weight limitation on messages executed
- Additonal alterations to XCM APIs for the new system

* Some build fixes

* Remove the Encode bounds sprayed around

* More faff

* Fix bounds amek use latest scale codec.

* remove println

* fixes

* Fix XcmExecutor Tests

* Fix XCM bounds using derivative crate

* Refactor names of XcmGeneric &c into Xcm

* Repot the xcm-executor into xcm-builder

* Docs

* Docs

* Fixes

* Update xcm/src/lib.rs
Co-authored-by: Shawn Tabrizi's avatarShawn Tabrizi <shawntabrizi@gmail.com>

* Fixes

* Docs

* Update runtime/parachains/src/ump.rs
Co-authored-by: Shawn Tabrizi's avatarShawn Tabrizi <shawntabrizi@gmail.com>

* Docs

* Fixes

* Fixes

* Fixes

* Docs

* Fixes

* Fixes

* Introduce transfer_asset specialisation.

* Fixes

* Fixes
Co-authored-by: Shawn Tabrizi's avatarShawn Tabrizi <shawntabrizi@gmail.com>
parent 5288ca3c
Pipeline #133243 failed with stages
in 32 minutes and 18 seconds
......@@ -160,6 +160,12 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "arrayvec"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a2f58b0bb10c380af2b26e57212856b8c9a59e0925b4c20f4a174a49734eaf7"
[[package]]
name = "asn1_der"
version = "0.6.3"
......@@ -1320,6 +1326,17 @@ dependencies = [
"syn",
]
[[package]]
name = "derivative"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "derive_more"
version = "0.99.11"
......@@ -5054,11 +5071,11 @@ dependencies = [
[[package]]
name = "parity-scale-codec"
version = "2.0.0"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75c823fdae1bb5ff5708ee61a62697e6296175dc671710876871c853f48592b3"
checksum = "731f4d179ed52b1c7eeb29baf29c604ea9301b889b23ce93660220a5465d5c6f"
dependencies = [
"arrayvec 0.5.2",
"arrayvec 0.7.0",
"bitvec",
"byte-slice-cast",
"parity-scale-codec-derive",
......@@ -5067,9 +5084,9 @@ dependencies = [
[[package]]
name = "parity-scale-codec-derive"
version = "2.0.0"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9029e65297c7fd6d7013f0579e193ec2b34ae78eabca854c9417504ad8a2d214"
checksum = "f44c5f94427bd0b5076e8f7e15ca3f60a4d8ac0077e4793884e6fdfd8915344e"
dependencies = [
"proc-macro-crate 0.1.5",
"proc-macro2",
......@@ -11307,6 +11324,7 @@ dependencies = [
name = "xcm"
version = "0.8.30"
dependencies = [
"derivative",
"parity-scale-codec",
]
......
......@@ -109,7 +109,7 @@ decl_module! {
/// The given parachain should exist and the payload should not exceed the preconfigured size
/// `config.max_downward_message_size`.
#[weight = (1_000, DispatchClass::Operational)]
pub fn sudo_queue_downward_xcm(origin, id: ParaId, xcm: xcm::VersionedXcm) -> DispatchResult {
pub fn sudo_queue_downward_xcm(origin, id: ParaId, xcm: xcm::opaque::VersionedXcm) -> DispatchResult {
ensure_root(origin)?;
ensure!(<paras::Module<T>>::is_valid_para(id), Error::<T>::ParaDoesntExist);
let config = <configuration::Module<T>>::config();
......
......@@ -18,7 +18,7 @@
use parity_scale_codec::Encode;
use sp_std::marker::PhantomData;
use xcm::{VersionedXcm, v0::{SendXcm, MultiLocation, Junction, Xcm, Result, Error}};
use xcm::opaque::{VersionedXcm, v0::{SendXcm, MultiLocation, Junction, Xcm, Result, Error}};
use runtime_parachains::{configuration, dmp};
/// Xcm sender for relay chain. It only sends downward message.
......@@ -36,7 +36,7 @@ impl<T: configuration::Config + dmp::Config> SendXcm for RelayChainXcmSender<T>
).map_err(Into::<Error>::into)?;
Ok(())
} else {
Err(Error::CannotReachDestination)
Err(Error::CannotReachDestination("UnsupportedDestination"))
}
}
}
......@@ -995,7 +995,7 @@ impl<T: Config> Module<T> {
<Self as Store>::HrmpOpenChannelRequestsList::append(channel_id);
let notification_bytes = {
use xcm::{v0::Xcm, VersionedXcm};
use xcm::opaque::{v0::Xcm, VersionedXcm};
use parity_scale_codec::Encode as _;
VersionedXcm::from(Xcm::HrmpNewChannelOpenRequest {
......@@ -1061,7 +1061,7 @@ impl<T: Config> Module<T> {
let notification_bytes = {
use parity_scale_codec::Encode as _;
use xcm::{v0::Xcm, VersionedXcm};
use xcm::opaque::{v0::Xcm, VersionedXcm};
VersionedXcm::from(Xcm::HrmpChannelAccepted {
recipient: u32::from(origin),
......@@ -1104,7 +1104,7 @@ impl<T: Config> Module<T> {
let config = <configuration::Module<T>>::config();
let notification_bytes = {
use parity_scale_codec::Encode as _;
use xcm::{v0::Xcm, VersionedXcm};
use xcm::opaque::{v0::Xcm, VersionedXcm};
VersionedXcm::from(Xcm::HrmpChannelClosing {
initiator: u32::from(origin),
......
......@@ -20,6 +20,7 @@ use crate::{
};
use sp_std::{fmt, prelude::*};
use sp_std::collections::{btree_map::BTreeMap, vec_deque::VecDeque};
use sp_runtime::traits::Zero;
use frame_support::{decl_module, decl_storage, StorageMap, StorageValue, weights::Weight, traits::Get};
use primitives::v1::{Id as ParaId, UpwardMessage};
......@@ -65,15 +66,15 @@ impl<Config: xcm_executor::Config> UmpSink for XcmSink<Config> {
use xcm::v0::{Junction, MultiLocation, ExecuteXcm};
use xcm_executor::XcmExecutor;
let weight: Weight = 0;
if let Ok(versioned_xcm_message) = VersionedXcm::decode(&mut &msg[..]) {
// TODO: #2841 #UMPQUEUE Get a proper weight limit here. Probably from Relay Chain Config
let weight_limit = Weight::max_value();
let weight = if let Ok(versioned_xcm_message) = VersionedXcm::decode(&mut &msg[..]) {
match versioned_xcm_message {
VersionedXcm::V0(xcm_message) => {
let xcm_junction: Junction = Junction::Parachain { id: origin.into() };
let xcm_location: MultiLocation = xcm_junction.into();
// TODO: Do something with result.
let _result = XcmExecutor::<Config>::execute_xcm(xcm_location, xcm_message);
let result = XcmExecutor::<Config>::execute_xcm(xcm_location, xcm_message, weight_limit);
result.weight_used()
}
}
} else {
......@@ -81,9 +82,10 @@ impl<Config: xcm_executor::Config> UmpSink for XcmSink<Config> {
target: LOG_TARGET,
"Failed to decode versioned XCM from upward message.",
);
}
Weight::zero()
};
// TODO: to be sound, this implementation must ensure that returned (and thus consumed)
// TODO: #2841 #UMPQUEUE to be sound, this implementation must ensure that returned (and thus consumed)
// weight is limited to some small portion of the total block weight (as a ballpark, 1/4, 1/8
// or lower).
weight
......
......@@ -81,11 +81,11 @@ pub use pallet_balances::Call as BalancesCall;
use polkadot_parachain::primitives::Id as ParaId;
use xcm::v0::{MultiLocation, NetworkId};
use xcm_executor::traits::IsConcrete;
use xcm_builder::{
AccountId32Aliases, ChildParachainConvertsVia, SovereignSignedViaLocation,
CurrencyAdapter as XcmCurrencyAdapter, ChildParachainAsNative,
SignedAccountId32AsNative, ChildSystemParachainAsSuperuser, LocationInverter,
IsConcrete, FixedWeightBounds, FixedRateOfConcreteFungible,
};
use constants::{time::*, currency::*, fee::*};
use frame_support::traits::InstanceFilter;
......@@ -616,6 +616,11 @@ type LocalOriginConverter = (
ChildSystemParachainAsSuperuser<ParaId, Origin>,
);
parameter_types! {
pub const BaseXcmWeight: Weight = 100_000;
pub const RocFee: (MultiLocation, u128) = (RocLocation::get(), 1 * CENTS);
}
pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type Call = Call;
......@@ -625,6 +630,10 @@ impl xcm_executor::Config for XcmConfig {
type IsReserve = ();
type IsTeleporter = ();
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = ();
type Weigher = FixedWeightBounds<BaseXcmWeight, Call>;
type Trader = FixedRateOfConcreteFungible<RocFee>;
type ResponseHandler = ();
}
impl parachains_session_info::Config for Runtime {}
......
......@@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
parity-scale-codec = { version = "2.0.0", default-features = false, features = [ "derive" ] }
derivative = {version = "2.2.0", default-features = false, features = [ "use_core" ] }
[features]
default = ["std"]
......
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use alloc::vec::Vec;
use parity_scale_codec::{Encode, Decode};
#[derive(Encode, Decode)]
#[codec(encode_bound())]
#[codec(decode_bound())]
pub struct DoubleEncoded<T> {
encoded: Vec<u8>,
#[codec(skip)]
decoded: Option<T>,
}
impl<T> Clone for DoubleEncoded<T> {
fn clone(&self) -> Self { Self { encoded: self.encoded.clone(), decoded: None } }
}
impl<T> Eq for DoubleEncoded<T> {
}
impl<T> PartialEq for DoubleEncoded<T> {
fn eq(&self, other: &Self) -> bool { self.encoded.eq(&other.encoded) }
}
impl<T> core::fmt::Debug for DoubleEncoded<T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { self.encoded.fmt(f) }
}
impl<T> From<Vec<u8>> for DoubleEncoded<T> {
fn from(encoded: Vec<u8>) -> Self {
Self { encoded, decoded: None }
}
}
impl<T> DoubleEncoded<T> {
pub fn into<S>(self) -> DoubleEncoded<S> { DoubleEncoded::from(self) }
pub fn from<S>(e: DoubleEncoded<S>) -> Self {
Self {
encoded: e.encoded,
decoded: None,
}
}
pub fn as_ref(&self) -> Option<&T> {
self.decoded.as_ref()
}
}
impl<T: Decode> DoubleEncoded<T> {
pub fn ensure_decoded(&mut self) -> Result<&T, ()> {
if self.decoded.is_none() {
self.decoded = T::decode(&mut &self.encoded[..]).ok();
}
self.decoded.as_ref().ok_or(())
}
pub fn take_decoded(&mut self) -> Result<T, ()> {
self.decoded.take().or_else(|| T::decode(&mut &self.encoded[..]).ok()).ok_or(())
}
pub fn try_into(mut self) -> Result<T, ()> {
self.ensure_decoded()?;
self.decoded.ok_or(())
}
}
......@@ -24,13 +24,32 @@
extern crate alloc;
use parity_scale_codec::{Encode, Decode};
use derivative::Derivative;
pub mod v0;
mod double_encoded;
pub use double_encoded::DoubleEncoded;
/// A single XCM message, together with its version code.
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)]
pub enum VersionedXcm {
V0(v0::Xcm),
#[derive(Derivative, Encode, Decode)]
#[derivative(Clone(bound=""), Eq(bound=""), PartialEq(bound=""), Debug(bound=""))]
#[codec(encode_bound())]
#[codec(decode_bound())]
pub enum VersionedXcm<Call> {
V0(v0::Xcm<Call>),
}
pub mod opaque {
pub mod v0 {
// Everything from v0
pub use crate::v0::*;
// Then override with the opaque types in v0
pub use crate::v0::opaque::{Xcm, Order};
}
/// The basic VersionedXcm type which just uses the `Vec<u8>` as an encoded call.
pub type VersionedXcm = super::VersionedXcm<()>;
}
/// A versioned multi-location, a relative location of a cross-consensus system identifier.
......
......@@ -45,6 +45,10 @@ pub enum Junction {
/// An indexed parachain belonging to and operated by the context.
///
/// Generally used when the context is a Polkadot Relay-chain.
///
/// There is also `Parachain` which can be used in tests to avoid the faffy `{ id: ... }` syntax. Production
/// code should use this.
// TODO: parity-scale-codec#262: Change to be `Parachain(#[codec(compact)] u32)`
Parachain { #[codec(compact)] id: u32 },
/// A 32-byte identifier for an account of a specific network that is respected as a sovereign endpoint within
/// the context.
......@@ -64,7 +68,7 @@ pub enum Junction {
/// An instanced, indexed pallet that forms a constituent part of the context.
///
/// Generally used when the context is a Frame-based chain.
PalletInstance { id: u8 },
PalletInstance(u8),
/// A non-descript index within the context location.
///
/// Usage will vary widely owing to its generality.
......
......@@ -16,11 +16,11 @@
//! Version 0 of the Cross-Consensus Message format data structures.
use core::{result, convert::TryFrom};
use alloc::{boxed::Box, vec::Vec};
use core::{result, convert::TryFrom, fmt::Debug};
use derivative::Derivative;
use alloc::vec::Vec;
use parity_scale_codec::{self, Encode, Decode};
use super::{VersionedXcm, VersionedMultiAsset};
use crate::{VersionedMultiAsset, DoubleEncoded, VersionedXcm};
mod junction;
mod multi_asset;
......@@ -31,10 +31,10 @@ pub use junction::{Junction, NetworkId};
pub use multi_asset::{MultiAsset, AssetInstance};
pub use multi_location::MultiLocation;
pub use order::Order;
pub use traits::{Error, Result, SendXcm, ExecuteXcm};
pub use traits::{Error, Result, SendXcm, ExecuteXcm, Outcome};
// TODO: Efficient encodings for Vec<MultiAsset>, Vec<Order>, using initial byte values 128+ to encode the number of
// items in the vector.
// TODO: #2841 #XCMENCODE Efficient encodings for Vec<MultiAsset>, 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)]
......@@ -52,6 +52,13 @@ pub enum OriginKind {
Superuser,
}
/// 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.
///
/// Consensus systems that may send and receive messages include blockchains and smart contracts.
......@@ -60,8 +67,11 @@ pub enum OriginKind {
///
/// This is the inner XCM format and is version-sensitive. Messages are typically passed using the outer
/// XCM format, known as `VersionedXcm`.
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)]
pub enum Xcm {
#[derive(Derivative, Encode, Decode)]
#[derivative(Clone(bound = ""), Eq(bound = ""), PartialEq(bound = ""), Debug(bound = ""))]
#[codec(encode_bound())]
#[codec(decode_bound())]
pub enum Xcm<Call> {
/// Withdraw asset(s) (`assets`) from the ownership of `origin` and place them into `holding`. Execute the
/// orders (`effects`).
///
......@@ -71,7 +81,8 @@ pub enum Xcm {
/// Kind: *Instruction*.
///
/// Errors:
WithdrawAsset { assets: Vec<MultiAsset>, effects: Vec<Order> },
#[codec(index = 0)]
WithdrawAsset { assets: Vec<MultiAsset>, effects: Vec<Order<Call>> },
/// Asset(s) (`assets`) have been received into the ownership of this system on the `origin` system.
///
......@@ -87,7 +98,8 @@ pub enum Xcm {
/// Kind: *Trusted Indication*.
///
/// Errors:
ReserveAssetDeposit { assets: Vec<MultiAsset>, effects: Vec<Order> },
#[codec(index = 1)]
ReserveAssetDeposit { assets: Vec<MultiAsset>, effects: Vec<Order<Call>> },
/// Asset(s) (`assets`) have been destroyed on the `origin` system and equivalent assets should be
/// created on this system.
......@@ -104,7 +116,8 @@ pub enum Xcm {
/// Kind: *Trusted Indication*.
///
/// Errors:
TeleportAsset { assets: Vec<MultiAsset>, effects: Vec<Order> },
#[codec(index = 2)]
TeleportAsset { assets: Vec<MultiAsset>, effects: Vec<Order<Call>> },
/// Indication of the contents of the holding account corresponding to the `QueryHolding` order of `query_id`.
///
......@@ -116,48 +129,56 @@ pub enum Xcm {
/// Kind: *Information*.
///
/// Errors:
Balances { #[codec(compact)] query_id: u64, assets: Vec<MultiAsset> },
#[codec(index = 3)]
QueryResponse { #[codec(compact)] query_id: u64, response: Response },
/// Apply the encoded transaction `call`, whose dispatch-origin should be `origin` as expressed by the kind
/// of origin `origin_type`.
/// Withdraw asset(s) (`assets`) from the ownership of `origin` and place equivalent assets under the
/// ownership of `dest` within this consensus system.
///
/// - `origin_type`: The means of expressing the message origin as a dispatch origin.
/// - `call`: The encoded transaction to be applied.
/// - `assets`: The asset(s) to be withdrawn.
/// - `dest`: The new owner for the assets.
///
/// Safety: No concerns.
///
/// Kind: *Instruction*.
///
/// Errors:
Transact { origin_type: OriginKind, call: Vec<u8> },
#[codec(index = 4)]
TransferAsset { assets: Vec<MultiAsset>, dest: MultiLocation },
/// Relay an inner message (`inner`) to a locally reachable destination ID `dest`.
/// Withdraw asset(s) (`assets`) from the ownership of `origin` and place equivalent assets under the
/// ownership of `dest` within this consensus system.
///
/// The message sent to the destination will be wrapped into a `RelayedFrom` message, with the
/// `superorigin` being this location.
/// Send an onward XCM message to `dest` of `ReserveAssetDeposit` with the given `effects`.
///
/// - `dest: MultiLocation`: The location of the to be relayed into. This may never contain `Parent`, and
/// it must be immediately reachable from the interpreting context.
/// - `inner: VersionedXcm`: The message to be wrapped and relayed.
/// - `assets`: The asset(s) to be withdrawn.
/// - `dest`: The new owner for the assets.
/// - `effects`: The orders that should be contained in the `ReserveAssetDeposit` which is sent onwards to
/// `dest.
///
/// Safety: No concerns.
///
/// Kind: *Instruction*.
///
/// Errors:
RelayTo { dest: MultiLocation, inner: Box<VersionedXcm> },
#[codec(index = 5)]
TransferReserveAsset { assets: Vec<MultiAsset>, dest: MultiLocation, effects: Vec<Order<()>> },
/// A message (`inner`) was sent to `origin` from `superorigin` with the intention of being relayed.
/// Apply the encoded transaction `call`, whose dispatch-origin should be `origin` as expressed by the kind
/// of origin `origin_type`.
///
/// - `superorigin`: The location of the `inner` message origin, **relative to `origin`**.
/// - `inner`: The message sent by the super origin.
/// - `origin_type`: The means of expressing the message origin as a dispatch origin.
/// - `max_weight`: The weight of `call`; this should be at least the chain's calculated weight and will
/// be used in the weight determination arithmetic.
/// - `call`: The encoded transaction to be applied.
///
/// Safety: `superorigin` must express a sub-consensus only; it may *NEVER* contain a `Parent` junction.
/// Safety: No concerns.
///
/// Kind: *Trusted Indication*.
/// Kind: *Instruction*.
///
/// Errors:
RelayedFrom { superorigin: MultiLocation, inner: Box<VersionedXcm> },
#[codec(index = 6)]
Transact { origin_type: OriginKind, require_weight_at_most: u64, call: DoubleEncoded<Call> },
/// A message to notify about a new incoming HRMP channel. This message is meant to be sent by the
/// relay-chain to a para.
......@@ -169,6 +190,7 @@ pub enum Xcm {
/// Safety: The message should originate directly from the relay-chain.
///
/// Kind: *System Notification*
#[codec(index = 7)]
HrmpNewChannelOpenRequest {
#[codec(compact)] sender: u32,
#[codec(compact)] max_message_size: u32,
......@@ -184,6 +206,7 @@ pub enum Xcm {
/// Kind: *System Notification*
///
/// Errors:
#[codec(index = 8)]
HrmpChannelAccepted {
#[codec(compact)] recipient: u32,
},
......@@ -198,6 +221,7 @@ pub enum Xcm {
/// Kind: *System Notification*
///
/// Errors:
#[codec(index = 9)]
HrmpChannelClosing {
#[codec(compact)] initiator: u32,
#[codec(compact)] sender: u32,
......@@ -205,17 +229,54 @@ pub enum Xcm {
},
}
impl From<Xcm> for VersionedXcm {
fn from(x: Xcm) -> Self {
impl<Call> From<Xcm<Call>> for VersionedXcm<Call> {
fn from(x: Xcm<Call>) -> Self {
VersionedXcm::V0(x)
}
}
impl TryFrom<VersionedXcm> for Xcm {
impl<Call> TryFrom<VersionedXcm<Call>> for Xcm<Call> {
type Error = ();
fn try_from(x: VersionedXcm) -> result::Result<Self, ()> {
fn try_from(x: VersionedXcm<Call>) -> result::Result<Self, ()> {
match x {
VersionedXcm::V0(x) => Ok(x),
}
}
}
impl<Call> Xcm<Call> {
pub fn into<C>(self) -> Xcm<C> { Xcm::from(self) }
pub fn from<C>(xcm: Xcm<C>) -> Self {
use Xcm::*;
match xcm {
WithdrawAsset { assets, effects }
=> WithdrawAsset { assets, effects: effects.into_iter().map(Order::into).collect() },
ReserveAssetDeposit { assets, effects }
=> ReserveAssetDeposit { assets, effects: effects.into_iter().map(Order::into).collect() },
TeleportAsset { assets, effects }
=> TeleportAsset { assets, effects: effects.into_iter().map(Order::into).collect() },
QueryResponse { query_id: u64, response }
=> QueryResponse { query_id: u64, response },
TransferAsset { assets, dest }
=> TransferAsset { assets, dest },
TransferReserveAsset { assets, dest, effects }
=> TransferReserveAsset { assets, dest, effects },
HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity}
=> HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity},
HrmpChannelAccepted { recipient}
=> HrmpChannelAccepted { recipient},
HrmpChannelClosing { initiator, sender, recipient}
=> HrmpChannelClosing { initiator, sender, recipient},
Transact { origin_type, require_weight_at_most, call}
=> Transact { origin_type, require_weight_at_most, call: call.into() }
}
}
}
pub mod opaque {
/// The basic concrete type of `generic::Xcm`, which doesn't make any assumptions about the format of a
/// call other than it is pre-encoded.
pub type Xcm = super::Xcm<()>;
pub use super::order::opaque::*;
}
......@@ -146,6 +146,159 @@ pub enum MultiAsset {
ConcreteNonFungible { class: MultiLocation, instance: AssetInstance },
}
impl MultiAsset {
pub fn is_wildcard(&self) -> bool {
match self {
MultiAsset::None
| MultiAsset::AbstractFungible {..}
| MultiAsset::AbstractNonFungible {..}
| MultiAsset::ConcreteFungible {..}
| MultiAsset::ConcreteNonFungible {..}
=> false,
MultiAsset::All
| MultiAsset::AllFungible
| MultiAsset::AllNonFungible
| MultiAsset::AllAbstractFungible {..}
| MultiAsset::AllConcreteFungible {..}
| MultiAsset::AllAbstractNonFungible {..}
| MultiAsset::AllConcreteNonFungible {..}
=> true,
}
}
fn is_none(&self) -> bool {
match self {
MultiAsset::None
| MultiAsset::AbstractFungible { amount: 0, .. }
| MultiAsset::ConcreteFungible { amount: 0, .. }
=> true,
_ => false,