Skip to content

Commit

Permalink
fix trait
Browse files Browse the repository at this point in the history
  • Loading branch information
1xstj committed Jan 13, 2025
1 parent f20d3ed commit 3a90ba4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
6 changes: 1 addition & 5 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,11 +1451,7 @@ pub type Executive = frame_executive::Executive<
// 1000 - 50000 (reserved for LST pools)
// 50000 - 1000000 (reserved for native assets)
// set user start at 50_000, everything below is reserved for system use
pallet_assets::migration::next_asset_id::SetNextAssetId<
ConstU32<50_000>,
Runtime,
TrustBackedAssetsInstance,
>,
migrations::SetNextAssetId<ConstU128<50_000>, Runtime>,
),
>;

Expand Down
19 changes: 19 additions & 0 deletions runtime/mainnet/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::*;
use frame_support::traits::Incrementable;
use frame_support::traits::OnRuntimeUpgrade;
use pallet_assets::NextAssetId;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use sp_runtime::{BoundToRuntimeAppPublic, RuntimeAppPublic, RuntimeDebug};

Expand Down Expand Up @@ -69,3 +71,20 @@ impl<T: pallet_session::Config> OnRuntimeUpgrade for MigrateSessionKeys<T> {
T::DbWeight::get().reads_writes(10, 10)
}
}

/// Set [`NextAssetId`] to the value of `ID` if [`NextAssetId`] does not exist yet.
pub struct SetNextAssetId<ID, T: pallet_assets::Config>(core::marker::PhantomData<(ID, T)>);
impl<ID, T: pallet_assets::Config> OnRuntimeUpgrade for SetNextAssetId<ID, T>
where
T::AssetId: Incrementable,
ID: Get<T::AssetId>,
{
fn on_runtime_upgrade() -> frame_support::weights::Weight {
if !NextAssetId::<T>::exists() {
NextAssetId::<T>::put(ID::get());
T::DbWeight::get().reads_writes(1, 1)
} else {
T::DbWeight::get().reads(1)
}
}
}
6 changes: 1 addition & 5 deletions runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,11 +1362,7 @@ pub type Executive = frame_executive::Executive<
// 1000 - 50000 (reserved for LST pools)
// 50000 - 1000000 (reserved for native assets)
// set user start at 50_000, everything below is reserved for system use
pallet_assets::migration::next_asset_id::SetNextAssetId<
ConstU32<50_000>,
Runtime,
TrustBackedAssetsInstance,
>,
migrations::SetNextAssetId<ConstU128<50_000>, Runtime>,
),
>;

Expand Down
19 changes: 19 additions & 0 deletions runtime/testnet/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::*;
use frame_support::traits::Incrementable;
use frame_support::traits::OnRuntimeUpgrade;
use pallet_assets::NextAssetId;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use sp_runtime::{BoundToRuntimeAppPublic, RuntimeAppPublic, RuntimeDebug};

Expand Down Expand Up @@ -69,3 +71,20 @@ impl<T: pallet_session::Config> OnRuntimeUpgrade for MigrateSessionKeys<T> {
T::DbWeight::get().reads_writes(10, 10)
}
}

/// Set [`NextAssetId`] to the value of `ID` if [`NextAssetId`] does not exist yet.
pub struct SetNextAssetId<ID, T: pallet_assets::Config>(core::marker::PhantomData<(ID, T)>);
impl<ID, T: pallet_assets::Config> OnRuntimeUpgrade for SetNextAssetId<ID, T>
where
T::AssetId: Incrementable,
ID: Get<T::AssetId>,
{
fn on_runtime_upgrade() -> frame_support::weights::Weight {
if !NextAssetId::<T>::exists() {
NextAssetId::<T>::put(ID::get());
T::DbWeight::get().reads_writes(1, 1)
} else {
T::DbWeight::get().reads(1)
}
}
}

0 comments on commit 3a90ba4

Please sign in to comment.