git.delta.rocks / unique-network / refs/commits / 583a28bcbcc8

difftreelog

refactor(foreign-asset) remove migration

Yaroslav Bolyukin2023-03-24parent: #c177614.patch.diff
in: master

2 files changed

modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
202 accounts: BTreeMap::new(),202 accounts: BTreeMap::new(),
203 },203 },
204 ethereum: EthereumConfig {},204 ethereum: EthereumConfig {},
205 foreign_assets: Default::default(),
206 polkadot_xcm: Default::default(),205 polkadot_xcm: Default::default(),
207 transaction_payment: Default::default(),206 transaction_payment: Default::default(),
208 }207 }
255 accounts: BTreeMap::new(),254 accounts: BTreeMap::new(),
256 },255 },
257 ethereum: EthereumConfig {},256 ethereum: EthereumConfig {},
258 foreign_assets: Default::default(),
259 polkadot_xcm: Default::default(),257 polkadot_xcm: Default::default(),
260 transaction_payment: Default::default(),258 transaction_payment: Default::default(),
261 }259 }
modifiedpallets/foreign-assets/src/lib.rsdiffbeforeafterboth
276 StorageMap<_, Twox64Concat, ForeignAssetId, CollectionId, OptionQuery>;276 StorageMap<_, Twox64Concat, ForeignAssetId, CollectionId, OptionQuery>;
277277
278 #[pallet::pallet]278 #[pallet::pallet]
279 #[pallet::without_storage_info]
280 pub struct Pallet<T>(_);279 pub struct Pallet<T>(_);
281
282 pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
283 #[pallet::hooks]
284 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
285 fn on_runtime_upgrade() -> Weight {
286 let mut weight = Weight::default();
287 // 0-1 -- xcmv2 => xcmv3
288 if StorageVersion::get::<Pallet<T>>() <= 0 {
289 pub trait V0ToV1 {
290 type Pallet: 'static + PalletInfoAccess;
291 }
292 #[frame_support::storage_alias]
293 type LocationToCurrencyIds<T: Config> =
294 StorageMap<Pallet<T>, Twox64Concat, xcm::v2::MultiLocation, ForeignAssetId>;
295 <ForeignAssetLocations<T>>::translate_values::<xcm::v2::MultiLocation, _>(|loc| {
296 weight += T::DbWeight::get().reads_writes(1, 1);
297 Some(
298 xcm::v3::MultiLocation::try_from(loc)
299 .expect("failed to migrate multilocation from XCMv2 to XCMv3"),
300 )
301 });
302
303 let old_values: Vec<(xcm::v2::MultiLocation, _)> =
304 <LocationToCurrencyIds<T>>::drain().collect();
305 weight += T::DbWeight::get()
306 .reads_writes(old_values.len() as u64, old_values.len() as u64);
307 for (loc, asset_id) in old_values {
308 let loc = xcm::v3::MultiLocation::try_from(loc)
309 .expect("failed to migrate multilocation from XCMv2 to XCMv3");
310 <crate::LocationToCurrencyIds<T>>::insert(loc, asset_id);
311 }
312 }
313 STORAGE_VERSION.put::<Pallet<T>>();
314 weight += T::DbWeight::get().writes(1);
315 weight
316 }
317 }
318
319 #[pallet::genesis_config]
320 pub struct GenesisConfig;
321
322 #[cfg(feature = "std")]
323 impl Default for GenesisConfig {
324 fn default() -> Self {
325 Self
326 }
327 }
328
329 #[pallet::genesis_build]
330 impl<T: Config> GenesisBuild<T> for GenesisConfig {
331 fn build(&self) {
332 STORAGE_VERSION.put::<Pallet<T>>();
333 }
334 }
335280
336 #[pallet::call]281 #[pallet::call]
337 impl<T: Config> Pallet<T> {282 impl<T: Config> Pallet<T> {