Skip to content

Commit d16bba5

Browse files
committed
added new extrinsics
1 parent 54eded0 commit d16bba5

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,5 +2334,62 @@ mod dispatches {
23342334

23352335
Ok(())
23362336
}
2337+
2338+
/// Announces a coldkey swap. This is required before the coldkey swap can be performed after the delay period.
2339+
#[pallet::call_index(125)]
2340+
#[pallet::weight(Weight::zero())]
2341+
pub fn announce_coldkey_swap(
2342+
origin: OriginFor<T>,
2343+
new_coldkey: T::AccountId,
2344+
) -> DispatchResult {
2345+
let who = ensure_signed(origin)?;
2346+
let now = <frame_system::Pallet<T>>::block_number();
2347+
2348+
ColdkeySwapAnnouncements::<T>::insert(who.clone(), (now, new_coldkey.clone()));
2349+
2350+
Self::deposit_event(Event::ColdkeySwapAnnounced {
2351+
who: who.clone(),
2352+
new_coldkey: new_coldkey.clone(),
2353+
block_number: now,
2354+
});
2355+
Ok(())
2356+
}
2357+
2358+
/// Removes a coldkey swap announcement.
2359+
#[pallet::call_index(126)]
2360+
#[pallet::weight(Weight::zero())]
2361+
pub fn remove_coldkey_swap_announcement(origin: OriginFor<T>) -> DispatchResult {
2362+
let who = ensure_signed(origin)?;
2363+
2364+
ensure!(
2365+
ColdkeySwapAnnouncements::<T>::contains_key(who.clone()),
2366+
Error::<T>::ColdkeySwapAnnouncementNotFound
2367+
);
2368+
2369+
ColdkeySwapAnnouncements::<T>::remove(who.clone());
2370+
2371+
Self::deposit_event(Event::ColdkeySwapAnnouncementRemoved { who: who.clone() });
2372+
Ok(())
2373+
}
2374+
2375+
/// Performs a coldkey swap iff an announcement has been made.
2376+
#[pallet::call_index(127)]
2377+
#[pallet::weight(Weight::zero())]
2378+
pub fn coldkey_swap_announced(origin: OriginFor<T>) -> DispatchResult {
2379+
let who = ensure_signed(origin)?;
2380+
2381+
let (when, new_coldkey) = ColdkeySwapAnnouncements::<T>::take(who.clone())
2382+
.ok_or(Error::<T>::ColdkeySwapAnnouncementNotFound)?;
2383+
2384+
let now = <frame_system::Pallet<T>>::block_number();
2385+
let delay = when + ColdkeySwapScheduleDuration::<T>::get();
2386+
ensure!(now >= delay, Error::<T>::ColdkeySwapTooEarly);
2387+
2388+
Self::do_swap_coldkey(&who, &new_coldkey)?;
2389+
2390+
ColdkeySwapAnnouncements::<T>::remove(who.clone());
2391+
2392+
Ok(())
2393+
}
23372394
}
23382395
}

pallets/subtensor/src/swap/swap_coldkey.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ impl<T: Config> Pallet<T> {
4646
}
4747

4848
Self::set_last_tx_block(&new_coldkey, Self::get_current_block_as_u64());
49-
ColdkeySwapAnnouncements::<T>::remove(old_coldkey);
5049

5150
Self::deposit_event(Event::ColdkeySwapped {
5251
old_coldkey: old_coldkey.clone(),

0 commit comments

Comments
 (0)