@@ -60,6 +60,16 @@ impl<T: Config> Pallet<T> {
6060 T :: DbWeight :: get ( ) . reads ( ( TotalNetworks :: < T > :: get ( ) . saturating_add ( 1u16 ) ) as u64 ) ,
6161 ) ;
6262
63+ let swap_cost = Self :: get_hotkey_swap_cost ( ) ;
64+ log:: debug!( "Swap cost: {:?}" , swap_cost) ;
65+
66+ ensure ! (
67+ Self :: can_remove_balance_from_coldkey_account( & coldkey, swap_cost) ,
68+ Error :: <T >:: NotEnoughBalanceToPaySwapHotKey
69+ ) ;
70+ let actual_burn_amount = Self :: remove_balance_from_coldkey_account ( & coldkey, swap_cost) ?;
71+ Self :: burn_tokens ( actual_burn_amount) ;
72+
6373 Self :: swap_owner ( old_hotkey, new_hotkey, & coldkey, & mut weight) ;
6474 Self :: swap_total_hotkey_stake ( old_hotkey, new_hotkey, & mut weight) ;
6575 Self :: swap_delegates ( old_hotkey, new_hotkey, & mut weight) ;
@@ -76,7 +86,6 @@ impl<T: Config> Pallet<T> {
7686 Self :: swap_prometheus ( old_hotkey, new_hotkey, & netuid_is_member, & mut weight) ;
7787
7888 Self :: swap_total_hotkey_coldkey_stakes_this_interval ( old_hotkey, new_hotkey, & mut weight) ;
79- Self :: swap_senate_member ( old_hotkey, new_hotkey, & mut weight) ?;
8089
8190 Self :: set_last_tx_block ( & coldkey, block) ;
8291 weight. saturating_accrue ( T :: DbWeight :: get ( ) . writes ( 1 ) ) ;
@@ -950,15 +959,15 @@ impl<T: Config> Pallet<T> {
950959 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( TotalNetworks :: < T > :: get ( ) as u64 ) ) ;
951960 }
952961
953- /// Swaps the Senate membership from the old hotkey to the new hotkey if applicable.
954962 pub fn swap_senate_member (
955963 old_hotkey : & T :: AccountId ,
956964 new_hotkey : & T :: AccountId ,
957965 weight : & mut Weight ,
958966 ) -> DispatchResult {
967+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
959968 if T :: SenateMembers :: is_member ( old_hotkey) {
960969 T :: SenateMembers :: swap_member ( old_hotkey, new_hotkey) . map_err ( |e| e. error ) ?;
961- weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 2 ) ) ;
970+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 2 ) ) ;
962971 }
963972 Ok ( ( ) )
964973 }
0 commit comments