use super::*; use crate::AccountIdOf; use frame_support::{ pallet_prelude::{Blake2_128Concat, ValueQuery}, storage_alias, traits::Get, weights::Weight, }; pub use frame_system::pallet_prelude::BlockNumberFor; use scale_info::prelude::string::String; /// Module containing deprecated storage format for LoadedEmission pub mod deprecated_coldkey_swap_scheduled_format { use super::*; #[storage_alias] pub(super) type ColdkeySwapScheduled = StorageMap, Blake2_128Concat, AccountIdOf, (), ValueQuery>; } /// Migrate the ColdkeySwapScheduled map to the new storage format pub fn migrate_coldkey_swap_scheduled() -> Weight { use deprecated_coldkey_swap_scheduled_format as old; let migration_name = b"migrate_coldkey_swap_scheduled".to_vec(); let mut weight = T::DbWeight::get().reads(1); if HasMigrationRun::::get(&migration_name) { log::info!( "Migration '{:?}' has already run. Skipping.", String::from_utf8_lossy(&migration_name) ); return weight; } log::info!( "Running migration '{}'", String::from_utf8_lossy(&migration_name) ); // ------------------------------ // Step 1: Migrate ColdkeySwapScheduled map // ------------------------------ let curr_keys: Vec> = old::ColdkeySwapScheduled::::iter_keys().collect(); // Remove any undecodable entries for coldkey in &curr_keys { weight.saturating_accrue(T::DbWeight::get().reads(1)); if old::ColdkeySwapScheduled::::try_get(coldkey).is_err() { old::ColdkeySwapScheduled::::remove(coldkey); log::warn!( "Was unable to decode old coldkey_swap_scheduled for coldkey {:?}", &coldkey ); } } // ------------------------------ // Step 2: Mark Migration as Completed // ------------------------------ HasMigrationRun::::insert(&migration_name, true); weight = weight.saturating_add(T::DbWeight::get().writes(1)); log::info!( "Migration '{:?}' completed successfully.", String::from_utf8_lossy(&migration_name) ); weight }