@@ -4,42 +4,18 @@ use frame_support::{traits::Get, weights::Weight};
4
4
use sp_core:: crypto:: Ss58Codec ;
5
5
use sp_runtime:: AccountId32 ;
6
6
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
-
35
7
fn get_account_id_from_ss58 < T : Config > ( ss58_str : & str ) -> T :: AccountId {
36
8
let account = AccountId32 :: from_ss58check ( ss58_str) . unwrap ( ) ;
37
9
let onchain_account = T :: AccountId :: decode ( & mut account. as_ref ( ) ) . unwrap ( ) ;
38
10
39
11
onchain_account
40
12
}
41
13
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 > (
43
19
old_hotkey : & T :: AccountId ,
44
20
new_hotkey : & T :: AccountId ,
45
21
) -> Weight {
@@ -104,7 +80,7 @@ pub fn do_migrate_fix_pending_emission<T: Config>() -> Weight {
104
80
let taostats_old_hk_account: T :: AccountId = get_account_id_from_ss58 :: < T > ( taostats_old_hotkey) ;
105
81
let taostats_new_hk_account: T :: AccountId = get_account_id_from_ss58 :: < T > ( taostats_new_hotkey) ;
106
82
107
- weight. saturating_accrue ( unstake_old_hotkey_and_move_to_pending :: < T > (
83
+ weight. saturating_accrue ( migrate_pending_emissions_including_null_stake :: < T > (
108
84
& taostats_old_hk_account,
109
85
& taostats_new_hk_account,
110
86
) ) ;
@@ -115,7 +91,7 @@ pub fn do_migrate_fix_pending_emission<T: Config>() -> Weight {
115
91
let datura_old_hk_account: T :: AccountId = get_account_id_from_ss58 :: < T > ( datura_old_hotkey) ;
116
92
let datura_new_hk_account: T :: AccountId = get_account_id_from_ss58 :: < T > ( datura_new_hotkey) ;
117
93
118
- weight. saturating_accrue ( swap_pending_emissions :: < T > (
94
+ weight. saturating_accrue ( migrate_pending_emissions_including_null_stake :: < T > (
119
95
& datura_old_hk_account,
120
96
& datura_new_hk_account,
121
97
) ) ;
0 commit comments