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;
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, Eq, Clone, Encode, Decode, DecodeWithMemTracking, TypeInfo, Debug, MaxEncodedLen,
64 )]
65 #[pallet::origin]
66 pub enum Origin {
67 Relay,
69 SiblingParachain(ParaId),
71 }
72
73 #[pallet::call]
74 impl<T: Config> Pallet<T> {}
75
76 impl From<ParaId> for Origin {
77 fn from(id: ParaId) -> Origin {
78 Origin::SiblingParachain(id)
79 }
80 }
81 impl From<u32> for Origin {
82 fn from(id: u32) -> Origin {
83 Origin::SiblingParachain(id.into())
84 }
85 }
86}
87
88pub fn ensure_sibling_para<OuterOrigin>(o: OuterOrigin) -> Result<ParaId, BadOrigin>
91where
92 OuterOrigin: Into<Result<Origin, OuterOrigin>>,
93{
94 match o.into() {
95 Ok(Origin::SiblingParachain(id)) => Ok(id),
96 _ => Err(BadOrigin),
97 }
98}
99
100pub fn ensure_relay<OuterOrigin>(o: OuterOrigin) -> Result<(), BadOrigin>
103where
104 OuterOrigin: Into<Result<Origin, OuterOrigin>>,
105{
106 match o.into() {
107 Ok(Origin::Relay) => Ok(()),
108 _ => Err(BadOrigin),
109 }
110}