cumulus_pallet_xcm/
lib.rs1#![cfg_attr(not(feature = "std"), no_std)]
22
23use codec::{Decode, Encode};
24use cumulus_primitives_core::ParaId;
25pub use pallet::*;
26use scale_info::TypeInfo;
27use sp_runtime::{traits::BadOrigin, RuntimeDebug};
28use xcm::latest::{ExecuteXcm, Outcome};
29
30#[frame_support::pallet]
31pub mod pallet {
32 use super::*;
33 use frame_support::pallet_prelude::*;
34
35 #[pallet::pallet]
36 pub struct Pallet<T>(_);
37
38 #[pallet::config]
40 pub trait Config: frame_system::Config {
41 #[allow(deprecated)]
43 type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
44
45 type XcmExecutor: ExecuteXcm<Self::RuntimeCall>;
46 }
47
48 #[pallet::event]
49 pub enum Event<T: Config> {
50 InvalidFormat([u8; 32]),
53 UnsupportedVersion([u8; 32]),
56 ExecutedDownward([u8; 32], Outcome),
59 }
60
61 #[derive(
63 PartialEq,
64 Eq,
65 Clone,
66 Encode,
67 Decode,
68 DecodeWithMemTracking,
69 TypeInfo,
70 RuntimeDebug,
71 MaxEncodedLen,
72 )]
73 #[pallet::origin]
74 pub enum Origin {
75 Relay,
77 SiblingParachain(ParaId),
79 }
80
81 #[pallet::call]
82 impl<T: Config> Pallet<T> {}
83
84 impl From<ParaId> for Origin {
85 fn from(id: ParaId) -> Origin {
86 Origin::SiblingParachain(id)
87 }
88 }
89 impl From<u32> for Origin {
90 fn from(id: u32) -> Origin {
91 Origin::SiblingParachain(id.into())
92 }
93 }
94}
95
96pub fn ensure_sibling_para<OuterOrigin>(o: OuterOrigin) -> Result<ParaId, BadOrigin>
99where
100 OuterOrigin: Into<Result<Origin, OuterOrigin>>,
101{
102 match o.into() {
103 Ok(Origin::SiblingParachain(id)) => Ok(id),
104 _ => Err(BadOrigin),
105 }
106}
107
108pub fn ensure_relay<OuterOrigin>(o: OuterOrigin) -> Result<(), BadOrigin>
111where
112 OuterOrigin: Into<Result<Origin, OuterOrigin>>,
113{
114 match o.into() {
115 Ok(Origin::Relay) => Ok(()),
116 _ => Err(BadOrigin),
117 }
118}