@@ -23,9 +23,9 @@ mod tests;
23
23
#[ frame_support:: pallet]
24
24
pub mod pallet {
25
25
use super :: * ;
26
- use frame_support:: dispatch:: DispatchResult ;
27
26
use frame_support:: pallet_prelude:: * ;
28
27
use frame_support:: traits:: tokens:: Balance ;
28
+ use frame_support:: { dispatch:: DispatchResult , pallet_prelude:: StorageMap } ;
29
29
use frame_system:: pallet_prelude:: * ;
30
30
use pallet_evm_chain_id:: { self , ChainId } ;
31
31
use sp_runtime:: BoundedVec ;
@@ -69,7 +69,16 @@ pub mod pallet {
69
69
}
70
70
71
71
#[ pallet:: event]
72
- pub enum Event < T : Config > { }
72
+ #[ pallet:: generate_deposit( pub ( super ) fn deposit_event) ]
73
+ pub enum Event < T : Config > {
74
+ /// Event emitted when a precompile operation is updated.
75
+ PrecompileUpdated {
76
+ /// The type of precompile operation being updated.
77
+ precompile_id : PrecompileEnum ,
78
+ /// Indicates if the precompile operation is enabled or not.
79
+ enabled : bool ,
80
+ } ,
81
+ }
73
82
74
83
// Errors inform users that something went wrong.
75
84
#[ pallet:: error]
@@ -81,6 +90,39 @@ pub mod pallet {
81
90
/// The maximum number of subnet validators must be more than the current number of UIDs already in the subnet.
82
91
MaxAllowedUIdsLessThanCurrentUIds ,
83
92
}
93
+ /// Enum for specifying the type of precompile operation.
94
+ #[ derive( Encode , Decode , TypeInfo , Clone , PartialEq , Eq , Debug , Copy ) ]
95
+ pub enum PrecompileEnum {
96
+ /// Enum for balance transfer precompile
97
+ BalanceTransfer ,
98
+ /// Enum for staking precompile
99
+ Staking ,
100
+ /// Enum for subnet precompile
101
+ Subnet ,
102
+ /// Enum for metagraph precompile
103
+ Metagraph ,
104
+ /// Enum for subnets precompile
105
+ Subnets ,
106
+ /// Enum for neurons precompile
107
+ Neurons ,
108
+ }
109
+
110
+ #[ pallet:: type_value]
111
+ /// Default value for precompile enable
112
+ pub fn DefaultPrecompileEnabled < T : Config > ( ) -> bool {
113
+ true
114
+ }
115
+
116
+ #[ pallet:: storage]
117
+ /// Map PrecompileEnum --> enabled
118
+ pub type PrecompileEnable < T : Config > = StorageMap <
119
+ _ ,
120
+ Blake2_128Concat ,
121
+ PrecompileEnum ,
122
+ bool ,
123
+ ValueQuery ,
124
+ DefaultPrecompileEnabled < T > ,
125
+ > ;
84
126
85
127
/// Dispatchable functions allows users to interact with the pallet and invoke state changes.
86
128
#[ pallet:: call]
@@ -1276,6 +1318,26 @@ pub mod pallet {
1276
1318
ensure_root ( origin) ?;
1277
1319
T :: Grandpa :: schedule_change ( next_authorities, in_blocks, forced)
1278
1320
}
1321
+
1322
+ /// A public interface for `pallet_grandpa::Pallet::schedule_grandpa_change`.
1323
+ #[ pallet:: call_index( 60 ) ]
1324
+ #[ pallet:: weight( Weight :: from_parts( 46_000_000 , 0 ) ) ]
1325
+ pub fn sudo_toggle_evm_precompile (
1326
+ origin : OriginFor < T > ,
1327
+ precompile_id : PrecompileEnum ,
1328
+ enabled : bool ,
1329
+ ) -> DispatchResult {
1330
+ ensure_root ( origin) ?;
1331
+ if PrecompileEnable :: < T > :: get ( precompile_id) != enabled {
1332
+ PrecompileEnable :: < T > :: insert ( precompile_id, enabled) ;
1333
+ Self :: deposit_event ( Event :: PrecompileUpdated {
1334
+ precompile_id,
1335
+ enabled,
1336
+ } ) ;
1337
+ }
1338
+ // T::Grandpa::schedule_change(next_authorities, in_blocks, forced)
1339
+ Ok ( ( ) )
1340
+ }
1279
1341
}
1280
1342
}
1281
1343
0 commit comments