westend_runtime/governance/
origins.rs1pub use pallet_custom_origins::*;
20
21#[frame_support::pallet]
22pub mod pallet_custom_origins {
23 use crate::{Balance, CENTS, GRAND};
24 use frame_support::pallet_prelude::*;
25
26 #[pallet::config]
27 pub trait Config: frame_system::Config {}
28
29 #[pallet::pallet]
30 pub struct Pallet<T>(_);
31
32 #[derive(
33 PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, DecodeWithMemTracking, TypeInfo, Debug,
34 )]
35 #[pallet::origin]
36 pub enum Origin {
37 StakingAdmin,
39 Treasurer,
41 FellowshipAdmin,
43 GeneralAdmin,
45 AuctionAdmin,
47 LeaseAdmin,
49 ReferendumCanceller,
51 ReferendumKiller,
53 SmallTipper,
55 BigTipper,
57 SmallSpender,
59 MediumSpender,
61 BigSpender,
63 WhitelistedCaller,
65 FellowshipInitiates,
67 Fellows,
69 FellowshipExperts,
71 FellowshipMasters,
73 Fellowship1Dan,
75 Fellowship2Dan,
77 Fellowship3Dan,
79 Fellowship4Dan,
81 Fellowship5Dan,
83 Fellowship6Dan,
85 Fellowship7Dan,
87 Fellowship8Dan,
89 Fellowship9Dan,
91 }
92
93 macro_rules! decl_unit_ensures {
94 ( $name:ident: $success_type:ty = $success:expr ) => {
95 pub struct $name;
96 impl<O: OriginTrait + From<Origin>> EnsureOrigin<O> for $name
97 where
98 for <'a> &'a O::PalletsOrigin: TryInto<&'a Origin>,
99 {
100 type Success = $success_type;
101 fn try_origin(o: O) -> Result<Self::Success, O> {
102 match o.caller().try_into() {
103 Ok(Origin::$name) => return Ok($success),
104 _ => (),
105 }
106
107 Err(o)
108 }
109 #[cfg(feature = "runtime-benchmarks")]
110 fn try_successful_origin() -> Result<O, ()> {
111 Ok(O::from(Origin::$name))
112 }
113 }
114 };
115 ( $name:ident ) => { decl_unit_ensures! { $name : () = () } };
116 ( $name:ident: $success_type:ty = $success:expr, $( $rest:tt )* ) => {
117 decl_unit_ensures! { $name: $success_type = $success }
118 decl_unit_ensures! { $( $rest )* }
119 };
120 ( $name:ident, $( $rest:tt )* ) => {
121 decl_unit_ensures! { $name }
122 decl_unit_ensures! { $( $rest )* }
123 };
124 () => {}
125 }
126 decl_unit_ensures!(
127 StakingAdmin,
128 Treasurer,
129 FellowshipAdmin,
130 GeneralAdmin,
131 AuctionAdmin,
132 LeaseAdmin,
133 ReferendumCanceller,
134 ReferendumKiller,
135 WhitelistedCaller,
136 FellowshipInitiates: u16 = 0,
137 Fellows: u16 = 3,
138 FellowshipExperts: u16 = 5,
139 FellowshipMasters: u16 = 7,
140 );
141
142 macro_rules! decl_ensure {
143 (
144 $vis:vis type $name:ident: EnsureOrigin<Success = $success_type:ty> {
145 $( $item:ident = $success:expr, )*
146 }
147 ) => {
148 $vis struct $name;
149 impl<O: OriginTrait + From<Origin>> EnsureOrigin<O> for $name
150 where
151 for <'a> &'a O::PalletsOrigin: TryInto<&'a Origin>,
152 {
153 type Success = $success_type;
154 fn try_origin(o: O) -> Result<Self::Success, O> {
155 match o.caller().try_into() {
156 $(
157 Ok(Origin::$item) => return Ok($success),
158 )*
159 _ => (),
160 }
161
162 Err(o)
163 }
164 #[cfg(feature = "runtime-benchmarks")]
165 fn try_successful_origin() -> Result<O, ()> {
166 let _result: Result<O, ()> = Err(());
169 $(
170 let _result: Result<O, ()> = Ok(O::from(Origin::$item));
171 )*
172 _result
173 }
174 }
175 }
176 }
177
178 decl_ensure! {
179 pub type Spender: EnsureOrigin<Success = Balance> {
180 SmallTipper = 250 * 3 * CENTS,
181 BigTipper = 1 * GRAND,
182 SmallSpender = 10 * GRAND,
183 MediumSpender = 100 * GRAND,
184 BigSpender = 1_000 * GRAND,
185 Treasurer = 10_000 * GRAND,
186 }
187 }
188
189 decl_ensure! {
190 pub type EnsureFellowship: EnsureOrigin<Success = u16> {
191 Fellowship1Dan = 1,
192 Fellowship2Dan = 2,
193 Fellowship3Dan = 3,
194 Fellowship4Dan = 4,
195 Fellowship5Dan = 5,
196 Fellowship6Dan = 6,
197 Fellowship7Dan = 7,
198 Fellowship8Dan = 8,
199 Fellowship9Dan = 9,
200 }
201 }
202}