@@ -4,42 +4,18 @@ use frame_support::{traits::Get, weights::Weight};
44use sp_core:: crypto:: Ss58Codec ;
55use sp_runtime:: AccountId32 ;
66
7- fn swap_pending_emissions < T : Config > (
8- old_hotkey : & T :: AccountId ,
9- new_hotkey : & T :: AccountId ,
10- ) -> Weight {
11- let mut weight = T :: DbWeight :: get ( ) . reads ( 0 ) ;
12-
13- // Get the pending emissions for the old hotkey
14- let pending_emissions = PendingdHotkeyEmission :: < T > :: get ( old_hotkey) ;
15- weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
16-
17- // Remove the pending emissions for the old hotkey
18- PendingdHotkeyEmission :: < T > :: remove ( old_hotkey) ;
19- weight. saturating_accrue ( T :: DbWeight :: get ( ) . writes ( 1 ) ) ;
20-
21- // Get any existing pending emissions for the new hotkey
22- let existing_new_pending_emissions = PendingdHotkeyEmission :: < T > :: get ( new_hotkey) ;
23- weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
24-
25- // Add the pending emissions for the new hotkey
26- PendingdHotkeyEmission :: < T > :: insert (
27- new_hotkey,
28- pending_emissions. saturating_add ( existing_new_pending_emissions) ,
29- ) ;
30- weight. saturating_accrue ( T :: DbWeight :: get ( ) . writes ( 1 ) ) ;
31-
32- weight
33- }
34-
357fn get_account_id_from_ss58 < T : Config > ( ss58_str : & str ) -> T :: AccountId {
368 let account = AccountId32 :: from_ss58check ( ss58_str) . unwrap ( ) ;
379 let onchain_account = T :: AccountId :: decode ( & mut account. as_ref ( ) ) . unwrap ( ) ;
3810
3911 onchain_account
4012}
4113
42- fn unstake_old_hotkey_and_move_to_pending < T : Config > (
14+ /**
15+ * Migrates the pending emissions from the old hotkey to the new hotkey.
16+ * Also migrates the stake entry of (old_hotkey, 0x000) to the pending emissions of the new hotkey.
17+ */
18+ fn migrate_pending_emissions_including_null_stake < T : Config > (
4319 old_hotkey : & T :: AccountId ,
4420 new_hotkey : & T :: AccountId ,
4521) -> Weight {
@@ -104,7 +80,7 @@ pub fn do_migrate_fix_pending_emission<T: Config>() -> Weight {
10480 let taostats_old_hk_account: T :: AccountId = get_account_id_from_ss58 :: < T > ( taostats_old_hotkey) ;
10581 let taostats_new_hk_account: T :: AccountId = get_account_id_from_ss58 :: < T > ( taostats_new_hotkey) ;
10682
107- weight. saturating_accrue ( unstake_old_hotkey_and_move_to_pending :: < T > (
83+ weight. saturating_accrue ( migrate_pending_emissions_including_null_stake :: < T > (
10884 & taostats_old_hk_account,
10985 & taostats_new_hk_account,
11086 ) ) ;
@@ -115,7 +91,7 @@ pub fn do_migrate_fix_pending_emission<T: Config>() -> Weight {
11591 let datura_old_hk_account: T :: AccountId = get_account_id_from_ss58 :: < T > ( datura_old_hotkey) ;
11692 let datura_new_hk_account: T :: AccountId = get_account_id_from_ss58 :: < T > ( datura_new_hotkey) ;
11793
118- weight. saturating_accrue ( swap_pending_emissions :: < T > (
94+ weight. saturating_accrue ( migrate_pending_emissions_including_null_stake :: < T > (
11995 & datura_old_hk_account,
12096 & datura_new_hk_account,
12197 ) ) ;
0 commit comments