@@ -363,6 +363,9 @@ pub mod pallet {
363
363
#[ pallet:: storage] // --- MAP ( hot ) --> cold | Returns the controlling coldkey for a hotkey.
364
364
pub type Owner < T : Config > =
365
365
StorageMap < _ , Blake2_128Concat , T :: AccountId , T :: AccountId , ValueQuery , DefaultAccount < T > > ;
366
+ #[ pallet:: storage] // --- MAP ( cold ) --> Vec<hot> | Returns the vector of hotkeys controlled by this coldkey.
367
+ pub type OwnedHotkeys < T : Config > =
368
+ StorageMap < _ , Blake2_128Concat , T :: AccountId , Vec < T :: AccountId > , ValueQuery > ;
366
369
#[ pallet:: storage] // --- MAP ( hot ) --> take | Returns the hotkey delegation take. And signals that this key is open for delegation.
367
370
pub type Delegates < T : Config > =
368
371
StorageMap < _ , Blake2_128Concat , T :: AccountId , u16 , ValueQuery , DefaultDefaultTake < T > > ;
@@ -377,6 +380,9 @@ pub mod pallet {
377
380
ValueQuery ,
378
381
DefaultAccountTake < T > ,
379
382
> ;
383
+ #[ pallet:: storage] // --- DMAP ( cold ) --> Vec<hot> | Maps coldkey to hotkeys that stake to it
384
+ pub type StakingHotkeys < T : Config > =
385
+ StorageMap < _ , Blake2_128Concat , T :: AccountId , Vec < T :: AccountId > , ValueQuery > ;
380
386
/// -- ITEM (switches liquid alpha on)
381
387
#[ pallet:: type_value]
382
388
pub fn DefaultLiquidAlpha < T : Config > ( ) -> bool {
@@ -1204,6 +1210,13 @@ pub mod pallet {
1204
1210
// Fill stake information.
1205
1211
Owner :: < T > :: insert ( hotkey. clone ( ) , coldkey. clone ( ) ) ;
1206
1212
1213
+ // Update OwnedHotkeys map
1214
+ let mut hotkeys = OwnedHotkeys :: < T > :: get ( coldkey) ;
1215
+ if !hotkeys. contains ( hotkey) {
1216
+ hotkeys. push ( hotkey. clone ( ) ) ;
1217
+ OwnedHotkeys :: < T > :: insert ( coldkey, hotkeys) ;
1218
+ }
1219
+
1207
1220
TotalHotkeyStake :: < T > :: insert ( hotkey. clone ( ) , stake) ;
1208
1221
TotalColdkeyStake :: < T > :: insert (
1209
1222
coldkey. clone ( ) ,
@@ -1215,6 +1228,13 @@ pub mod pallet {
1215
1228
1216
1229
Stake :: < T > :: insert ( hotkey. clone ( ) , coldkey. clone ( ) , stake) ;
1217
1230
1231
+ // Update StakingHotkeys map
1232
+ let mut staking_hotkeys = StakingHotkeys :: < T > :: get ( coldkey) ;
1233
+ if !staking_hotkeys. contains ( hotkey) {
1234
+ staking_hotkeys. push ( hotkey. clone ( ) ) ;
1235
+ StakingHotkeys :: < T > :: insert ( coldkey, staking_hotkeys) ;
1236
+ }
1237
+
1218
1238
next_uid = next_uid. checked_add ( 1 ) . expect (
1219
1239
"should not have total number of hotkey accounts larger than u16::MAX" ,
1220
1240
) ;
@@ -1325,7 +1345,11 @@ pub mod pallet {
1325
1345
// Storage version v4 -> v5
1326
1346
. saturating_add ( migration:: migrate_delete_subnet_3 :: < T > ( ) )
1327
1347
// Doesn't check storage version. TODO: Remove after upgrade
1328
- . saturating_add ( migration:: migration5_total_issuance :: < T > ( false ) ) ;
1348
+ . saturating_add ( migration:: migration5_total_issuance :: < T > ( false ) )
1349
+ // Populate OwnedHotkeys map for coldkey swap. Doesn't update storage vesion.
1350
+ . saturating_add ( migration:: migrate_populate_owned :: < T > ( ) )
1351
+ // Populate StakingHotkeys map for coldkey swap. Doesn't update storage vesion.
1352
+ . saturating_add ( migration:: migrate_populate_staking_hotkeys :: < T > ( ) ) ;
1329
1353
1330
1354
weight
1331
1355
}
@@ -1970,6 +1994,60 @@ pub mod pallet {
1970
1994
Self :: do_swap_hotkey ( origin, & hotkey, & new_hotkey)
1971
1995
}
1972
1996
1997
+ /// The extrinsic for user to change the coldkey associated with their account.
1998
+ ///
1999
+ /// # Arguments
2000
+ ///
2001
+ /// * `origin` - The origin of the call, must be signed by the old coldkey.
2002
+ /// * `old_coldkey` - The current coldkey associated with the account.
2003
+ /// * `new_coldkey` - The new coldkey to be associated with the account.
2004
+ ///
2005
+ /// # Returns
2006
+ ///
2007
+ /// Returns a `DispatchResultWithPostInfo` indicating success or failure of the operation.
2008
+ ///
2009
+ /// # Weight
2010
+ ///
2011
+ /// Weight is calculated based on the number of database reads and writes.
2012
+ #[ pallet:: call_index( 71 ) ]
2013
+ #[ pallet:: weight( ( Weight :: from_parts( 1_940_000_000 , 0 )
2014
+ . saturating_add( T :: DbWeight :: get( ) . reads( 272 ) )
2015
+ . saturating_add( T :: DbWeight :: get( ) . writes( 527 ) ) , DispatchClass :: Operational , Pays :: No ) ) ]
2016
+ pub fn swap_coldkey (
2017
+ origin : OriginFor < T > ,
2018
+ old_coldkey : T :: AccountId ,
2019
+ new_coldkey : T :: AccountId ,
2020
+ ) -> DispatchResultWithPostInfo {
2021
+ Self :: do_swap_coldkey ( origin, & old_coldkey, & new_coldkey)
2022
+ }
2023
+
2024
+ /// Unstakes all tokens associated with a hotkey and transfers them to a new coldkey.
2025
+ ///
2026
+ /// # Arguments
2027
+ ///
2028
+ /// * `origin` - The origin of the call, must be signed by the current coldkey.
2029
+ /// * `hotkey` - The hotkey associated with the stakes to be unstaked.
2030
+ /// * `new_coldkey` - The new coldkey to receive the unstaked tokens.
2031
+ ///
2032
+ /// # Returns
2033
+ ///
2034
+ /// Returns a `DispatchResult` indicating success or failure of the operation.
2035
+ ///
2036
+ /// # Weight
2037
+ ///
2038
+ /// Weight is calculated based on the number of database reads and writes.
2039
+ #[ pallet:: call_index( 72 ) ]
2040
+ #[ pallet:: weight( ( Weight :: from_parts( 1_940_000_000 , 0 )
2041
+ . saturating_add( T :: DbWeight :: get( ) . reads( 272 ) )
2042
+ . saturating_add( T :: DbWeight :: get( ) . writes( 527 ) ) , DispatchClass :: Operational , Pays :: No ) ) ]
2043
+ pub fn unstake_all_and_transfer_to_new_coldkey (
2044
+ origin : OriginFor < T > ,
2045
+ new_coldkey : T :: AccountId ,
2046
+ ) -> DispatchResult {
2047
+ let current_coldkey = ensure_signed ( origin) ?;
2048
+ Self :: do_unstake_all_and_transfer_to_new_coldkey ( current_coldkey, new_coldkey)
2049
+ }
2050
+
1973
2051
// ---- SUDO ONLY FUNCTIONS ------------------------------------------------------------
1974
2052
1975
2053
// ==================================
0 commit comments