pallet_staking_async_rc_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,
34 Eq,
35 Clone,
36 MaxEncodedLen,
37 Encode,
38 Decode,
39 DecodeWithMemTracking,
40 TypeInfo,
41 RuntimeDebug,
42 )]
43 #[pallet::origin]
44 pub enum Origin {
45 StakingAdmin,
47 Treasurer,
49 FellowshipAdmin,
51 GeneralAdmin,
53 AuctionAdmin,
55 LeaseAdmin,
57 ReferendumCanceller,
59 ReferendumKiller,
61 SmallTipper,
63 BigTipper,
65 SmallSpender,
67 MediumSpender,
69 BigSpender,
71 WhitelistedCaller,
73 FellowshipInitiates,
75 Fellows,
77 FellowshipExperts,
79 FellowshipMasters,
81 Fellowship1Dan,
83 Fellowship2Dan,
85 Fellowship3Dan,
87 Fellowship4Dan,
89 Fellowship5Dan,
91 Fellowship6Dan,
93 Fellowship7Dan,
95 Fellowship8Dan,
97 Fellowship9Dan,
99 }
100
101 macro_rules! decl_unit_ensures {
102 ( $name:ident: $success_type:ty = $success:expr ) => {
103 pub struct $name;
104 impl<O: Into<Result<Origin, O>> + From<Origin>>
105 EnsureOrigin<O> for $name
106 {
107 type Success = $success_type;
108 fn try_origin(o: O) -> Result<Self::Success, O> {
109 o.into().and_then(|o| match o {
110 Origin::$name => Ok($success),
111 r => Err(O::from(r)),
112 })
113 }
114 #[cfg(feature = "runtime-benchmarks")]
115 fn try_successful_origin() -> Result<O, ()> {
116 Ok(O::from(Origin::$name))
117 }
118 }
119 };
120 ( $name:ident ) => { decl_unit_ensures! { $name : () = () } };
121 ( $name:ident: $success_type:ty = $success:expr, $( $rest:tt )* ) => {
122 decl_unit_ensures! { $name: $success_type = $success }
123 decl_unit_ensures! { $( $rest )* }
124 };
125 ( $name:ident, $( $rest:tt )* ) => {
126 decl_unit_ensures! { $name }
127 decl_unit_ensures! { $( $rest )* }
128 };
129 () => {}
130 }
131 decl_unit_ensures!(
132 StakingAdmin,
133 Treasurer,
134 FellowshipAdmin,
135 GeneralAdmin,
136 AuctionAdmin,
137 LeaseAdmin,
138 ReferendumCanceller,
139 ReferendumKiller,
140 WhitelistedCaller,
141 FellowshipInitiates: u16 = 0,
142 Fellows: u16 = 3,
143 FellowshipExperts: u16 = 5,
144 FellowshipMasters: u16 = 7,
145 );
146
147 macro_rules! decl_ensure {
148 (
149 $vis:vis type $name:ident: EnsureOrigin<Success = $success_type:ty> {
150 $( $item:ident = $success:expr, )*
151 }
152 ) => {
153 $vis struct $name;
154 impl<O: Into<Result<Origin, O>> + From<Origin>>
155 EnsureOrigin<O> for $name
156 {
157 type Success = $success_type;
158 fn try_origin(o: O) -> Result<Self::Success, O> {
159 o.into().and_then(|o| match o {
160 $(
161 Origin::$item => Ok($success),
162 )*
163 r => Err(O::from(r)),
164 })
165 }
166 #[cfg(feature = "runtime-benchmarks")]
167 fn try_successful_origin() -> Result<O, ()> {
168 let _result: Result<O, ()> = Err(());
171 $(
172 let _result: Result<O, ()> = Ok(O::from(Origin::$item));
173 )*
174 _result
175 }
176 }
177 }
178 }
179
180 decl_ensure! {
181 pub type Spender: EnsureOrigin<Success = Balance> {
182 SmallTipper = 250 * 3 * CENTS,
183 BigTipper = 1 * GRAND,
184 SmallSpender = 10 * GRAND,
185 MediumSpender = 100 * GRAND,
186 BigSpender = 1_000 * GRAND,
187 Treasurer = 10_000 * GRAND,
188 }
189 }
190
191 decl_ensure! {
192 pub type EnsureFellowship: EnsureOrigin<Success = u16> {
193 Fellowship1Dan = 1,
194 Fellowship2Dan = 2,
195 Fellowship3Dan = 3,
196 Fellowship4Dan = 4,
197 Fellowship5Dan = 5,
198 Fellowship6Dan = 6,
199 Fellowship7Dan = 7,
200 Fellowship8Dan = 8,
201 Fellowship9Dan = 9,
202 }
203 }
204}