diff --git a/pallets/funding/src/storage_migrations.rs b/pallets/funding/src/storage_migrations.rs index 4b56512e1..cca2489d6 100644 --- a/pallets/funding/src/storage_migrations.rs +++ b/pallets/funding/src/storage_migrations.rs @@ -2,7 +2,7 @@ use frame_support::traits::StorageVersion; /// The current storage version -pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); +pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(3); pub const LOG: &str = "runtime::funding::migration"; pub mod v2 { @@ -152,3 +152,99 @@ pub mod v2 { ::DbWeight, >; } + +pub mod v3 { + use crate::{ + AccountIdOf, BalanceOf, Config, EvaluationRoundInfoOf, HRMPChannelStatus, MigrationReadinessCheck, + PhaseTransitionPoints, PriceOf, ProjectDetailsOf, ProjectStatus, + }; + use frame_support::{ + pallet_prelude::Get, + traits::{tokens::Balance as BalanceT, OnRuntimeUpgrade}, + }; + use frame_system::pallet_prelude::BlockNumberFor; + use polimec_common::credentials::Did; + use polkadot_parachain_primitives::primitives::Id as ParaId; + use scale_info::TypeInfo; + use sp_arithmetic::FixedPointNumber; + use sp_core::{Decode, Encode, MaxEncodedLen, RuntimeDebug}; + use sp_std::marker::PhantomData; + + #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] + pub struct OldProjectDetails< + AccountId, + Did, + BlockNumber, + Price: FixedPointNumber, + Balance: BalanceT, + EvaluationRoundInfo, + > { + pub issuer_account: AccountId, + pub issuer_did: Did, + /// Whether the project is frozen, so no `metadata` changes are allowed. + pub is_frozen: bool, + /// The price in USD per token decided after the Auction Round + pub weighted_average_price: Option, + /// The current status of the project + pub status: ProjectStatus, + /// When the different project phases start and end + pub phase_transition_points: PhaseTransitionPoints, + /// Fundraising target amount in USD (6 decimals) + pub fundraising_target_usd: Balance, + /// The amount of Contribution Tokens that have not yet been sold + pub remaining_contribution_tokens: Balance, + /// Funding reached amount in USD (6 decimals) + pub funding_amount_reached_usd: Balance, + /// Information about the total amount bonded, and the outcome in regards to reward/slash/nothing + pub evaluation_round_info: EvaluationRoundInfo, + /// When the Funding Round ends + pub funding_end_block: Option, + /// ParaId of project + pub parachain_id: Option, + /// Migration readiness check + pub migration_readiness_check: Option, + /// HRMP Channel status + pub hrmp_channel_status: HRMPChannelStatus, + } + type OldProjectDetailsOf = + OldProjectDetails, Did, BlockNumberFor, PriceOf, BalanceOf, EvaluationRoundInfoOf>; + + pub struct UncheckedMigrationToV3(PhantomData); + impl OnRuntimeUpgrade for UncheckedMigrationToV3 { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let mut items = 0; + let mut translate = |_key, item: OldProjectDetailsOf| -> Option> { + items += 1; + Some(ProjectDetailsOf:: { + issuer_account: item.issuer_account, + issuer_did: item.issuer_did, + is_frozen: item.is_frozen, + weighted_average_price: item.weighted_average_price, + status: item.status, + phase_transition_points: item.phase_transition_points, + fundraising_target_usd: item.fundraising_target_usd, + remaining_contribution_tokens: item.remaining_contribution_tokens, + funding_amount_reached_usd: item.funding_amount_reached_usd, + evaluation_round_info: item.evaluation_round_info, + usd_bid_on_oversubscription: None, + funding_end_block: item.funding_end_block, + parachain_id: item.parachain_id, + migration_readiness_check: item.migration_readiness_check, + hrmp_channel_status: item.hrmp_channel_status, + }) + }; + + crate::ProjectsDetails::::translate(|key, object: OldProjectDetailsOf| translate(key, object)); + + T::DbWeight::get().reads_writes(items, items) + } + } + + pub type MigrationToV3 = frame_support::migrations::VersionedMigration< + 2, + 3, + UncheckedMigrationToV3, + crate::Pallet, + ::DbWeight, + >; +} diff --git a/runtimes/polimec/src/lib.rs b/runtimes/polimec/src/lib.rs index 0c37ee098..0ff64608d 100644 --- a/runtimes/polimec/src/lib.rs +++ b/runtimes/polimec/src/lib.rs @@ -157,10 +157,11 @@ pub type Migrations = migrations::Unreleased; /// The runtime migrations per release. #[allow(missing_docs)] pub mod migrations { - use crate::{custom_migrations::init_pallet::InitializePallet, DmpQueue}; + use crate::Runtime; + /// Unreleased migrations. Add new ones here: #[allow(unused_parens)] - pub type Unreleased = (InitializePallet); + pub type Unreleased = (pallet_funding::storage_migrations::v3::MigrationToV3); } /// Executive: handles dispatch to the various modules. @@ -206,7 +207,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("polimec-mainnet"), impl_name: create_runtime_str!("polimec-mainnet"), authoring_version: 1, - spec_version: 0_007_001, + spec_version: 0_007_002, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, diff --git a/runtimes/politest/src/lib.rs b/runtimes/politest/src/lib.rs index 817ff4659..44b9cdf1d 100644 --- a/runtimes/politest/src/lib.rs +++ b/runtimes/politest/src/lib.rs @@ -166,8 +166,10 @@ pub type Migrations = migrations::Unreleased; /// The runtime migrations per release. #[allow(missing_docs)] pub mod migrations { + use crate::Runtime; + /// Unreleased migrations. Add new ones here: - pub type Unreleased = (); + pub type Unreleased = (pallet_funding::storage_migrations::v3::MigrationToV3); } /// Executive: handles dispatch to the various modules. @@ -213,7 +215,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("politest"), impl_name: create_runtime_str!("politest"), authoring_version: 1, - spec_version: 0_007_004, + spec_version: 0_007_005, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2,