Skip to content

Commit

Permalink
migration v1 doesn't depend on v2 anymore
Browse files Browse the repository at this point in the history
Signed-off-by: muraca <mmuraca247@gmail.com>
  • Loading branch information
muraca committed Oct 23, 2023
1 parent 7161328 commit 2f1cfe7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
40 changes: 33 additions & 7 deletions substrate/frame/assets/src/migration/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{
migration::v2::old::{Asset, AssetDetails},
AssetStatus, Config, DepositBalanceOf, Pallet, LOG_TARGET,
};
use crate::{AssetStatus, Config, DepositBalanceOf, Pallet, LOG_TARGET};
use frame_support::{
pallet_prelude::*, sp_runtime::traits::Saturating, traits::OnRuntimeUpgrade, weights::Weight,
};
Expand Down Expand Up @@ -72,6 +69,35 @@ mod old {
}
}

#[frame_support::storage_alias]
/// Details of an asset.
pub(crate) type Asset<T: Config<I>, I: 'static> = StorageMap<
Pallet<T, I>,
Blake2_128Concat,
<T as Config<I>>::AssetId,
AssetDetails<
<T as Config<I>>::Balance,
<T as frame_system::Config>::AccountId,
DepositBalanceOf<T, I>,
>,
>;

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub(crate) struct AssetDetails<Balance, AccountId, DepositBalance> {
pub owner: AccountId,
pub issuer: AccountId,
pub admin: AccountId,
pub freezer: AccountId,
pub supply: Balance,
pub deposit: DepositBalance,
pub min_balance: Balance,
pub is_sufficient: bool,
pub accounts: u32,
pub sufficients: u32,
pub approvals: u32,
pub status: AssetStatus,
}

pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
fn on_runtime_upgrade() -> Weight {
Expand Down Expand Up @@ -134,9 +160,9 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {

Asset::<T, ()>::iter().try_for_each(|(_id, asset)| -> Result<(), TryRuntimeError> {
ensure!(
asset.status == AssetStatus::Live || asset.status == AssetStatus::Frozen,
"assets should only be live or frozen. None should be in destroying status, or undefined state"
);
asset.status == AssetStatus::Live || asset.status == AssetStatus::Frozen,
"assets should only be live or frozen. None should be in destroying status, or undefined state"
);
Ok(())
})?;
Ok(())
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/assets/src/migration/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub mod old {
}
}
}

/// This migration moves all the state to v2 of Assets
pub struct VersionUncheckedMigrateToV2<
T: Config<I>,
Expand Down

0 comments on commit 2f1cfe7

Please sign in to comment.