referrerpolicy=no-referrer-when-downgrade

staging_xcm/v4/
mod.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Version 4 of the Cross-Consensus Message format data structures.
18
19pub use super::v3::GetWeight;
20use super::{
21	v3::{
22		Instruction as OldInstruction, PalletInfo as OldPalletInfo,
23		QueryResponseInfo as OldQueryResponseInfo, Response as OldResponse, Xcm as OldXcm,
24	},
25	v5::{
26		Instruction as NewInstruction, PalletInfo as NewPalletInfo,
27		QueryResponseInfo as NewQueryResponseInfo, Response as NewResponse, Xcm as NewXcm,
28	},
29};
30use crate::{utils::decode_xcm_instructions, DoubleEncoded};
31use alloc::{vec, vec::Vec};
32use bounded_collections::{parameter_types, BoundedVec};
33use codec::{
34	self, Decode, DecodeWithMemTracking, Encode, Error as CodecError, Input as CodecInput,
35	MaxEncodedLen,
36};
37use core::{fmt::Debug, result};
38use derive_where::derive_where;
39use frame_support::dispatch::GetDispatchInfo;
40use scale_info::TypeInfo;
41
42mod asset;
43mod junction;
44pub(crate) mod junctions;
45mod location;
46mod traits;
47
48pub use asset::{
49	Asset, AssetFilter, AssetId, AssetInstance, Assets, Fungibility, WildAsset, WildFungibility,
50	MAX_ITEMS_IN_ASSETS,
51};
52pub use junction::{BodyId, BodyPart, Junction, NetworkId};
53pub use junctions::Junctions;
54pub use location::{Ancestor, AncestorThen, InteriorLocation, Location, Parent, ParentThen};
55pub use traits::{
56	send_xcm, validate_send, Error, ExecuteXcm, Outcome, PreparedMessage, Reanchorable, Result,
57	SendError, SendResult, SendXcm, Weight, XcmHash,
58};
59// These parts of XCM v3 are unchanged in XCM v4, and are re-imported here.
60pub use super::v3::{MaxDispatchErrorLen, MaybeErrorCode, OriginKind, WeightLimit};
61
62/// This module's XCM version.
63pub const VERSION: super::Version = 4;
64
65/// An identifier for a query.
66pub type QueryId = u64;
67
68#[derive(Default, Encode, DecodeWithMemTracking, TypeInfo)]
69#[derive_where(Clone, Eq, PartialEq, Debug)]
70#[codec(encode_bound())]
71#[codec(decode_bound())]
72#[scale_info(bounds(), skip_type_params(Call))]
73pub struct Xcm<Call>(pub Vec<Instruction<Call>>);
74
75impl<Call> Decode for Xcm<Call> {
76	fn decode<I: CodecInput>(input: &mut I) -> core::result::Result<Self, CodecError> {
77		Ok(Xcm(decode_xcm_instructions(input)?))
78	}
79}
80
81impl<Call> Xcm<Call> {
82	/// Create an empty instance.
83	pub fn new() -> Self {
84		Self(vec![])
85	}
86
87	/// Return `true` if no instructions are held in `self`.
88	pub fn is_empty(&self) -> bool {
89		self.0.is_empty()
90	}
91
92	/// Return the number of instructions held in `self`.
93	pub fn len(&self) -> usize {
94		self.0.len()
95	}
96
97	/// Return a reference to the inner value.
98	pub fn inner(&self) -> &[Instruction<Call>] {
99		&self.0
100	}
101
102	/// Return a mutable reference to the inner value.
103	pub fn inner_mut(&mut self) -> &mut Vec<Instruction<Call>> {
104		&mut self.0
105	}
106
107	/// Consume and return the inner value.
108	pub fn into_inner(self) -> Vec<Instruction<Call>> {
109		self.0
110	}
111
112	/// Return an iterator over references to the items.
113	pub fn iter(&self) -> impl Iterator<Item = &Instruction<Call>> {
114		self.0.iter()
115	}
116
117	/// Return an iterator over mutable references to the items.
118	pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Instruction<Call>> {
119		self.0.iter_mut()
120	}
121
122	/// Consume and return an iterator over the items.
123	pub fn into_iter(self) -> impl Iterator<Item = Instruction<Call>> {
124		self.0.into_iter()
125	}
126
127	/// Consume and either return `self` if it contains some instructions, or if it's empty, then
128	/// instead return the result of `f`.
129	pub fn or_else(self, f: impl FnOnce() -> Self) -> Self {
130		if self.0.is_empty() {
131			f()
132		} else {
133			self
134		}
135	}
136
137	/// Return the first instruction, if any.
138	pub fn first(&self) -> Option<&Instruction<Call>> {
139		self.0.first()
140	}
141
142	/// Return the last instruction, if any.
143	pub fn last(&self) -> Option<&Instruction<Call>> {
144		self.0.last()
145	}
146
147	/// Return the only instruction, contained in `Self`, iff only one exists (`None` otherwise).
148	pub fn only(&self) -> Option<&Instruction<Call>> {
149		if self.0.len() == 1 {
150			self.0.first()
151		} else {
152			None
153		}
154	}
155
156	/// Return the only instruction, contained in `Self`, iff only one exists (returns `self`
157	/// otherwise).
158	pub fn into_only(mut self) -> core::result::Result<Instruction<Call>, Self> {
159		if self.0.len() == 1 {
160			self.0.pop().ok_or(self)
161		} else {
162			Err(self)
163		}
164	}
165}
166
167impl<Call> From<Vec<Instruction<Call>>> for Xcm<Call> {
168	fn from(c: Vec<Instruction<Call>>) -> Self {
169		Self(c)
170	}
171}
172
173impl<Call> From<Xcm<Call>> for Vec<Instruction<Call>> {
174	fn from(c: Xcm<Call>) -> Self {
175		c.0
176	}
177}
178
179/// A prelude for importing all types typically used when interacting with XCM messages.
180pub mod prelude {
181	mod contents {
182		pub use super::super::{
183			send_xcm, validate_send, Ancestor, AncestorThen, Asset,
184			AssetFilter::{self, *},
185			AssetId,
186			AssetInstance::{self, *},
187			Assets, BodyId, BodyPart, Error as XcmError, ExecuteXcm,
188			Fungibility::{self, *},
189			Instruction::*,
190			InteriorLocation,
191			Junction::{self, *},
192			Junctions::{self, Here},
193			Location, MaybeErrorCode,
194			NetworkId::{self, *},
195			OriginKind, Outcome, PalletInfo, Parent, ParentThen, PreparedMessage, QueryId,
196			QueryResponseInfo, Reanchorable, Response, Result as XcmResult, SendError, SendResult,
197			SendXcm, Weight,
198			WeightLimit::{self, *},
199			WildAsset::{self, *},
200			WildFungibility::{self, Fungible as WildFungible, NonFungible as WildNonFungible},
201			XcmContext, XcmHash, XcmWeightInfo, VERSION as XCM_VERSION,
202		};
203	}
204	pub use super::{Instruction, Xcm};
205	pub use contents::*;
206	pub mod opaque {
207		pub use super::{
208			super::opaque::{Instruction, Xcm},
209			contents::*,
210		};
211	}
212}
213
214parameter_types! {
215	pub MaxPalletNameLen: u32 = 48;
216	pub MaxPalletsInfo: u32 = 64;
217}
218
219#[derive(
220	Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen,
221)]
222pub struct PalletInfo {
223	#[codec(compact)]
224	pub index: u32,
225	pub name: BoundedVec<u8, MaxPalletNameLen>,
226	pub module_name: BoundedVec<u8, MaxPalletNameLen>,
227	#[codec(compact)]
228	pub major: u32,
229	#[codec(compact)]
230	pub minor: u32,
231	#[codec(compact)]
232	pub patch: u32,
233}
234
235impl TryInto<OldPalletInfo> for PalletInfo {
236	type Error = ();
237
238	fn try_into(self) -> result::Result<OldPalletInfo, Self::Error> {
239		OldPalletInfo::new(
240			self.index,
241			self.name.into_inner(),
242			self.module_name.into_inner(),
243			self.major,
244			self.minor,
245			self.patch,
246		)
247		.map_err(|_| ())
248	}
249}
250
251impl TryInto<NewPalletInfo> for PalletInfo {
252	type Error = ();
253
254	fn try_into(self) -> result::Result<NewPalletInfo, Self::Error> {
255		NewPalletInfo::new(
256			self.index,
257			self.name.into_inner(),
258			self.module_name.into_inner(),
259			self.major,
260			self.minor,
261			self.patch,
262		)
263		.map_err(|_| ())
264	}
265}
266
267impl PalletInfo {
268	pub fn new(
269		index: u32,
270		name: Vec<u8>,
271		module_name: Vec<u8>,
272		major: u32,
273		minor: u32,
274		patch: u32,
275	) -> result::Result<Self, Error> {
276		let name = BoundedVec::try_from(name).map_err(|_| Error::Overflow)?;
277		let module_name = BoundedVec::try_from(module_name).map_err(|_| Error::Overflow)?;
278
279		Ok(Self { index, name, module_name, major, minor, patch })
280	}
281}
282
283/// Response data to a query.
284#[derive(
285	Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen,
286)]
287pub enum Response {
288	/// No response. Serves as a neutral default.
289	Null,
290	/// Some assets.
291	Assets(Assets),
292	/// The outcome of an XCM instruction.
293	ExecutionResult(Option<(u32, Error)>),
294	/// An XCM version.
295	Version(super::Version),
296	/// The index, instance name, pallet name and version of some pallets.
297	PalletsInfo(BoundedVec<PalletInfo, MaxPalletsInfo>),
298	/// The status of a dispatch attempt using `Transact`.
299	DispatchResult(MaybeErrorCode),
300}
301
302impl Default for Response {
303	fn default() -> Self {
304		Self::Null
305	}
306}
307
308impl TryFrom<OldResponse> for Response {
309	type Error = ();
310
311	fn try_from(old: OldResponse) -> result::Result<Self, Self::Error> {
312		use OldResponse::*;
313		Ok(match old {
314			Null => Self::Null,
315			Assets(assets) => Self::Assets(assets.try_into()?),
316			ExecutionResult(result) =>
317				Self::ExecutionResult(result.map(|(num, old_error)| (num, old_error.into()))),
318			Version(version) => Self::Version(version),
319			PalletsInfo(pallet_info) => {
320				let inner = pallet_info
321					.into_iter()
322					.map(TryInto::try_into)
323					.collect::<result::Result<Vec<_>, _>>()?;
324				Self::PalletsInfo(
325					BoundedVec::<PalletInfo, MaxPalletsInfo>::try_from(inner).map_err(|_| ())?,
326				)
327			},
328			DispatchResult(maybe_error) => Self::DispatchResult(maybe_error),
329		})
330	}
331}
332
333impl TryFrom<NewResponse> for Response {
334	type Error = ();
335
336	fn try_from(new: NewResponse) -> result::Result<Self, Self::Error> {
337		use NewResponse::*;
338		Ok(match new {
339			Null => Self::Null,
340			Assets(assets) => Self::Assets(assets.try_into()?),
341			ExecutionResult(result) => Self::ExecutionResult(
342				result
343					.map(|(num, new_error)| (num, new_error.try_into()))
344					.map(|(num, result)| result.map(|inner| (num, inner)))
345					.transpose()?,
346			),
347			Version(version) => Self::Version(version),
348			PalletsInfo(pallet_info) => {
349				let inner = pallet_info
350					.into_iter()
351					.map(TryInto::try_into)
352					.collect::<result::Result<Vec<_>, _>>()?;
353				Self::PalletsInfo(
354					BoundedVec::<PalletInfo, MaxPalletsInfo>::try_from(inner).map_err(|_| ())?,
355				)
356			},
357			DispatchResult(maybe_error) =>
358				Self::DispatchResult(maybe_error.try_into().map_err(|_| ())?),
359		})
360	}
361}
362
363/// Information regarding the composition of a query response.
364#[derive(Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo)]
365pub struct QueryResponseInfo {
366	/// The destination to which the query response message should be send.
367	pub destination: Location,
368	/// The `query_id` field of the `QueryResponse` message.
369	#[codec(compact)]
370	pub query_id: QueryId,
371	/// The `max_weight` field of the `QueryResponse` message.
372	pub max_weight: Weight,
373}
374
375impl TryFrom<NewQueryResponseInfo> for QueryResponseInfo {
376	type Error = ();
377
378	fn try_from(new: NewQueryResponseInfo) -> result::Result<Self, Self::Error> {
379		Ok(Self {
380			destination: new.destination.try_into()?,
381			query_id: new.query_id,
382			max_weight: new.max_weight,
383		})
384	}
385}
386
387impl TryFrom<OldQueryResponseInfo> for QueryResponseInfo {
388	type Error = ();
389
390	fn try_from(old: OldQueryResponseInfo) -> result::Result<Self, Self::Error> {
391		Ok(Self {
392			destination: old.destination.try_into()?,
393			query_id: old.query_id,
394			max_weight: old.max_weight,
395		})
396	}
397}
398
399/// Contextual data pertaining to a specific list of XCM instructions.
400#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)]
401pub struct XcmContext {
402	/// The current value of the Origin register of the `XCVM`.
403	pub origin: Option<Location>,
404	/// The identity of the XCM; this may be a hash of its versioned encoding but could also be
405	/// a high-level identity set by an appropriate barrier.
406	pub message_id: XcmHash,
407	/// The current value of the Topic register of the `XCVM`.
408	pub topic: Option<[u8; 32]>,
409}
410
411impl XcmContext {
412	/// Constructor which sets the message ID to the supplied parameter and leaves the origin and
413	/// topic unset.
414	pub fn with_message_id(message_id: XcmHash) -> XcmContext {
415		XcmContext { origin: None, message_id, topic: None }
416	}
417}
418
419/// Cross-Consensus Message: A message from one consensus system to another.
420///
421/// Consensus systems that may send and receive messages include blockchains and smart contracts.
422///
423/// All messages are delivered from a known *origin*, expressed as a `Location`.
424///
425/// This is the inner XCM format and is version-sensitive. Messages are typically passed using the
426/// outer XCM format, known as `VersionedXcm`.
427#[derive(
428	Encode,
429	Decode,
430	DecodeWithMemTracking,
431	TypeInfo,
432	xcm_procedural::XcmWeightInfoTrait,
433	xcm_procedural::Builder,
434)]
435#[derive_where(Clone, Eq, PartialEq, Debug)]
436#[codec(encode_bound())]
437#[codec(decode_bound())]
438#[codec(decode_with_mem_tracking_bound())]
439#[scale_info(bounds(), skip_type_params(Call))]
440pub enum Instruction<Call> {
441	/// Withdraw asset(s) (`assets`) from the ownership of `origin` and place them into the Holding
442	/// Register.
443	///
444	/// - `assets`: The asset(s) to be withdrawn into holding.
445	///
446	/// Kind: *Command*.
447	///
448	/// Errors:
449	#[builder(loads_holding)]
450	WithdrawAsset(Assets),
451
452	/// Asset(s) (`assets`) have been received into the ownership of this system on the `origin`
453	/// system and equivalent derivatives should be placed into the Holding Register.
454	///
455	/// - `assets`: The asset(s) that are minted into holding.
456	///
457	/// Safety: `origin` must be trusted to have received and be storing `assets` such that they
458	/// may later be withdrawn should this system send a corresponding message.
459	///
460	/// Kind: *Trusted Indication*.
461	///
462	/// Errors:
463	#[builder(loads_holding)]
464	ReserveAssetDeposited(Assets),
465
466	/// Asset(s) (`assets`) have been destroyed on the `origin` system and equivalent assets should
467	/// be created and placed into the Holding Register.
468	///
469	/// - `assets`: The asset(s) that are minted into the Holding Register.
470	///
471	/// Safety: `origin` must be trusted to have irrevocably destroyed the corresponding `assets`
472	/// prior as a consequence of sending this message.
473	///
474	/// Kind: *Trusted Indication*.
475	///
476	/// Errors:
477	#[builder(loads_holding)]
478	ReceiveTeleportedAsset(Assets),
479
480	/// Respond with information that the local system is expecting.
481	///
482	/// - `query_id`: The identifier of the query that resulted in this message being sent.
483	/// - `response`: The message content.
484	/// - `max_weight`: The maximum weight that handling this response should take.
485	/// - `querier`: The location responsible for the initiation of the response, if there is one.
486	///   In general this will tend to be the same location as the receiver of this message. NOTE:
487	///   As usual, this is interpreted from the perspective of the receiving consensus system.
488	///
489	/// Safety: Since this is information only, there are no immediate concerns. However, it should
490	/// be remembered that even if the Origin behaves reasonably, it can always be asked to make
491	/// a response to a third-party chain who may or may not be expecting the response. Therefore
492	/// the `querier` should be checked to match the expected value.
493	///
494	/// Kind: *Information*.
495	///
496	/// Errors:
497	QueryResponse {
498		#[codec(compact)]
499		query_id: QueryId,
500		response: Response,
501		max_weight: Weight,
502		querier: Option<Location>,
503	},
504
505	/// Withdraw asset(s) (`assets`) from the ownership of `origin` and place equivalent assets
506	/// under the ownership of `beneficiary`.
507	///
508	/// - `assets`: The asset(s) to be withdrawn.
509	/// - `beneficiary`: The new owner for the assets.
510	///
511	/// Safety: No concerns.
512	///
513	/// Kind: *Command*.
514	///
515	/// Errors:
516	TransferAsset { assets: Assets, beneficiary: Location },
517
518	/// Withdraw asset(s) (`assets`) from the ownership of `origin` and place equivalent assets
519	/// under the ownership of `dest` within this consensus system (i.e. its sovereign account).
520	///
521	/// Send an onward XCM message to `dest` of `ReserveAssetDeposited` with the given
522	/// `xcm`.
523	///
524	/// - `assets`: The asset(s) to be withdrawn.
525	/// - `dest`: The location whose sovereign account will own the assets and thus the effective
526	///   beneficiary for the assets and the notification target for the reserve asset deposit
527	///   message.
528	/// - `xcm`: The instructions that should follow the `ReserveAssetDeposited` instruction, which
529	///   is sent onwards to `dest`.
530	///
531	/// Safety: No concerns.
532	///
533	/// Kind: *Command*.
534	///
535	/// Errors:
536	TransferReserveAsset { assets: Assets, dest: Location, xcm: Xcm<()> },
537
538	/// Apply the encoded transaction `call`, whose dispatch-origin should be `origin` as expressed
539	/// by the kind of origin `origin_kind`.
540	///
541	/// The Transact Status Register is set according to the result of dispatching the call.
542	///
543	/// - `origin_kind`: The means of expressing the message origin as a dispatch origin.
544	/// - `require_weight_at_most`: The weight of `call`; this should be at least the chain's
545	///   calculated weight and will be used in the weight determination arithmetic.
546	/// - `call`: The encoded transaction to be applied.
547	///
548	/// Safety: No concerns.
549	///
550	/// Kind: *Command*.
551	///
552	/// Errors:
553	Transact { origin_kind: OriginKind, require_weight_at_most: Weight, call: DoubleEncoded<Call> },
554
555	/// A message to notify about a new incoming HRMP channel. This message is meant to be sent by
556	/// the relay-chain to a para.
557	///
558	/// - `sender`: The sender in the to-be opened channel. Also, the initiator of the channel
559	///   opening.
560	/// - `max_message_size`: The maximum size of a message proposed by the sender.
561	/// - `max_capacity`: The maximum number of messages that can be queued in the channel.
562	///
563	/// Safety: The message should originate directly from the relay-chain.
564	///
565	/// Kind: *System Notification*
566	HrmpNewChannelOpenRequest {
567		#[codec(compact)]
568		sender: u32,
569		#[codec(compact)]
570		max_message_size: u32,
571		#[codec(compact)]
572		max_capacity: u32,
573	},
574
575	/// A message to notify about that a previously sent open channel request has been accepted by
576	/// the recipient. That means that the channel will be opened during the next relay-chain
577	/// session change. This message is meant to be sent by the relay-chain to a para.
578	///
579	/// Safety: The message should originate directly from the relay-chain.
580	///
581	/// Kind: *System Notification*
582	///
583	/// Errors:
584	HrmpChannelAccepted {
585		// NOTE: We keep this as a structured item to a) keep it consistent with the other Hrmp
586		// items; and b) because the field's meaning is not obvious/mentioned from the item name.
587		#[codec(compact)]
588		recipient: u32,
589	},
590
591	/// A message to notify that the other party in an open channel decided to close it. In
592	/// particular, `initiator` is going to close the channel opened from `sender` to the
593	/// `recipient`. The close will be enacted at the next relay-chain session change. This message
594	/// is meant to be sent by the relay-chain to a para.
595	///
596	/// Safety: The message should originate directly from the relay-chain.
597	///
598	/// Kind: *System Notification*
599	///
600	/// Errors:
601	HrmpChannelClosing {
602		#[codec(compact)]
603		initiator: u32,
604		#[codec(compact)]
605		sender: u32,
606		#[codec(compact)]
607		recipient: u32,
608	},
609
610	/// Clear the origin.
611	///
612	/// This may be used by the XCM author to ensure that later instructions cannot command the
613	/// authority of the origin (e.g. if they are being relayed from an untrusted source, as often
614	/// the case with `ReserveAssetDeposited`).
615	///
616	/// Safety: No concerns.
617	///
618	/// Kind: *Command*.
619	///
620	/// Errors:
621	ClearOrigin,
622
623	/// Mutate the origin to some interior location.
624	///
625	/// Kind: *Command*
626	///
627	/// Errors:
628	DescendOrigin(InteriorLocation),
629
630	/// Immediately report the contents of the Error Register to the given destination via XCM.
631	///
632	/// A `QueryResponse` message of type `ExecutionOutcome` is sent to the described destination.
633	///
634	/// - `response_info`: Information for making the response.
635	///
636	/// Kind: *Command*
637	///
638	/// Errors:
639	ReportError(QueryResponseInfo),
640
641	/// Remove the asset(s) (`assets`) from the Holding Register and place equivalent assets under
642	/// the ownership of `beneficiary` within this consensus system.
643	///
644	/// - `assets`: The asset(s) to remove from holding.
645	/// - `beneficiary`: The new owner for the assets.
646	///
647	/// Kind: *Command*
648	///
649	/// Errors:
650	DepositAsset { assets: AssetFilter, beneficiary: Location },
651
652	/// Remove the asset(s) (`assets`) from the Holding Register and place equivalent assets under
653	/// the ownership of `dest` within this consensus system (i.e. deposit them into its sovereign
654	/// account).
655	///
656	/// Send an onward XCM message to `dest` of `ReserveAssetDeposited` with the given `effects`.
657	///
658	/// - `assets`: The asset(s) to remove from holding.
659	/// - `dest`: The location whose sovereign account will own the assets and thus the effective
660	///   beneficiary for the assets and the notification target for the reserve asset deposit
661	///   message.
662	/// - `xcm`: The orders that should follow the `ReserveAssetDeposited` instruction which is
663	///   sent onwards to `dest`.
664	///
665	/// Kind: *Command*
666	///
667	/// Errors:
668	DepositReserveAsset { assets: AssetFilter, dest: Location, xcm: Xcm<()> },
669
670	/// Remove the asset(s) (`want`) from the Holding Register and replace them with alternative
671	/// assets.
672	///
673	/// The minimum amount of assets to be received into the Holding Register for the order not to
674	/// fail may be stated.
675	///
676	/// - `give`: The maximum amount of assets to remove from holding.
677	/// - `want`: The minimum amount of assets which `give` should be exchanged for.
678	/// - `maximal`: If `true`, then prefer to give as much as possible up to the limit of `give`
679	///   and receive accordingly more. If `false`, then prefer to give as little as possible in
680	///   order to receive as little as possible while receiving at least `want`.
681	///
682	/// Kind: *Command*
683	///
684	/// Errors:
685	ExchangeAsset { give: AssetFilter, want: Assets, maximal: bool },
686
687	/// Remove the asset(s) (`assets`) from holding and send a `WithdrawAsset` XCM message to a
688	/// reserve location.
689	///
690	/// - `assets`: The asset(s) to remove from holding.
691	/// - `reserve`: A valid location that acts as a reserve for all asset(s) in `assets`. The
692	///   sovereign account of this consensus system *on the reserve location* will have
693	///   appropriate assets withdrawn and `effects` will be executed on them. There will typically
694	///   be only one valid location on any given asset/chain combination.
695	/// - `xcm`: The instructions to execute on the assets once withdrawn *on the reserve
696	///   location*.
697	///
698	/// Kind: *Command*
699	///
700	/// Errors:
701	InitiateReserveWithdraw { assets: AssetFilter, reserve: Location, xcm: Xcm<()> },
702
703	/// Remove the asset(s) (`assets`) from holding and send a `ReceiveTeleportedAsset` XCM message
704	/// to a `dest` location.
705	///
706	/// - `assets`: The asset(s) to remove from holding.
707	/// - `dest`: A valid location that respects teleports coming from this location.
708	/// - `xcm`: The instructions to execute on the assets once arrived *on the destination
709	///   location*.
710	///
711	/// NOTE: The `dest` location *MUST* respect this origin as a valid teleportation origin for
712	/// all `assets`. If it does not, then the assets may be lost.
713	///
714	/// Kind: *Command*
715	///
716	/// Errors:
717	InitiateTeleport { assets: AssetFilter, dest: Location, xcm: Xcm<()> },
718
719	/// Report to a given destination the contents of the Holding Register.
720	///
721	/// A `QueryResponse` message of type `Assets` is sent to the described destination.
722	///
723	/// - `response_info`: Information for making the response.
724	/// - `assets`: A filter for the assets that should be reported back. The assets reported back
725	///   will be, asset-wise, *the lesser of this value and the holding register*. No wildcards
726	///   will be used when reporting assets back.
727	///
728	/// Kind: *Command*
729	///
730	/// Errors:
731	ReportHolding { response_info: QueryResponseInfo, assets: AssetFilter },
732
733	/// Pay for the execution of some XCM `xcm` and `orders` with up to `weight`
734	/// picoseconds of execution time, paying for this with up to `fees` from the Holding Register.
735	///
736	/// - `fees`: The asset(s) to remove from the Holding Register to pay for fees.
737	/// - `weight_limit`: The maximum amount of weight to purchase; this must be at least the
738	///   expected maximum weight of the total XCM to be executed for the
739	///   `AllowTopLevelPaidExecutionFrom` barrier to allow the XCM be executed.
740	///
741	/// Kind: *Command*
742	///
743	/// Errors:
744	#[builder(pays_fees)]
745	BuyExecution { fees: Asset, weight_limit: WeightLimit },
746
747	/// Refund any surplus weight previously bought with `BuyExecution`.
748	///
749	/// Kind: *Command*
750	///
751	/// Errors: None.
752	RefundSurplus,
753
754	/// Set the Error Handler Register. This is code that should be called in the case of an error
755	/// happening.
756	///
757	/// An error occurring within execution of this code will _NOT_ result in the error register
758	/// being set, nor will an error handler be called due to it. The error handler and appendix
759	/// may each still be set.
760	///
761	/// The apparent weight of this instruction is inclusive of the inner `Xcm`; the executing
762	/// weight however includes only the difference between the previous handler and the new
763	/// handler, which can reasonably be negative, which would result in a surplus.
764	///
765	/// Kind: *Command*
766	///
767	/// Errors: None.
768	SetErrorHandler(Xcm<Call>),
769
770	/// Set the Appendix Register. This is code that should be called after code execution
771	/// (including the error handler if any) is finished. This will be called regardless of whether
772	/// an error occurred.
773	///
774	/// Any error occurring due to execution of this code will result in the error register being
775	/// set, and the error handler (if set) firing.
776	///
777	/// The apparent weight of this instruction is inclusive of the inner `Xcm`; the executing
778	/// weight however includes only the difference between the previous appendix and the new
779	/// appendix, which can reasonably be negative, which would result in a surplus.
780	///
781	/// Kind: *Command*
782	///
783	/// Errors: None.
784	SetAppendix(Xcm<Call>),
785
786	/// Clear the Error Register.
787	///
788	/// Kind: *Command*
789	///
790	/// Errors: None.
791	ClearError,
792
793	/// Create some assets which are being held on behalf of the origin.
794	///
795	/// - `assets`: The assets which are to be claimed. This must match exactly with the assets
796	///   claimable by the origin of the ticket.
797	/// - `ticket`: The ticket of the asset; this is an abstract identifier to help locate the
798	///   asset.
799	///
800	/// Kind: *Command*
801	///
802	/// Errors:
803	#[builder(loads_holding)]
804	ClaimAsset { assets: Assets, ticket: Location },
805
806	/// Always throws an error of type `Trap`.
807	///
808	/// Kind: *Command*
809	///
810	/// Errors:
811	/// - `Trap`: All circumstances, whose inner value is the same as this item's inner value.
812	Trap(#[codec(compact)] u64),
813
814	/// Ask the destination system to respond with the most recent version of XCM that they
815	/// support in a `QueryResponse` instruction. Any changes to this should also elicit similar
816	/// responses when they happen.
817	///
818	/// - `query_id`: An identifier that will be replicated into the returned XCM message.
819	/// - `max_response_weight`: The maximum amount of weight that the `QueryResponse` item which
820	///   is sent as a reply may take to execute. NOTE: If this is unexpectedly large then the
821	///   response may not execute at all.
822	///
823	/// Kind: *Command*
824	///
825	/// Errors: *Fallible*
826	SubscribeVersion {
827		#[codec(compact)]
828		query_id: QueryId,
829		max_response_weight: Weight,
830	},
831
832	/// Cancel the effect of a previous `SubscribeVersion` instruction.
833	///
834	/// Kind: *Command*
835	///
836	/// Errors: *Fallible*
837	UnsubscribeVersion,
838
839	/// Reduce Holding by up to the given assets.
840	///
841	/// Holding is reduced by as much as possible up to the assets in the parameter. It is not an
842	/// error if the Holding does not contain the assets (to make this an error, use `ExpectAsset`
843	/// prior).
844	///
845	/// Kind: *Command*
846	///
847	/// Errors: *Infallible*
848	BurnAsset(Assets),
849
850	/// Throw an error if Holding does not contain at least the given assets.
851	///
852	/// Kind: *Command*
853	///
854	/// Errors:
855	/// - `ExpectationFalse`: If Holding Register does not contain the assets in the parameter.
856	ExpectAsset(Assets),
857
858	/// Ensure that the Origin Register equals some given value and throw an error if not.
859	///
860	/// Kind: *Command*
861	///
862	/// Errors:
863	/// - `ExpectationFalse`: If Origin Register is not equal to the parameter.
864	ExpectOrigin(Option<Location>),
865
866	/// Ensure that the Error Register equals some given value and throw an error if not.
867	///
868	/// Kind: *Command*
869	///
870	/// Errors:
871	/// - `ExpectationFalse`: If the value of the Error Register is not equal to the parameter.
872	ExpectError(Option<(u32, Error)>),
873
874	/// Ensure that the Transact Status Register equals some given value and throw an error if
875	/// not.
876	///
877	/// Kind: *Command*
878	///
879	/// Errors:
880	/// - `ExpectationFalse`: If the value of the Transact Status Register is not equal to the
881	///   parameter.
882	ExpectTransactStatus(MaybeErrorCode),
883
884	/// Query the existence of a particular pallet type.
885	///
886	/// - `module_name`: The module name of the pallet to query.
887	/// - `response_info`: Information for making the response.
888	///
889	/// Sends a `QueryResponse` to Origin whose data field `PalletsInfo` containing the information
890	/// of all pallets on the local chain whose name is equal to `name`. This is empty in the case
891	/// that the local chain is not based on Substrate Frame.
892	///
893	/// Safety: No concerns.
894	///
895	/// Kind: *Command*
896	///
897	/// Errors: *Fallible*.
898	QueryPallet { module_name: Vec<u8>, response_info: QueryResponseInfo },
899
900	/// Ensure that a particular pallet with a particular version exists.
901	///
902	/// - `index: Compact`: The index which identifies the pallet. An error if no pallet exists at
903	///   this index.
904	/// - `name: Vec<u8>`: Name which must be equal to the name of the pallet.
905	/// - `module_name: Vec<u8>`: Module name which must be equal to the name of the module in
906	///   which the pallet exists.
907	/// - `crate_major: Compact`: Version number which must be equal to the major version of the
908	///   crate which implements the pallet.
909	/// - `min_crate_minor: Compact`: Version number which must be at most the minor version of the
910	///   crate which implements the pallet.
911	///
912	/// Safety: No concerns.
913	///
914	/// Kind: *Command*
915	///
916	/// Errors:
917	/// - `ExpectationFalse`: In case any of the expectations are broken.
918	ExpectPallet {
919		#[codec(compact)]
920		index: u32,
921		name: Vec<u8>,
922		module_name: Vec<u8>,
923		#[codec(compact)]
924		crate_major: u32,
925		#[codec(compact)]
926		min_crate_minor: u32,
927	},
928
929	/// Send a `QueryResponse` message containing the value of the Transact Status Register to some
930	/// destination.
931	///
932	/// - `query_response_info`: The information needed for constructing and sending the
933	///   `QueryResponse` message.
934	///
935	/// Safety: No concerns.
936	///
937	/// Kind: *Command*
938	///
939	/// Errors: *Fallible*.
940	ReportTransactStatus(QueryResponseInfo),
941
942	/// Set the Transact Status Register to its default, cleared, value.
943	///
944	/// Safety: No concerns.
945	///
946	/// Kind: *Command*
947	///
948	/// Errors: *Infallible*.
949	ClearTransactStatus,
950
951	/// Set the Origin Register to be some child of the Universal Ancestor.
952	///
953	/// Safety: Should only be usable if the Origin is trusted to represent the Universal Ancestor
954	/// child in general. In general, no Origin should be able to represent the Universal Ancestor
955	/// child which is the root of the local consensus system since it would by extension
956	/// allow it to act as any location within the local consensus.
957	///
958	/// The `Junction` parameter should generally be a `GlobalConsensus` variant since it is only
959	/// these which are children of the Universal Ancestor.
960	///
961	/// Kind: *Command*
962	///
963	/// Errors: *Fallible*.
964	UniversalOrigin(Junction),
965
966	/// Send a message on to Non-Local Consensus system.
967	///
968	/// This will tend to utilize some extra-consensus mechanism, the obvious one being a bridge.
969	/// A fee may be charged; this may be determined based on the contents of `xcm`. It will be
970	/// taken from the Holding register.
971	///
972	/// - `network`: The remote consensus system to which the message should be exported.
973	/// - `destination`: The location relative to the remote consensus system to which the message
974	///   should be sent on arrival.
975	/// - `xcm`: The message to be exported.
976	///
977	/// As an example, to export a message for execution on Statemine (parachain #1000 in the
978	/// Kusama network), you would call with `network: NetworkId::Kusama` and
979	/// `destination: [Parachain(1000)].into()`. Alternatively, to export a message for execution
980	/// on Polkadot, you would call with `network: NetworkId:: Polkadot` and `destination: Here`.
981	///
982	/// Kind: *Command*
983	///
984	/// Errors: *Fallible*.
985	ExportMessage { network: NetworkId, destination: InteriorLocation, xcm: Xcm<()> },
986
987	/// Lock the locally held asset and prevent further transfer or withdrawal.
988	///
989	/// This restriction may be removed by the `UnlockAsset` instruction being called with an
990	/// Origin of `unlocker` and a `target` equal to the current `Origin`.
991	///
992	/// If the locking is successful, then a `NoteUnlockable` instruction is sent to `unlocker`.
993	///
994	/// - `asset`: The asset(s) which should be locked.
995	/// - `unlocker`: The value which the Origin must be for a corresponding `UnlockAsset`
996	///   instruction to work.
997	///
998	/// Kind: *Command*.
999	///
1000	/// Errors:
1001	LockAsset { asset: Asset, unlocker: Location },
1002
1003	/// Remove the lock over `asset` on this chain and (if nothing else is preventing it) allow the
1004	/// asset to be transferred.
1005	///
1006	/// - `asset`: The asset to be unlocked.
1007	/// - `target`: The owner of the asset on the local chain.
1008	///
1009	/// Safety: No concerns.
1010	///
1011	/// Kind: *Command*.
1012	///
1013	/// Errors:
1014	UnlockAsset { asset: Asset, target: Location },
1015
1016	/// Asset (`asset`) has been locked on the `origin` system and may not be transferred. It may
1017	/// only be unlocked with the receipt of the `UnlockAsset` instruction from this chain.
1018	///
1019	/// - `asset`: The asset(s) which are now unlockable from this origin.
1020	/// - `owner`: The owner of the asset on the chain in which it was locked. This may be a
1021	///   location specific to the origin network.
1022	///
1023	/// Safety: `origin` must be trusted to have locked the corresponding `asset`
1024	/// prior as a consequence of sending this message.
1025	///
1026	/// Kind: *Trusted Indication*.
1027	///
1028	/// Errors:
1029	NoteUnlockable { asset: Asset, owner: Location },
1030
1031	/// Send an `UnlockAsset` instruction to the `locker` for the given `asset`.
1032	///
1033	/// This may fail if the local system is making use of the fact that the asset is locked or,
1034	/// of course, if there is no record that the asset actually is locked.
1035	///
1036	/// - `asset`: The asset(s) to be unlocked.
1037	/// - `locker`: The location from which a previous `NoteUnlockable` was sent and to which an
1038	///   `UnlockAsset` should be sent.
1039	///
1040	/// Kind: *Command*.
1041	///
1042	/// Errors:
1043	RequestUnlock { asset: Asset, locker: Location },
1044
1045	/// Sets the Fees Mode Register.
1046	///
1047	/// - `jit_withdraw`: The fees mode item; if set to `true` then fees for any instructions are
1048	///   withdrawn as needed using the same mechanism as `WithdrawAssets`.
1049	///
1050	/// Kind: *Command*.
1051	///
1052	/// Errors:
1053	SetFeesMode { jit_withdraw: bool },
1054
1055	/// Set the Topic Register.
1056	///
1057	/// The 32-byte array identifier in the parameter is not guaranteed to be
1058	/// unique; if such a property is desired, it is up to the code author to
1059	/// enforce uniqueness.
1060	///
1061	/// Safety: No concerns.
1062	///
1063	/// Kind: *Command*
1064	///
1065	/// Errors:
1066	SetTopic([u8; 32]),
1067
1068	/// Clear the Topic Register.
1069	///
1070	/// Kind: *Command*
1071	///
1072	/// Errors: None.
1073	ClearTopic,
1074
1075	/// Alter the current Origin to another given origin.
1076	///
1077	/// Kind: *Command*
1078	///
1079	/// Errors: If the existing state would not allow such a change.
1080	AliasOrigin(Location),
1081
1082	/// A directive to indicate that the origin expects free execution of the message.
1083	///
1084	/// At execution time, this instruction just does a check on the Origin register.
1085	/// However, at the barrier stage messages starting with this instruction can be disregarded if
1086	/// the origin is not acceptable for free execution or the `weight_limit` is `Limited` and
1087	/// insufficient.
1088	///
1089	/// Kind: *Indication*
1090	///
1091	/// Errors: If the given origin is `Some` and not equal to the current Origin register.
1092	UnpaidExecution { weight_limit: WeightLimit, check_origin: Option<Location> },
1093}
1094
1095impl<Call> Xcm<Call> {
1096	pub fn into<C>(self) -> Xcm<C> {
1097		Xcm::from(self)
1098	}
1099	pub fn from<C>(xcm: Xcm<C>) -> Self {
1100		Self(xcm.0.into_iter().map(Instruction::<Call>::from).collect())
1101	}
1102}
1103
1104impl<Call> Instruction<Call> {
1105	pub fn into<C>(self) -> Instruction<C> {
1106		Instruction::from(self)
1107	}
1108	pub fn from<C>(xcm: Instruction<C>) -> Self {
1109		use Instruction::*;
1110		match xcm {
1111			WithdrawAsset(assets) => WithdrawAsset(assets),
1112			ReserveAssetDeposited(assets) => ReserveAssetDeposited(assets),
1113			ReceiveTeleportedAsset(assets) => ReceiveTeleportedAsset(assets),
1114			QueryResponse { query_id, response, max_weight, querier } =>
1115				QueryResponse { query_id, response, max_weight, querier },
1116			TransferAsset { assets, beneficiary } => TransferAsset { assets, beneficiary },
1117			TransferReserveAsset { assets, dest, xcm } =>
1118				TransferReserveAsset { assets, dest, xcm },
1119			HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } =>
1120				HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity },
1121			HrmpChannelAccepted { recipient } => HrmpChannelAccepted { recipient },
1122			HrmpChannelClosing { initiator, sender, recipient } =>
1123				HrmpChannelClosing { initiator, sender, recipient },
1124			Transact { origin_kind, require_weight_at_most, call } =>
1125				Transact { origin_kind, require_weight_at_most, call: call.into() },
1126			ReportError(response_info) => ReportError(response_info),
1127			DepositAsset { assets, beneficiary } => DepositAsset { assets, beneficiary },
1128			DepositReserveAsset { assets, dest, xcm } => DepositReserveAsset { assets, dest, xcm },
1129			ExchangeAsset { give, want, maximal } => ExchangeAsset { give, want, maximal },
1130			InitiateReserveWithdraw { assets, reserve, xcm } =>
1131				InitiateReserveWithdraw { assets, reserve, xcm },
1132			InitiateTeleport { assets, dest, xcm } => InitiateTeleport { assets, dest, xcm },
1133			ReportHolding { response_info, assets } => ReportHolding { response_info, assets },
1134			BuyExecution { fees, weight_limit } => BuyExecution { fees, weight_limit },
1135			ClearOrigin => ClearOrigin,
1136			DescendOrigin(who) => DescendOrigin(who),
1137			RefundSurplus => RefundSurplus,
1138			SetErrorHandler(xcm) => SetErrorHandler(xcm.into()),
1139			SetAppendix(xcm) => SetAppendix(xcm.into()),
1140			ClearError => ClearError,
1141			ClaimAsset { assets, ticket } => ClaimAsset { assets, ticket },
1142			Trap(code) => Trap(code),
1143			SubscribeVersion { query_id, max_response_weight } =>
1144				SubscribeVersion { query_id, max_response_weight },
1145			UnsubscribeVersion => UnsubscribeVersion,
1146			BurnAsset(assets) => BurnAsset(assets),
1147			ExpectAsset(assets) => ExpectAsset(assets),
1148			ExpectOrigin(origin) => ExpectOrigin(origin),
1149			ExpectError(error) => ExpectError(error),
1150			ExpectTransactStatus(transact_status) => ExpectTransactStatus(transact_status),
1151			QueryPallet { module_name, response_info } =>
1152				QueryPallet { module_name, response_info },
1153			ExpectPallet { index, name, module_name, crate_major, min_crate_minor } =>
1154				ExpectPallet { index, name, module_name, crate_major, min_crate_minor },
1155			ReportTransactStatus(response_info) => ReportTransactStatus(response_info),
1156			ClearTransactStatus => ClearTransactStatus,
1157			UniversalOrigin(j) => UniversalOrigin(j),
1158			ExportMessage { network, destination, xcm } =>
1159				ExportMessage { network, destination, xcm },
1160			LockAsset { asset, unlocker } => LockAsset { asset, unlocker },
1161			UnlockAsset { asset, target } => UnlockAsset { asset, target },
1162			NoteUnlockable { asset, owner } => NoteUnlockable { asset, owner },
1163			RequestUnlock { asset, locker } => RequestUnlock { asset, locker },
1164			SetFeesMode { jit_withdraw } => SetFeesMode { jit_withdraw },
1165			SetTopic(topic) => SetTopic(topic),
1166			ClearTopic => ClearTopic,
1167			AliasOrigin(location) => AliasOrigin(location),
1168			UnpaidExecution { weight_limit, check_origin } =>
1169				UnpaidExecution { weight_limit, check_origin },
1170		}
1171	}
1172}
1173
1174// TODO: Automate Generation
1175impl<Call, W: XcmWeightInfo<Call>> GetWeight<W> for Instruction<Call> {
1176	fn weight(&self) -> Weight {
1177		use Instruction::*;
1178		match self {
1179			WithdrawAsset(assets) => W::withdraw_asset(assets),
1180			ReserveAssetDeposited(assets) => W::reserve_asset_deposited(assets),
1181			ReceiveTeleportedAsset(assets) => W::receive_teleported_asset(assets),
1182			QueryResponse { query_id, response, max_weight, querier } =>
1183				W::query_response(query_id, response, max_weight, querier),
1184			TransferAsset { assets, beneficiary } => W::transfer_asset(assets, beneficiary),
1185			TransferReserveAsset { assets, dest, xcm } =>
1186				W::transfer_reserve_asset(&assets, dest, xcm),
1187			Transact { origin_kind, require_weight_at_most, call } =>
1188				W::transact(origin_kind, require_weight_at_most, call),
1189			HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } =>
1190				W::hrmp_new_channel_open_request(sender, max_message_size, max_capacity),
1191			HrmpChannelAccepted { recipient } => W::hrmp_channel_accepted(recipient),
1192			HrmpChannelClosing { initiator, sender, recipient } =>
1193				W::hrmp_channel_closing(initiator, sender, recipient),
1194			ClearOrigin => W::clear_origin(),
1195			DescendOrigin(who) => W::descend_origin(who),
1196			ReportError(response_info) => W::report_error(&response_info),
1197			DepositAsset { assets, beneficiary } => W::deposit_asset(assets, beneficiary),
1198			DepositReserveAsset { assets, dest, xcm } =>
1199				W::deposit_reserve_asset(assets, dest, xcm),
1200			ExchangeAsset { give, want, maximal } => W::exchange_asset(give, want, maximal),
1201			InitiateReserveWithdraw { assets, reserve, xcm } =>
1202				W::initiate_reserve_withdraw(assets, reserve, xcm),
1203			InitiateTeleport { assets, dest, xcm } => W::initiate_teleport(assets, dest, xcm),
1204			ReportHolding { response_info, assets } => W::report_holding(&response_info, &assets),
1205			BuyExecution { fees, weight_limit } => W::buy_execution(fees, weight_limit),
1206			RefundSurplus => W::refund_surplus(),
1207			SetErrorHandler(xcm) => W::set_error_handler(xcm),
1208			SetAppendix(xcm) => W::set_appendix(xcm),
1209			ClearError => W::clear_error(),
1210			ClaimAsset { assets, ticket } => W::claim_asset(assets, ticket),
1211			Trap(code) => W::trap(code),
1212			SubscribeVersion { query_id, max_response_weight } =>
1213				W::subscribe_version(query_id, max_response_weight),
1214			UnsubscribeVersion => W::unsubscribe_version(),
1215			BurnAsset(assets) => W::burn_asset(assets),
1216			ExpectAsset(assets) => W::expect_asset(assets),
1217			ExpectOrigin(origin) => W::expect_origin(origin),
1218			ExpectError(error) => W::expect_error(error),
1219			ExpectTransactStatus(transact_status) => W::expect_transact_status(transact_status),
1220			QueryPallet { module_name, response_info } =>
1221				W::query_pallet(module_name, response_info),
1222			ExpectPallet { index, name, module_name, crate_major, min_crate_minor } =>
1223				W::expect_pallet(index, name, module_name, crate_major, min_crate_minor),
1224			ReportTransactStatus(response_info) => W::report_transact_status(response_info),
1225			ClearTransactStatus => W::clear_transact_status(),
1226			UniversalOrigin(j) => W::universal_origin(j),
1227			ExportMessage { network, destination, xcm } =>
1228				W::export_message(network, destination, xcm),
1229			LockAsset { asset, unlocker } => W::lock_asset(asset, unlocker),
1230			UnlockAsset { asset, target } => W::unlock_asset(asset, target),
1231			NoteUnlockable { asset, owner } => W::note_unlockable(asset, owner),
1232			RequestUnlock { asset, locker } => W::request_unlock(asset, locker),
1233			SetFeesMode { jit_withdraw } => W::set_fees_mode(jit_withdraw),
1234			SetTopic(topic) => W::set_topic(topic),
1235			ClearTopic => W::clear_topic(),
1236			AliasOrigin(location) => W::alias_origin(location),
1237			UnpaidExecution { weight_limit, check_origin } =>
1238				W::unpaid_execution(weight_limit, check_origin),
1239		}
1240	}
1241}
1242
1243pub mod opaque {
1244	/// The basic concrete type of `Xcm`, which doesn't make any assumptions about the
1245	/// format of a call other than it is pre-encoded.
1246	pub type Xcm = super::Xcm<()>;
1247
1248	/// The basic concrete type of `Instruction`, which doesn't make any assumptions about the
1249	/// format of a call other than it is pre-encoded.
1250	pub type Instruction = super::Instruction<()>;
1251}
1252
1253// Convert from a v3 XCM to a v4 XCM
1254impl<Call> TryFrom<OldXcm<Call>> for Xcm<Call> {
1255	type Error = ();
1256	fn try_from(old_xcm: OldXcm<Call>) -> result::Result<Self, Self::Error> {
1257		Ok(Xcm(old_xcm.0.into_iter().map(TryInto::try_into).collect::<result::Result<_, _>>()?))
1258	}
1259}
1260
1261// Convert from a v5 XCM to a v4 XCM.
1262impl<Call: Decode + GetDispatchInfo> TryFrom<NewXcm<Call>> for Xcm<Call> {
1263	type Error = ();
1264	fn try_from(new_xcm: NewXcm<Call>) -> result::Result<Self, Self::Error> {
1265		Ok(Xcm(new_xcm.0.into_iter().map(TryInto::try_into).collect::<result::Result<_, _>>()?))
1266	}
1267}
1268
1269// Convert from a v5 instruction to a v4 instruction.
1270impl<Call: Decode + GetDispatchInfo> TryFrom<NewInstruction<Call>> for Instruction<Call> {
1271	type Error = ();
1272	fn try_from(new_instruction: NewInstruction<Call>) -> result::Result<Self, Self::Error> {
1273		use NewInstruction::*;
1274		Ok(match new_instruction {
1275			WithdrawAsset(assets) => Self::WithdrawAsset(assets.try_into()?),
1276			ReserveAssetDeposited(assets) => Self::ReserveAssetDeposited(assets.try_into()?),
1277			ReceiveTeleportedAsset(assets) => Self::ReceiveTeleportedAsset(assets.try_into()?),
1278			QueryResponse { query_id, response, max_weight, querier: Some(querier) } =>
1279				Self::QueryResponse {
1280					query_id,
1281					querier: querier.try_into()?,
1282					response: response.try_into()?,
1283					max_weight,
1284				},
1285			QueryResponse { query_id, response, max_weight, querier: None } =>
1286				Self::QueryResponse {
1287					query_id,
1288					querier: None,
1289					response: response.try_into()?,
1290					max_weight,
1291				},
1292			TransferAsset { assets, beneficiary } => Self::TransferAsset {
1293				assets: assets.try_into()?,
1294				beneficiary: beneficiary.try_into()?,
1295			},
1296			TransferReserveAsset { assets, dest, xcm } => Self::TransferReserveAsset {
1297				assets: assets.try_into()?,
1298				dest: dest.try_into()?,
1299				xcm: xcm.try_into()?,
1300			},
1301			HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } =>
1302				Self::HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity },
1303			HrmpChannelAccepted { recipient } => Self::HrmpChannelAccepted { recipient },
1304			HrmpChannelClosing { initiator, sender, recipient } =>
1305				Self::HrmpChannelClosing { initiator, sender, recipient },
1306			Transact { origin_kind, mut call, fallback_max_weight } => {
1307				// We first try to decode the call, if we can't, we use the fallback weight,
1308				// if there's no fallback, we just return `Weight::MAX`.
1309				let require_weight_at_most = match call.take_decoded() {
1310					Ok(decoded) => decoded.get_dispatch_info().call_weight,
1311					Err(error) => {
1312						let fallback_weight = fallback_max_weight.unwrap_or(Weight::MAX);
1313						tracing::debug!(
1314							target: "xcm::versions::v5Tov4",
1315							?error,
1316							?fallback_weight,
1317							"Couldn't decode call in Transact"
1318						);
1319						fallback_weight
1320					},
1321				};
1322				Self::Transact { origin_kind, require_weight_at_most, call: call.into() }
1323			},
1324			ReportError(response_info) => Self::ReportError(QueryResponseInfo {
1325				query_id: response_info.query_id,
1326				destination: response_info.destination.try_into().map_err(|_| ())?,
1327				max_weight: response_info.max_weight,
1328			}),
1329			DepositAsset { assets, beneficiary } => {
1330				let beneficiary = beneficiary.try_into()?;
1331				let assets = assets.try_into()?;
1332				Self::DepositAsset { assets, beneficiary }
1333			},
1334			DepositReserveAsset { assets, dest, xcm } => {
1335				let dest = dest.try_into()?;
1336				let xcm = xcm.try_into()?;
1337				let assets = assets.try_into()?;
1338				Self::DepositReserveAsset { assets, dest, xcm }
1339			},
1340			ExchangeAsset { give, want, maximal } => {
1341				let give = give.try_into()?;
1342				let want = want.try_into()?;
1343				Self::ExchangeAsset { give, want, maximal }
1344			},
1345			InitiateReserveWithdraw { assets, reserve, xcm } => {
1346				// No `max_assets` here, so if there's a connt, then we cannot translate.
1347				let assets = assets.try_into()?;
1348				let reserve = reserve.try_into()?;
1349				let xcm = xcm.try_into()?;
1350				Self::InitiateReserveWithdraw { assets, reserve, xcm }
1351			},
1352			InitiateTeleport { assets, dest, xcm } => {
1353				// No `max_assets` here, so if there's a connt, then we cannot translate.
1354				let assets = assets.try_into()?;
1355				let dest = dest.try_into()?;
1356				let xcm = xcm.try_into()?;
1357				Self::InitiateTeleport { assets, dest, xcm }
1358			},
1359			ReportHolding { response_info, assets } => {
1360				let response_info = QueryResponseInfo {
1361					destination: response_info.destination.try_into().map_err(|_| ())?,
1362					query_id: response_info.query_id,
1363					max_weight: response_info.max_weight,
1364				};
1365				Self::ReportHolding { response_info, assets: assets.try_into()? }
1366			},
1367			BuyExecution { fees, weight_limit } => {
1368				let fees = fees.try_into()?;
1369				let weight_limit = weight_limit.into();
1370				Self::BuyExecution { fees, weight_limit }
1371			},
1372			ClearOrigin => Self::ClearOrigin,
1373			DescendOrigin(who) => Self::DescendOrigin(who.try_into()?),
1374			RefundSurplus => Self::RefundSurplus,
1375			SetErrorHandler(xcm) => Self::SetErrorHandler(xcm.try_into()?),
1376			SetAppendix(xcm) => Self::SetAppendix(xcm.try_into()?),
1377			ClearError => Self::ClearError,
1378			ClaimAsset { assets, ticket } => {
1379				let assets = assets.try_into()?;
1380				let ticket = ticket.try_into()?;
1381				Self::ClaimAsset { assets, ticket }
1382			},
1383			Trap(code) => Self::Trap(code),
1384			SubscribeVersion { query_id, max_response_weight } =>
1385				Self::SubscribeVersion { query_id, max_response_weight },
1386			UnsubscribeVersion => Self::UnsubscribeVersion,
1387			BurnAsset(assets) => Self::BurnAsset(assets.try_into()?),
1388			ExpectAsset(assets) => Self::ExpectAsset(assets.try_into()?),
1389			ExpectOrigin(maybe_origin) =>
1390				Self::ExpectOrigin(maybe_origin.map(|origin| origin.try_into()).transpose()?),
1391			ExpectError(maybe_error) => Self::ExpectError(
1392				maybe_error
1393					.map(|(num, new_error)| (num, new_error.try_into()))
1394					.map(|(num, result)| result.map(|inner| (num, inner)))
1395					.transpose()?,
1396			),
1397			ExpectTransactStatus(maybe_error_code) => Self::ExpectTransactStatus(maybe_error_code),
1398			QueryPallet { module_name, response_info } =>
1399				Self::QueryPallet { module_name, response_info: response_info.try_into()? },
1400			ExpectPallet { index, name, module_name, crate_major, min_crate_minor } =>
1401				Self::ExpectPallet { index, name, module_name, crate_major, min_crate_minor },
1402			ReportTransactStatus(response_info) =>
1403				Self::ReportTransactStatus(response_info.try_into()?),
1404			ClearTransactStatus => Self::ClearTransactStatus,
1405			UniversalOrigin(junction) => Self::UniversalOrigin(junction.try_into()?),
1406			ExportMessage { network, destination, xcm } => Self::ExportMessage {
1407				network: network.into(),
1408				destination: destination.try_into()?,
1409				xcm: xcm.try_into()?,
1410			},
1411			LockAsset { asset, unlocker } =>
1412				Self::LockAsset { asset: asset.try_into()?, unlocker: unlocker.try_into()? },
1413			UnlockAsset { asset, target } =>
1414				Self::UnlockAsset { asset: asset.try_into()?, target: target.try_into()? },
1415			NoteUnlockable { asset, owner } =>
1416				Self::NoteUnlockable { asset: asset.try_into()?, owner: owner.try_into()? },
1417			RequestUnlock { asset, locker } =>
1418				Self::RequestUnlock { asset: asset.try_into()?, locker: locker.try_into()? },
1419			SetFeesMode { jit_withdraw } => Self::SetFeesMode { jit_withdraw },
1420			SetTopic(topic) => Self::SetTopic(topic),
1421			ClearTopic => Self::ClearTopic,
1422			AliasOrigin(location) => Self::AliasOrigin(location.try_into()?),
1423			UnpaidExecution { weight_limit, check_origin } => Self::UnpaidExecution {
1424				weight_limit,
1425				check_origin: check_origin.map(|origin| origin.try_into()).transpose()?,
1426			},
1427			InitiateTransfer { .. } |
1428			PayFees { .. } |
1429			SetHints { .. } |
1430			ExecuteWithOrigin { .. } => {
1431				tracing::debug!(target: "xcm::versions::v5tov4", ?new_instruction, "not supported by v4");
1432				return Err(());
1433			},
1434		})
1435	}
1436}
1437
1438// Convert from a v3 instruction to a v4 instruction
1439impl<Call> TryFrom<OldInstruction<Call>> for Instruction<Call> {
1440	type Error = ();
1441	fn try_from(old_instruction: OldInstruction<Call>) -> result::Result<Self, Self::Error> {
1442		use OldInstruction::*;
1443		Ok(match old_instruction {
1444			WithdrawAsset(assets) => Self::WithdrawAsset(assets.try_into()?),
1445			ReserveAssetDeposited(assets) => Self::ReserveAssetDeposited(assets.try_into()?),
1446			ReceiveTeleportedAsset(assets) => Self::ReceiveTeleportedAsset(assets.try_into()?),
1447			QueryResponse { query_id, response, max_weight, querier: Some(querier) } =>
1448				Self::QueryResponse {
1449					query_id,
1450					querier: querier.try_into()?,
1451					response: response.try_into()?,
1452					max_weight,
1453				},
1454			QueryResponse { query_id, response, max_weight, querier: None } =>
1455				Self::QueryResponse {
1456					query_id,
1457					querier: None,
1458					response: response.try_into()?,
1459					max_weight,
1460				},
1461			TransferAsset { assets, beneficiary } => Self::TransferAsset {
1462				assets: assets.try_into()?,
1463				beneficiary: beneficiary.try_into()?,
1464			},
1465			TransferReserveAsset { assets, dest, xcm } => Self::TransferReserveAsset {
1466				assets: assets.try_into()?,
1467				dest: dest.try_into()?,
1468				xcm: xcm.try_into()?,
1469			},
1470			HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } =>
1471				Self::HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity },
1472			HrmpChannelAccepted { recipient } => Self::HrmpChannelAccepted { recipient },
1473			HrmpChannelClosing { initiator, sender, recipient } =>
1474				Self::HrmpChannelClosing { initiator, sender, recipient },
1475			Transact { origin_kind, require_weight_at_most, call } =>
1476				Self::Transact { origin_kind, require_weight_at_most, call: call.into() },
1477			ReportError(response_info) => Self::ReportError(QueryResponseInfo {
1478				query_id: response_info.query_id,
1479				destination: response_info.destination.try_into().map_err(|_| ())?,
1480				max_weight: response_info.max_weight,
1481			}),
1482			DepositAsset { assets, beneficiary } => {
1483				let beneficiary = beneficiary.try_into()?;
1484				let assets = assets.try_into()?;
1485				Self::DepositAsset { assets, beneficiary }
1486			},
1487			DepositReserveAsset { assets, dest, xcm } => {
1488				let dest = dest.try_into()?;
1489				let xcm = xcm.try_into()?;
1490				let assets = assets.try_into()?;
1491				Self::DepositReserveAsset { assets, dest, xcm }
1492			},
1493			ExchangeAsset { give, want, maximal } => {
1494				let give = give.try_into()?;
1495				let want = want.try_into()?;
1496				Self::ExchangeAsset { give, want, maximal }
1497			},
1498			InitiateReserveWithdraw { assets, reserve, xcm } => {
1499				let assets = assets.try_into()?;
1500				let reserve = reserve.try_into()?;
1501				let xcm = xcm.try_into()?;
1502				Self::InitiateReserveWithdraw { assets, reserve, xcm }
1503			},
1504			InitiateTeleport { assets, dest, xcm } => {
1505				let assets = assets.try_into()?;
1506				let dest = dest.try_into()?;
1507				let xcm = xcm.try_into()?;
1508				Self::InitiateTeleport { assets, dest, xcm }
1509			},
1510			ReportHolding { response_info, assets } => {
1511				let response_info = QueryResponseInfo {
1512					destination: response_info.destination.try_into().map_err(|_| ())?,
1513					query_id: response_info.query_id,
1514					max_weight: response_info.max_weight,
1515				};
1516				Self::ReportHolding { response_info, assets: assets.try_into()? }
1517			},
1518			BuyExecution { fees, weight_limit } => {
1519				let fees = fees.try_into()?;
1520				let weight_limit = weight_limit.into();
1521				Self::BuyExecution { fees, weight_limit }
1522			},
1523			ClearOrigin => Self::ClearOrigin,
1524			DescendOrigin(who) => Self::DescendOrigin(who.try_into()?),
1525			RefundSurplus => Self::RefundSurplus,
1526			SetErrorHandler(xcm) => Self::SetErrorHandler(xcm.try_into()?),
1527			SetAppendix(xcm) => Self::SetAppendix(xcm.try_into()?),
1528			ClearError => Self::ClearError,
1529			ClaimAsset { assets, ticket } => {
1530				let assets = assets.try_into()?;
1531				let ticket = ticket.try_into()?;
1532				Self::ClaimAsset { assets, ticket }
1533			},
1534			Trap(code) => Self::Trap(code),
1535			SubscribeVersion { query_id, max_response_weight } =>
1536				Self::SubscribeVersion { query_id, max_response_weight },
1537			UnsubscribeVersion => Self::UnsubscribeVersion,
1538			BurnAsset(assets) => Self::BurnAsset(assets.try_into()?),
1539			ExpectAsset(assets) => Self::ExpectAsset(assets.try_into()?),
1540			ExpectOrigin(maybe_location) => Self::ExpectOrigin(
1541				maybe_location.map(|location| location.try_into()).transpose().map_err(|_| ())?,
1542			),
1543			ExpectError(maybe_error) => Self::ExpectError(
1544				maybe_error.map(|error| error.try_into()).transpose().map_err(|_| ())?,
1545			),
1546			ExpectTransactStatus(maybe_error_code) => Self::ExpectTransactStatus(maybe_error_code),
1547			QueryPallet { module_name, response_info } => Self::QueryPallet {
1548				module_name,
1549				response_info: response_info.try_into().map_err(|_| ())?,
1550			},
1551			ExpectPallet { index, name, module_name, crate_major, min_crate_minor } =>
1552				Self::ExpectPallet { index, name, module_name, crate_major, min_crate_minor },
1553			ReportTransactStatus(response_info) =>
1554				Self::ReportTransactStatus(response_info.try_into().map_err(|_| ())?),
1555			ClearTransactStatus => Self::ClearTransactStatus,
1556			UniversalOrigin(junction) =>
1557				Self::UniversalOrigin(junction.try_into().map_err(|_| ())?),
1558			ExportMessage { network, destination, xcm } => Self::ExportMessage {
1559				network: network.into(),
1560				destination: destination.try_into().map_err(|_| ())?,
1561				xcm: xcm.try_into().map_err(|_| ())?,
1562			},
1563			LockAsset { asset, unlocker } => Self::LockAsset {
1564				asset: asset.try_into().map_err(|_| ())?,
1565				unlocker: unlocker.try_into().map_err(|_| ())?,
1566			},
1567			UnlockAsset { asset, target } => Self::UnlockAsset {
1568				asset: asset.try_into().map_err(|_| ())?,
1569				target: target.try_into().map_err(|_| ())?,
1570			},
1571			NoteUnlockable { asset, owner } => Self::NoteUnlockable {
1572				asset: asset.try_into().map_err(|_| ())?,
1573				owner: owner.try_into().map_err(|_| ())?,
1574			},
1575			RequestUnlock { asset, locker } => Self::RequestUnlock {
1576				asset: asset.try_into().map_err(|_| ())?,
1577				locker: locker.try_into().map_err(|_| ())?,
1578			},
1579			SetFeesMode { jit_withdraw } => Self::SetFeesMode { jit_withdraw },
1580			SetTopic(topic) => Self::SetTopic(topic),
1581			ClearTopic => Self::ClearTopic,
1582			AliasOrigin(location) => Self::AliasOrigin(location.try_into().map_err(|_| ())?),
1583			UnpaidExecution { weight_limit, check_origin } => Self::UnpaidExecution {
1584				weight_limit,
1585				check_origin: check_origin
1586					.map(|location| location.try_into())
1587					.transpose()
1588					.map_err(|_| ())?,
1589			},
1590		})
1591	}
1592}
1593
1594#[cfg(test)]
1595mod tests {
1596	use super::{prelude::*, *};
1597	use crate::{
1598		v3::{
1599			Junctions::Here as OldHere, MultiAssetFilter as OldMultiAssetFilter,
1600			WildMultiAsset as OldWildMultiAsset,
1601		},
1602		MAX_INSTRUCTIONS_TO_DECODE,
1603	};
1604
1605	#[test]
1606	fn basic_roundtrip_works() {
1607		let xcm = Xcm::<()>(vec![TransferAsset {
1608			assets: (Here, 1u128).into(),
1609			beneficiary: Here.into(),
1610		}]);
1611		let old_xcm = OldXcm::<()>(vec![OldInstruction::TransferAsset {
1612			assets: (OldHere, 1u128).into(),
1613			beneficiary: OldHere.into(),
1614		}]);
1615		assert_eq!(old_xcm, OldXcm::<()>::try_from(xcm.clone()).unwrap());
1616		let new_xcm: Xcm<()> = old_xcm.try_into().unwrap();
1617		assert_eq!(new_xcm, xcm);
1618	}
1619
1620	#[test]
1621	fn teleport_roundtrip_works() {
1622		let xcm = Xcm::<()>(vec![
1623			ReceiveTeleportedAsset((Here, 1u128).into()),
1624			ClearOrigin,
1625			DepositAsset { assets: Wild(AllCounted(1)), beneficiary: Here.into() },
1626		]);
1627		let old_xcm: OldXcm<()> = OldXcm::<()>(vec![
1628			OldInstruction::ReceiveTeleportedAsset((OldHere, 1u128).into()),
1629			OldInstruction::ClearOrigin,
1630			OldInstruction::DepositAsset {
1631				assets: crate::v3::MultiAssetFilter::Wild(crate::v3::WildMultiAsset::AllCounted(1)),
1632				beneficiary: OldHere.into(),
1633			},
1634		]);
1635		assert_eq!(old_xcm, OldXcm::<()>::try_from(xcm.clone()).unwrap());
1636		let new_xcm: Xcm<()> = old_xcm.try_into().unwrap();
1637		assert_eq!(new_xcm, xcm);
1638	}
1639
1640	#[test]
1641	fn reserve_deposit_roundtrip_works() {
1642		let xcm = Xcm::<()>(vec![
1643			ReserveAssetDeposited((Here, 1u128).into()),
1644			ClearOrigin,
1645			BuyExecution {
1646				fees: (Here, 1u128).into(),
1647				weight_limit: Some(Weight::from_parts(1, 1)).into(),
1648			},
1649			DepositAsset { assets: Wild(AllCounted(1)), beneficiary: Here.into() },
1650		]);
1651		let old_xcm = OldXcm::<()>(vec![
1652			OldInstruction::ReserveAssetDeposited((OldHere, 1u128).into()),
1653			OldInstruction::ClearOrigin,
1654			OldInstruction::BuyExecution {
1655				fees: (OldHere, 1u128).into(),
1656				weight_limit: WeightLimit::Limited(Weight::from_parts(1, 1)),
1657			},
1658			OldInstruction::DepositAsset {
1659				assets: crate::v3::MultiAssetFilter::Wild(crate::v3::WildMultiAsset::AllCounted(1)),
1660				beneficiary: OldHere.into(),
1661			},
1662		]);
1663		assert_eq!(old_xcm, OldXcm::<()>::try_from(xcm.clone()).unwrap());
1664		let new_xcm: Xcm<()> = old_xcm.try_into().unwrap();
1665		assert_eq!(new_xcm, xcm);
1666	}
1667
1668	#[test]
1669	fn deposit_asset_roundtrip_works() {
1670		let xcm = Xcm::<()>(vec![
1671			WithdrawAsset((Here, 1u128).into()),
1672			DepositAsset { assets: Wild(AllCounted(1)), beneficiary: Here.into() },
1673		]);
1674		let old_xcm = OldXcm::<()>(vec![
1675			OldInstruction::WithdrawAsset((OldHere, 1u128).into()),
1676			OldInstruction::DepositAsset {
1677				assets: OldMultiAssetFilter::Wild(OldWildMultiAsset::AllCounted(1)),
1678				beneficiary: OldHere.into(),
1679			},
1680		]);
1681		assert_eq!(old_xcm, OldXcm::<()>::try_from(xcm.clone()).unwrap());
1682		let new_xcm: Xcm<()> = old_xcm.try_into().unwrap();
1683		assert_eq!(new_xcm, xcm);
1684	}
1685
1686	#[test]
1687	fn deposit_reserve_asset_roundtrip_works() {
1688		let xcm = Xcm::<()>(vec![
1689			WithdrawAsset((Here, 1u128).into()),
1690			DepositReserveAsset {
1691				assets: Wild(AllCounted(1)),
1692				dest: Here.into(),
1693				xcm: Xcm::<()>(vec![]),
1694			},
1695		]);
1696		let old_xcm = OldXcm::<()>(vec![
1697			OldInstruction::WithdrawAsset((OldHere, 1u128).into()),
1698			OldInstruction::DepositReserveAsset {
1699				assets: OldMultiAssetFilter::Wild(OldWildMultiAsset::AllCounted(1)),
1700				dest: OldHere.into(),
1701				xcm: OldXcm::<()>(vec![]),
1702			},
1703		]);
1704		assert_eq!(old_xcm, OldXcm::<()>::try_from(xcm.clone()).unwrap());
1705		let new_xcm: Xcm<()> = old_xcm.try_into().unwrap();
1706		assert_eq!(new_xcm, xcm);
1707	}
1708
1709	#[test]
1710	fn decoding_respects_limit() {
1711		let max_xcm = Xcm::<()>(vec![ClearOrigin; MAX_INSTRUCTIONS_TO_DECODE as usize]);
1712		let encoded = max_xcm.encode();
1713		assert!(Xcm::<()>::decode(&mut &encoded[..]).is_ok());
1714
1715		let big_xcm = Xcm::<()>(vec![ClearOrigin; MAX_INSTRUCTIONS_TO_DECODE as usize + 1]);
1716		let encoded = big_xcm.encode();
1717		assert!(Xcm::<()>::decode(&mut &encoded[..]).is_err());
1718
1719		let nested_xcm = Xcm::<()>(vec![
1720			DepositReserveAsset {
1721				assets: All.into(),
1722				dest: Here.into(),
1723				xcm: max_xcm,
1724			};
1725			(MAX_INSTRUCTIONS_TO_DECODE / 2) as usize
1726		]);
1727		let encoded = nested_xcm.encode();
1728		assert!(Xcm::<()>::decode(&mut &encoded[..]).is_err());
1729
1730		let even_more_nested_xcm = Xcm::<()>(vec![SetAppendix(nested_xcm); 64]);
1731		let encoded = even_more_nested_xcm.encode();
1732		assert_eq!(encoded.len(), 342530);
1733		// This should not decode since the limit is 100
1734		assert_eq!(MAX_INSTRUCTIONS_TO_DECODE, 100, "precondition");
1735		assert!(Xcm::<()>::decode(&mut &encoded[..]).is_err());
1736	}
1737}