@@ -363,6 +363,9 @@ pub mod pallet {
363363 #[ pallet:: storage] // --- MAP ( hot ) --> cold | Returns the controlling coldkey for a hotkey.
364364 pub type Owner < T : Config > =
365365 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 Owned < T : Config > =
368+ StorageMap < _ , Blake2_128Concat , T :: AccountId , Vec < T :: AccountId > , ValueQuery > ;
366369 #[ pallet:: storage] // --- MAP ( hot ) --> take | Returns the hotkey delegation take. And signals that this key is open for delegation.
367370 pub type Delegates < T : Config > =
368371 StorageMap < _ , Blake2_128Concat , T :: AccountId , u16 , ValueQuery , DefaultDefaultTake < T > > ;
@@ -1204,6 +1207,14 @@ pub mod pallet {
12041207 // Fill stake information.
12051208 Owner :: < T > :: insert ( hotkey. clone ( ) , coldkey. clone ( ) ) ;
12061209
1210+ // Update Owned map
1211+ let mut hotkeys = Owned :: < T > :: get ( & coldkey) ;
1212+ hotkeys. push ( hotkey. clone ( ) ) ;
1213+ Owned :: < T > :: insert (
1214+ & coldkey,
1215+ hotkeys,
1216+ ) ;
1217+
12071218 TotalHotkeyStake :: < T > :: insert ( hotkey. clone ( ) , stake) ;
12081219 TotalColdkeyStake :: < T > :: insert (
12091220 coldkey. clone ( ) ,
@@ -1325,7 +1336,9 @@ pub mod pallet {
13251336 // Storage version v4 -> v5
13261337 . saturating_add ( migration:: migrate_delete_subnet_3 :: < T > ( ) )
13271338 // Doesn't check storage version. TODO: Remove after upgrade
1328- . saturating_add ( migration:: migration5_total_issuance :: < T > ( false ) ) ;
1339+ . saturating_add ( migration:: migration5_total_issuance :: < T > ( false ) )
1340+ // Populate Owned map for coldkey swap. Doesn't update storage vesion.
1341+ . saturating_add ( migration:: migrate_populate_owned :: < T > ( ) ) ;
13291342
13301343 weight
13311344 }
@@ -1970,6 +1983,19 @@ pub mod pallet {
19701983 Self :: do_swap_hotkey ( origin, & hotkey, & new_hotkey)
19711984 }
19721985
1986+ /// The extrinsic for user to change the coldkey
1987+ #[ pallet:: call_index( 71 ) ]
1988+ #[ pallet:: weight( ( Weight :: from_parts( 1_940_000_000 , 0 )
1989+ . saturating_add( T :: DbWeight :: get( ) . reads( 272 ) )
1990+ . saturating_add( T :: DbWeight :: get( ) . writes( 527 ) ) , DispatchClass :: Operational , Pays :: No ) ) ]
1991+ pub fn swap_coldkey (
1992+ origin : OriginFor < T > ,
1993+ old_coldkey : T :: AccountId ,
1994+ new_coldkey : T :: AccountId ,
1995+ ) -> DispatchResultWithPostInfo {
1996+ Self :: do_swap_coldkey ( origin, & old_coldkey, & new_coldkey)
1997+ }
1998+
19731999 // ---- SUDO ONLY FUNCTIONS ------------------------------------------------------------
19742000
19752001 // ==================================
0 commit comments