difftreelog
fix foreign flags
in: master
1 file changed
pallets/foreign-assets/src/lib.rsdiffbeforeafterboth40 AssetsInHolding,40 AssetsInHolding,41};41};42use up_data_structs::{42use up_data_structs::{43 budget::ZeroBudget, CollectionId, CollectionMode, CollectionName, CollectionTokenPrefix,43 budget::ZeroBudget, CollectionFlags, CollectionId, CollectionMode, CollectionName,44 CreateCollectionData, CreateFungibleData, CreateItemData, TokenId,44 CollectionTokenPrefix, CreateCollectionData, CreateFungibleData, CreateItemData, TokenId,45};45};4646224 token_prefix,224 token_prefix,225 description,225 description,226 mode: mode.into(),226 mode: mode.into(),227 flags: CollectionFlags {228 foreign: true,229 ..Default::default()230 },227 ..Default::default()231 ..Default::default()228 },232 },229 )?;233 )?;243 #[pallet::hooks]247 #[pallet::hooks]244 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {248 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {245 fn on_runtime_upgrade() -> Weight {249 fn on_runtime_upgrade() -> Weight {250 if Self::on_chain_storage_version() < staging_xcm::v4::VERSION as u16 {251 let put_version_weight = T::DbWeight::get().writes(1);252 let fix_foreign_flag_weight = Self::fix_foreign_flag();246 Self::migrate_v3_to_v4()253 let weight_v3_to_v4 = Self::migrate_v3_to_v4();254255 StorageVersion::new(staging_xcm::v4::VERSION as u16).put::<Self>();256257 put_version_weight258 .saturating_add(fix_foreign_flag_weight)259 .saturating_add(weight_v3_to_v4)260 } else {261 Weight::zero()262 }247 }263 }248 }264 }249}265}283}299}284300285impl<T: Config> Pallet<T> {301impl<T: Config> Pallet<T> {302 fn fix_foreign_flag() -> Weight {303 let mut weight = Weight::zero();304305 for (_, collection_id) in v3_storage::ForeignAssetToCollection::<T>::iter() {306 pallet_common::CollectionById::<T>::mutate(collection_id, |collection| {307 if let Some(collection) = collection {308 collection.flags.foreign = true;309 }310 });311312 weight = weight.saturating_add(T::DbWeight::get().reads_writes(2, 1));313 }314315 weight316 }317286 fn migrate_v3_to_v4() -> Weight {318 fn migrate_v3_to_v4() -> Weight {287 if Self::on_chain_storage_version() < staging_xcm::v4::VERSION as u16 {288 let put_version_weight = T::DbWeight::get().writes(1);289 let event_weight = T::DbWeight::get().writes(1);319 let event_weight = T::DbWeight::get().writes(1);290 let collection_migration_weight = Self::migrate_collections();320 let collection_migration_weight = Self::migrate_collections();291292 StorageVersion::new(staging_xcm::v4::VERSION as u16).put::<Self>();293321294 Self::deposit_event(Event::<T>::MigrationStatus(MigrationStatus::V3ToV4(322 Self::deposit_event(Event::<T>::MigrationStatus(MigrationStatus::V3ToV4(295 MigrationStatusV3ToV4::Done,323 MigrationStatusV3ToV4::Done,296 )));324 )));297325298 put_version_weight299 .saturating_add(collection_migration_weight)326 collection_migration_weight.saturating_add(event_weight)300 .saturating_add(event_weight)301 } else {302 Weight::zero()303 }304 }327 }305328306 fn migrate_collections() -> Weight {329 fn migrate_collections() -> Weight {