1919#![ allow( clippy:: borrowed_box) ]
2020#![ allow( clippy:: unused_unit) ]
2121
22+ use frame_support:: {
23+ dispatch:: PostDispatchInfo ,
24+ pallet_prelude:: * ,
25+ traits:: {
26+ schedule:: { DispatchTime , Named as ScheduleNamed , Priority } ,
27+ EnsureOrigin , Get , IsType , OriginTrait ,
28+ } ,
29+ weights:: GetDispatchInfo ,
30+ } ;
31+ use frame_system:: pallet_prelude:: * ;
32+ use sp_runtime:: {
33+ traits:: { CheckedSub , Dispatchable , Saturating } ,
34+ DispatchError , DispatchResult , RuntimeDebug ,
35+ } ;
36+ use sp_std:: prelude:: * ;
37+
2238mod default_weight;
2339mod mock;
2440mod tests;
2541
42+ /// A delayed origin. Can only be dispatched via `dispatch_as` with a delay.
43+ #[ derive( PartialEq , Eq , Clone , RuntimeDebug , Encode , Decode ) ]
44+ pub struct DelayedOrigin < BlockNumber , PalletsOrigin > {
45+ /// Number of blocks that this call have been delayed.
46+ pub delay : BlockNumber ,
47+ /// The initial origin.
48+ pub origin : Box < PalletsOrigin > ,
49+ }
50+
51+ /// Ensure the origin have a minimum amount of delay.
52+ pub struct EnsureDelayed < Delay , Inner , BlockNumber , PalletsOrigin > (
53+ sp_std:: marker:: PhantomData < ( Delay , Inner , BlockNumber , PalletsOrigin ) > ,
54+ ) ;
55+ impl <
56+ PalletsOrigin : Into < O > ,
57+ O : Into < Result < DelayedOrigin < BlockNumber , PalletsOrigin > , O > > + From < DelayedOrigin < BlockNumber , PalletsOrigin > > ,
58+ Delay : Get < BlockNumber > ,
59+ Inner : EnsureOrigin < O > ,
60+ BlockNumber : PartialOrd ,
61+ > EnsureOrigin < O > for EnsureDelayed < Delay , Inner , BlockNumber , PalletsOrigin >
62+ {
63+ type Success = Inner :: Success ;
64+
65+ fn try_origin ( o : O ) -> Result < Self :: Success , O > {
66+ o. into ( ) . and_then ( |delayed_origin| {
67+ if delayed_origin. delay >= Delay :: get ( ) {
68+ let pallets_origin = * delayed_origin. origin ;
69+ Inner :: try_origin ( pallets_origin. into ( ) )
70+ } else {
71+ Err ( delayed_origin. into ( ) )
72+ }
73+ } )
74+ }
75+
76+ #[ cfg( feature = "runtime-benchmarks" ) ]
77+ fn successful_origin ( ) -> O {
78+ unimplemented ! ( )
79+ }
80+ }
81+
82+ /// Config for orml-authority
83+ pub trait AuthorityConfig < Origin , PalletsOrigin , BlockNumber > {
84+ /// Check if the `origin` is allowed to schedule a dispatchable call
85+ /// with a given `priority`.
86+ fn check_schedule_dispatch ( origin : Origin , priority : Priority ) -> DispatchResult ;
87+ /// Check if the `origin` is allow to fast track a scheduled task that
88+ /// initially created by `initial_origin`. `new_delay` is number of
89+ /// blocks this dispatchable will be dispatched from now after fast
90+ /// track.
91+ fn check_fast_track_schedule (
92+ origin : Origin ,
93+ initial_origin : & PalletsOrigin ,
94+ new_delay : BlockNumber ,
95+ ) -> DispatchResult ;
96+ /// Check if the `origin` is allow to delay a scheduled task that
97+ /// initially created by `inital_origin`.
98+ fn check_delay_schedule ( origin : Origin , initial_origin : & PalletsOrigin ) -> DispatchResult ;
99+ /// Check if the `origin` is allow to cancel a scheduled task that
100+ /// initially created by `inital_origin`.
101+ fn check_cancel_schedule ( origin : Origin , initial_origin : & PalletsOrigin ) -> DispatchResult ;
102+ }
103+
104+ /// Represent an origin that can be dispatched by other origins with
105+ /// permission check.
106+ pub trait AsOriginId < Origin , PalletsOrigin > {
107+ /// Convert into `PalletsOrigin`
108+ fn into_origin ( self ) -> PalletsOrigin ;
109+ /// Check if the `origin` is allow to dispatch call on behalf of this
110+ /// origin.
111+ fn check_dispatch_from ( & self , origin : Origin ) -> DispatchResult ;
112+ }
113+
114+ /// The schedule task index type.
115+ pub type ScheduleTaskIndex = u32 ;
116+
26117pub use module:: * ;
27118
28119#[ frame_support:: pallet]
29120pub mod module {
30- use frame_support:: {
31- dispatch:: PostDispatchInfo ,
32- pallet_prelude:: * ,
33- traits:: {
34- schedule:: { DispatchTime , Named as ScheduleNamed , Priority } ,
35- EnsureOrigin , Get , IsType , OriginTrait ,
36- } ,
37- weights:: GetDispatchInfo ,
38- } ;
39- use frame_system:: pallet_prelude:: * ;
40- use sp_runtime:: {
41- traits:: { CheckedSub , Dispatchable , Saturating } ,
42- DispatchError , DispatchResult , RuntimeDebug ,
43- } ;
44- use sp_std:: prelude:: * ;
121+ use super :: * ;
45122
46123 pub trait WeightInfo {
47124 fn dispatch_as ( ) -> Weight ;
@@ -52,86 +129,9 @@ pub mod module {
52129 fn cancel_scheduled_dispatch ( ) -> Weight ;
53130 }
54131
55- /// A delayed origin. Can only be dispatched via `dispatch_as` with a delay.
56- #[ derive( PartialEq , Eq , Clone , RuntimeDebug , Encode , Decode ) ]
57- pub struct DelayedOrigin < BlockNumber , PalletsOrigin > {
58- /// Number of blocks that this call have been delayed.
59- pub delay : BlockNumber ,
60- /// The initial origin.
61- pub origin : Box < PalletsOrigin > ,
62- }
63-
64- /// Ensure the origin have a minimum amount of delay.
65- pub struct EnsureDelayed < Delay , Inner , BlockNumber , PalletsOrigin > (
66- sp_std:: marker:: PhantomData < ( Delay , Inner , BlockNumber , PalletsOrigin ) > ,
67- ) ;
68- impl <
69- PalletsOrigin : Into < O > ,
70- O : Into < Result < DelayedOrigin < BlockNumber , PalletsOrigin > , O > >
71- + From < DelayedOrigin < BlockNumber , PalletsOrigin > > ,
72- Delay : Get < BlockNumber > ,
73- Inner : EnsureOrigin < O > ,
74- BlockNumber : PartialOrd ,
75- > EnsureOrigin < O > for EnsureDelayed < Delay , Inner , BlockNumber , PalletsOrigin >
76- {
77- type Success = Inner :: Success ;
78-
79- fn try_origin ( o : O ) -> Result < Self :: Success , O > {
80- o. into ( ) . and_then ( |delayed_origin| {
81- if delayed_origin. delay >= Delay :: get ( ) {
82- let pallets_origin = * delayed_origin. origin ;
83- Inner :: try_origin ( pallets_origin. into ( ) )
84- } else {
85- Err ( delayed_origin. into ( ) )
86- }
87- } )
88- }
89-
90- #[ cfg( feature = "runtime-benchmarks" ) ]
91- fn successful_origin ( ) -> O {
92- unimplemented ! ( )
93- }
94- }
95-
96132 /// Origin for the authority module.
97133 pub type Origin < T > = DelayedOrigin < <T as frame_system:: Config >:: BlockNumber , <T as Config >:: PalletsOrigin > ;
98-
99- /// Config for orml-authority
100- pub trait AuthorityConfig < Origin , PalletsOrigin , BlockNumber > {
101- /// Check if the `origin` is allowed to schedule a dispatchable call
102- /// with a given `priority`.
103- fn check_schedule_dispatch ( origin : Origin , priority : Priority ) -> DispatchResult ;
104- /// Check if the `origin` is allow to fast track a scheduled task that
105- /// initially created by `initial_origin`. `new_delay` is number of
106- /// blocks this dispatchable will be dispatched from now after fast
107- /// track.
108- fn check_fast_track_schedule (
109- origin : Origin ,
110- initial_origin : & PalletsOrigin ,
111- new_delay : BlockNumber ,
112- ) -> DispatchResult ;
113- /// Check if the `origin` is allow to delay a scheduled task that
114- /// initially created by `inital_origin`.
115- fn check_delay_schedule ( origin : Origin , initial_origin : & PalletsOrigin ) -> DispatchResult ;
116- /// Check if the `origin` is allow to cancel a scheduled task that
117- /// initially created by `inital_origin`.
118- fn check_cancel_schedule ( origin : Origin , initial_origin : & PalletsOrigin ) -> DispatchResult ;
119- }
120-
121- /// Represent an origin that can be dispatched by other origins with
122- /// permission check.
123- pub trait AsOriginId < Origin , PalletsOrigin > {
124- /// Convert into `PalletsOrigin`
125- fn into_origin ( self ) -> PalletsOrigin ;
126- /// Check if the `origin` is allow to dispatch call on behalf of this
127- /// origin.
128- fn check_dispatch_from ( & self , origin : Origin ) -> DispatchResult ;
129- }
130-
131- type CallOf < T > = <T as Config >:: Call ;
132-
133- /// The schedule task index type.
134- pub type ScheduleTaskIndex = u32 ;
134+ pub ( crate ) type CallOf < T > = <T as Config >:: Call ;
135135
136136 #[ pallet:: config]
137137 pub trait Config : frame_system:: Config {
0 commit comments