|
2 | 2 | use frame_support::traits::StorageVersion;
|
3 | 3 |
|
4 | 4 | /// The current storage version
|
5 |
| -pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); |
| 5 | +pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(3); |
6 | 6 | pub const LOG: &str = "runtime::funding::migration";
|
7 | 7 |
|
8 | 8 | pub mod v2 {
|
@@ -152,3 +152,99 @@ pub mod v2 {
|
152 | 152 | <T as frame_system::Config>::DbWeight,
|
153 | 153 | >;
|
154 | 154 | }
|
| 155 | + |
| 156 | +pub mod v3 { |
| 157 | + use crate::{ |
| 158 | + AccountIdOf, BalanceOf, Config, EvaluationRoundInfoOf, HRMPChannelStatus, MigrationReadinessCheck, |
| 159 | + PhaseTransitionPoints, PriceOf, ProjectDetailsOf, ProjectStatus, |
| 160 | + }; |
| 161 | + use frame_support::{ |
| 162 | + pallet_prelude::Get, |
| 163 | + traits::{tokens::Balance as BalanceT, OnRuntimeUpgrade}, |
| 164 | + }; |
| 165 | + use frame_system::pallet_prelude::BlockNumberFor; |
| 166 | + use polimec_common::credentials::Did; |
| 167 | + use polkadot_parachain_primitives::primitives::Id as ParaId; |
| 168 | + use scale_info::TypeInfo; |
| 169 | + use sp_arithmetic::FixedPointNumber; |
| 170 | + use sp_core::{Decode, Encode, MaxEncodedLen, RuntimeDebug}; |
| 171 | + use sp_std::marker::PhantomData; |
| 172 | + |
| 173 | + #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] |
| 174 | + pub struct OldProjectDetails< |
| 175 | + AccountId, |
| 176 | + Did, |
| 177 | + BlockNumber, |
| 178 | + Price: FixedPointNumber, |
| 179 | + Balance: BalanceT, |
| 180 | + EvaluationRoundInfo, |
| 181 | + > { |
| 182 | + pub issuer_account: AccountId, |
| 183 | + pub issuer_did: Did, |
| 184 | + /// Whether the project is frozen, so no `metadata` changes are allowed. |
| 185 | + pub is_frozen: bool, |
| 186 | + /// The price in USD per token decided after the Auction Round |
| 187 | + pub weighted_average_price: Option<Price>, |
| 188 | + /// The current status of the project |
| 189 | + pub status: ProjectStatus, |
| 190 | + /// When the different project phases start and end |
| 191 | + pub phase_transition_points: PhaseTransitionPoints<BlockNumber>, |
| 192 | + /// Fundraising target amount in USD (6 decimals) |
| 193 | + pub fundraising_target_usd: Balance, |
| 194 | + /// The amount of Contribution Tokens that have not yet been sold |
| 195 | + pub remaining_contribution_tokens: Balance, |
| 196 | + /// Funding reached amount in USD (6 decimals) |
| 197 | + pub funding_amount_reached_usd: Balance, |
| 198 | + /// Information about the total amount bonded, and the outcome in regards to reward/slash/nothing |
| 199 | + pub evaluation_round_info: EvaluationRoundInfo, |
| 200 | + /// When the Funding Round ends |
| 201 | + pub funding_end_block: Option<BlockNumber>, |
| 202 | + /// ParaId of project |
| 203 | + pub parachain_id: Option<ParaId>, |
| 204 | + /// Migration readiness check |
| 205 | + pub migration_readiness_check: Option<MigrationReadinessCheck>, |
| 206 | + /// HRMP Channel status |
| 207 | + pub hrmp_channel_status: HRMPChannelStatus, |
| 208 | + } |
| 209 | + type OldProjectDetailsOf<T> = |
| 210 | + OldProjectDetails<AccountIdOf<T>, Did, BlockNumberFor<T>, PriceOf<T>, BalanceOf<T>, EvaluationRoundInfoOf<T>>; |
| 211 | + |
| 212 | + pub struct UncheckedMigrationToV3<T: Config>(PhantomData<T>); |
| 213 | + impl<T: Config> OnRuntimeUpgrade for UncheckedMigrationToV3<T> { |
| 214 | + fn on_runtime_upgrade() -> frame_support::weights::Weight { |
| 215 | + let mut items = 0; |
| 216 | + let mut translate = |_key, item: OldProjectDetailsOf<T>| -> Option<ProjectDetailsOf<T>> { |
| 217 | + items += 1; |
| 218 | + Some(ProjectDetailsOf::<T> { |
| 219 | + issuer_account: item.issuer_account, |
| 220 | + issuer_did: item.issuer_did, |
| 221 | + is_frozen: item.is_frozen, |
| 222 | + weighted_average_price: item.weighted_average_price, |
| 223 | + status: item.status, |
| 224 | + phase_transition_points: item.phase_transition_points, |
| 225 | + fundraising_target_usd: item.fundraising_target_usd, |
| 226 | + remaining_contribution_tokens: item.remaining_contribution_tokens, |
| 227 | + funding_amount_reached_usd: item.funding_amount_reached_usd, |
| 228 | + evaluation_round_info: item.evaluation_round_info, |
| 229 | + usd_bid_on_oversubscription: None, |
| 230 | + funding_end_block: item.funding_end_block, |
| 231 | + parachain_id: item.parachain_id, |
| 232 | + migration_readiness_check: item.migration_readiness_check, |
| 233 | + hrmp_channel_status: item.hrmp_channel_status, |
| 234 | + }) |
| 235 | + }; |
| 236 | + |
| 237 | + crate::ProjectsDetails::<T>::translate(|key, object: OldProjectDetailsOf<T>| translate(key, object)); |
| 238 | + |
| 239 | + T::DbWeight::get().reads_writes(items, items) |
| 240 | + } |
| 241 | + } |
| 242 | + |
| 243 | + pub type MigrationToV3<T> = frame_support::migrations::VersionedMigration< |
| 244 | + 2, |
| 245 | + 3, |
| 246 | + UncheckedMigrationToV3<T>, |
| 247 | + crate::Pallet<T>, |
| 248 | + <T as frame_system::Config>::DbWeight, |
| 249 | + >; |
| 250 | +} |
0 commit comments