@@ -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,37 @@ 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 neuron precompile
105
+ Neuron ,
106
+ }
107
+
108
+ #[ pallet:: type_value]
109
+ /// Default value for precompile enable
110
+ pub fn DefaultPrecompileEnabled < T : Config > ( ) -> bool {
111
+ true
112
+ }
113
+
114
+ #[ pallet:: storage]
115
+ /// Map PrecompileEnum --> enabled
116
+ pub type PrecompileEnable < T : Config > = StorageMap <
117
+ _ ,
118
+ Blake2_128Concat ,
119
+ PrecompileEnum ,
120
+ bool ,
121
+ ValueQuery ,
122
+ DefaultPrecompileEnabled < T > ,
123
+ > ;
84
124
85
125
/// Dispatchable functions allows users to interact with the pallet and invoke state changes.
86
126
#[ pallet:: call]
@@ -1307,6 +1347,36 @@ pub mod pallet {
1307
1347
pallet_subtensor:: Pallet :: < T > :: ensure_subnet_owner_or_root ( origin, netuid) ?;
1308
1348
pallet_subtensor:: Pallet :: < T > :: toggle_transfer ( netuid, toggle)
1309
1349
}
1350
+
1351
+ /// Toggles the enablement of an EVM precompile.
1352
+ ///
1353
+ /// # Arguments
1354
+ /// * `origin` - The origin of the call, which must be the root account.
1355
+ /// * `precompile_id` - The identifier of the EVM precompile to toggle.
1356
+ /// * `enabled` - The new enablement state of the precompile.
1357
+ ///
1358
+ /// # Errors
1359
+ /// * `BadOrigin` - If the caller is not the root account.
1360
+ ///
1361
+ /// # Weight
1362
+ /// Weight is handled by the `#[pallet::weight]` attribute.
1363
+ #[ pallet:: call_index( 62 ) ]
1364
+ #[ pallet:: weight( ( 0 , DispatchClass :: Operational , Pays :: No ) ) ]
1365
+ pub fn sudo_toggle_evm_precompile (
1366
+ origin : OriginFor < T > ,
1367
+ precompile_id : PrecompileEnum ,
1368
+ enabled : bool ,
1369
+ ) -> DispatchResult {
1370
+ ensure_root ( origin) ?;
1371
+ if PrecompileEnable :: < T > :: get ( precompile_id) != enabled {
1372
+ PrecompileEnable :: < T > :: insert ( precompile_id, enabled) ;
1373
+ Self :: deposit_event ( Event :: PrecompileUpdated {
1374
+ precompile_id,
1375
+ enabled,
1376
+ } ) ;
1377
+ }
1378
+ Ok ( ( ) )
1379
+ }
1310
1380
}
1311
1381
}
1312
1382
0 commit comments