17
17
18
18
#![ cfg_attr( not( feature = "std" ) , no_std) ]
19
19
20
- // #[cfg(test)]
21
- // mod mock;
22
- // #[cfg(test)]
23
- // mod tests;
20
+ // --- substrate ---
21
+ use sp_core:: U256 ;
22
+ #[ cfg( feature = "std" ) ]
23
+ use sp_inherents:: InherentDataProvider as InherentDataProviderT ;
24
+ use sp_inherents:: { Error , InherentData , InherentIdentifier , IsFatalError } ;
25
+ use sp_runtime:: RuntimeDebug ;
26
+ // --- darwinia ---
27
+ use darwinia_evm:: FeeCalculator ;
28
+ // --- core ---
29
+ use codec:: { Decode , Encode } ;
30
+ use core:: cmp;
31
+
32
+ pub use pallet:: * ;
33
+ pub const INHERENT_IDENTIFIER : InherentIdentifier = * b"dynfee0_" ;
24
34
25
35
#[ frame_support:: pallet]
26
36
pub mod pallet {
27
- // --- core ---
28
- use core:: cmp;
29
- // --- substrate ---
37
+ use super :: * ;
30
38
use frame_support:: pallet_prelude:: * ;
31
39
use frame_system:: pallet_prelude:: * ;
32
- use sp_core:: U256 ;
33
- #[ cfg( feature = "std" ) ]
34
- use sp_inherents:: InherentDataProvider as InherentDataProviderT ;
35
- use sp_inherents:: { Error , IsFatalError } ;
36
- // --- darwinia ---
37
- use darwinia_evm:: FeeCalculator ;
38
-
39
- pub type InherentType = U256 ;
40
-
41
- pub const INHERENT_IDENTIFIER : InherentIdentifier = * b"dynfee0_" ;
42
40
43
41
#[ pallet:: config]
44
42
pub trait Config : frame_system:: Config {
@@ -56,16 +54,12 @@ pub mod pallet {
56
54
#[ pallet:: storage]
57
55
pub type TargetMinGasPrice < T > = StorageValue < _ , U256 , OptionQuery > ;
58
56
59
- #[ cfg_attr( feature = "std" , derive( Default ) ) ]
60
57
#[ pallet:: genesis_config]
61
- pub struct GenesisConfig {
62
- pub min_gas_price : U256 ,
63
- }
58
+ #[ derive( Default ) ]
59
+ pub struct GenesisConfig ;
64
60
#[ pallet:: genesis_build]
65
61
impl < T : Config > GenesisBuild < T > for GenesisConfig {
66
- fn build ( & self ) {
67
- <MinGasPrice < T > >:: put ( self . min_gas_price ) ;
68
- }
62
+ fn build ( & self ) { }
69
63
}
70
64
71
65
#[ pallet:: pallet]
@@ -99,15 +93,11 @@ pub mod pallet {
99
93
ensure_none ( origin) ?;
100
94
101
95
<TargetMinGasPrice < T > >:: set ( Some ( target) ) ;
102
-
103
96
Ok ( ( ) . into ( ) )
104
97
}
105
98
}
106
- impl < T : Config > FeeCalculator for Pallet < T > {
107
- fn min_gas_price ( ) -> U256 {
108
- <MinGasPrice < T > >:: get ( )
109
- }
110
- }
99
+
100
+ #[ pallet:: inherent]
111
101
impl < T : Config > ProvideInherent for Pallet < T > {
112
102
type Call = Call < T > ;
113
103
type Error = InherentError ;
@@ -116,7 +106,6 @@ pub mod pallet {
116
106
117
107
fn create_inherent ( data : & InherentData ) -> Option < Self :: Call > {
118
108
let target = data. get_data :: < InherentType > ( & INHERENT_IDENTIFIER ) . ok ( ) ??;
119
-
120
109
Some ( Call :: note_min_gas_price_target ( target) )
121
110
}
122
111
@@ -128,42 +117,49 @@ pub mod pallet {
128
117
true
129
118
}
130
119
}
120
+ }
121
+
122
+ impl < T : Config > FeeCalculator for Pallet < T > {
123
+ fn min_gas_price ( ) -> U256 {
124
+ <MinGasPrice < T > >:: get ( )
125
+ }
126
+ }
131
127
132
- #[ derive( Encode , Decode , RuntimeDebug ) ]
133
- pub enum InherentError { }
134
- impl IsFatalError for InherentError {
135
- fn is_fatal_error ( & self ) -> bool {
136
- match * self { }
137
- }
128
+ #[ derive( Encode , Decode , RuntimeDebug ) ]
129
+ pub enum InherentError { }
130
+ impl IsFatalError for InherentError {
131
+ fn is_fatal_error ( & self ) -> bool {
132
+ match * self { }
138
133
}
134
+ }
139
135
140
- # [ cfg ( feature = "std" ) ]
141
- pub struct InherentDataProvider ( pub InherentType ) ;
142
- # [ cfg ( feature = "std" ) ]
143
- impl InherentDataProvider {
144
- pub fn from_target_gas_price ( price : InherentType ) -> Self {
145
- Self ( price)
146
- }
136
+ pub type InherentType = U256 ;
137
+ # [ cfg ( feature = "std" ) ]
138
+ pub struct InherentDataProvider ( pub InherentType ) ;
139
+ # [ cfg ( feature = "std" ) ]
140
+ impl InherentDataProvider {
141
+ pub fn from_target_gas_price ( price : InherentType ) -> Self {
142
+ Self ( price )
147
143
}
148
- #[ cfg( feature = "std" ) ]
149
- #[ async_trait:: async_trait]
150
- impl InherentDataProviderT for InherentDataProvider {
151
- fn provide_inherent_data ( & self , inherent_data : & mut InherentData ) -> Result < ( ) , Error > {
152
- inherent_data. put_data ( INHERENT_IDENTIFIER , & self . 0 )
153
- }
144
+ }
154
145
155
- async fn try_handle_error (
156
- & self ,
157
- identifier : & InherentIdentifier ,
158
- error : & [ u8 ] ,
159
- ) -> Option < Result < ( ) , Error > > {
160
- if * identifier != INHERENT_IDENTIFIER {
161
- return None ;
162
- }
146
+ #[ cfg( feature = "std" ) ]
147
+ #[ async_trait:: async_trait]
148
+ impl InherentDataProviderT for InherentDataProvider {
149
+ fn provide_inherent_data ( & self , inherent_data : & mut InherentData ) -> Result < ( ) , Error > {
150
+ inherent_data. put_data ( INHERENT_IDENTIFIER , & self . 0 )
151
+ }
163
152
164
- let error = InherentError :: decode ( & mut & error[ ..] ) . ok ( ) ?;
165
- Some ( Err ( Error :: Application ( Box :: from ( format ! ( "{:?}" , error) ) ) ) )
153
+ async fn try_handle_error (
154
+ & self ,
155
+ identifier : & InherentIdentifier ,
156
+ error : & [ u8 ] ,
157
+ ) -> Option < Result < ( ) , Error > > {
158
+ if * identifier != INHERENT_IDENTIFIER {
159
+ return None ;
166
160
}
161
+
162
+ let error = InherentError :: decode ( & mut & error[ ..] ) . ok ( ) ?;
163
+ Some ( Err ( Error :: Application ( Box :: from ( format ! ( "{:?}" , error) ) ) ) )
167
164
}
168
165
}
169
- pub use pallet:: * ;
0 commit comments