@@ -139,6 +139,7 @@ impl<T: Config> Pallet<T> {
139
139
) ;
140
140
Self :: swap_subnet_owner_for_coldkey ( old_coldkey, new_coldkey, & mut weight) ;
141
141
Self :: swap_owned_for_coldkey ( old_coldkey, new_coldkey, & mut weight) ;
142
+ Self :: swap_staking_hotkeys_for_coldkey ( old_coldkey, new_coldkey, & mut weight) ;
142
143
143
144
// Transfer any remaining balance from old_coldkey to new_coldkey
144
145
let remaining_balance = Self :: get_coldkey_balance ( old_coldkey) ;
@@ -531,13 +532,36 @@ impl<T: Config> Pallet<T> {
531
532
let stake = Stake :: < T > :: get ( & hotkey, old_coldkey) ;
532
533
Stake :: < T > :: remove ( & hotkey, old_coldkey) ;
533
534
Stake :: < T > :: insert ( & hotkey, new_coldkey, stake) ;
535
+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 2 ) ) ;
536
+ }
537
+ }
534
538
535
- // Update StakingHotkeys map
536
- let staking_hotkeys = StakingHotkeys :: < T > :: get ( old_coldkey) ;
537
- StakingHotkeys :: < T > :: insert ( new_coldkey. clone ( ) , staking_hotkeys) ;
539
+ /// Swaps all staking hotkeys associated with a coldkey from the old coldkey to the new coldkey.
540
+ ///
541
+ /// # Arguments
542
+ ///
543
+ /// * `old_coldkey` - The AccountId of the old coldkey.
544
+ /// * `new_coldkey` - The AccountId of the new coldkey.
545
+ /// * `weight` - Mutable reference to the weight of the transaction.
546
+ ///
547
+ /// # Effects
548
+ ///
549
+ /// * Removes all stakes associated with the old coldkey.
550
+ /// * Inserts all stakes for the new coldkey.
551
+ /// * Updates the transaction weight.
552
+ pub fn swap_staking_hotkeys_for_coldkey (
553
+ old_coldkey : & T :: AccountId ,
554
+ new_coldkey : & T :: AccountId ,
555
+ weight : & mut Weight ,
556
+ ) {
557
+ // Find all hotkeys for this coldkey
558
+ let hotkeys = OwnedHotkeys :: < T > :: get ( old_coldkey) ;
538
559
539
- weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 3 ) ) ;
540
- }
560
+ // Update StakingHotkeys map
561
+ OwnedHotkeys :: < T > :: remove ( old_coldkey) ;
562
+ StakingHotkeys :: < T > :: insert ( new_coldkey. clone ( ) , hotkeys) ;
563
+
564
+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 2 ) ) ;
541
565
}
542
566
543
567
/// Swaps the owner of all hotkeys from the old coldkey to the new coldkey.
0 commit comments