diff --git a/pallets/asset/src/checkpoint/migrations.rs b/pallets/asset/src/checkpoint/migrations.rs index ee597b3a23..bb919ce759 100644 --- a/pallets/asset/src/checkpoint/migrations.rs +++ b/pallets/asset/src/checkpoint/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use sp_std::collections::btree_map::BTreeMap; @@ -10,43 +11,43 @@ mod v1 { decl_storage! { trait Store for Module as Checkpoint { // This storage changed the Ticker key to AssetID. - pub TotalSupply get(fn total_supply_at): + pub OldTotalSupply get(fn total_supply_at): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) CheckpointId => polymesh_primitives::Balance; // This storage changed the Ticker key to AssetID. - pub Balance get(fn balance_at_checkpoint): + pub OldBalance get(fn balance_at_checkpoint): double_map hasher(blake2_128_concat) (Ticker, CheckpointId), hasher(twox_64_concat) IdentityId => polymesh_primitives::Balance; // This storage changed the Ticker key to AssetID. - pub CheckpointIdSequence get(fn checkpoint_id_sequence): + pub OldCheckpointIdSequence get(fn checkpoint_id_sequence): map hasher(blake2_128_concat) Ticker => CheckpointId; // This storage changed the Ticker key to AssetID. - pub BalanceUpdates get(fn balance_updates): + pub OldBalanceUpdates get(fn balance_updates): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) IdentityId => Vec; // This storage changed the Ticker key to AssetID. - pub Timestamps get(fn timestamps): + pub OldTimestamps get(fn timestamps): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) CheckpointId => Moment; // This storage changed the Ticker key to AssetID. - pub ScheduleIdSequence get(fn schedule_id_sequence): + pub OldScheduleIdSequence get(fn schedule_id_sequence): map hasher(blake2_128_concat) Ticker => ScheduleId; // This storage changed the Ticker key to AssetID. - pub CachedNextCheckpoints get(fn cached_next_checkpoints): + pub OldCachedNextCheckpoints get(fn cached_next_checkpoints): map hasher(blake2_128_concat) Ticker => Option; // This storage changed the Ticker key to AssetID. - pub ScheduledCheckpoints get(fn scheduled_checkpoints): + pub OldScheduledCheckpoints get(fn scheduled_checkpoints): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) ScheduleId => Option; // This storage changed the Ticker key to AssetID. - pub ScheduleRefCount get(fn schedule_ref_count): + pub OldScheduleRefCount get(fn schedule_ref_count): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) ScheduleId => u32; // This storage changed the Ticker key to AssetID. - pub SchedulePoints get(fn schedule_points): + pub OldSchedulePoints get(fn schedule_points): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) ScheduleId => Vec; } } @@ -64,7 +65,11 @@ pub(crate) fn migrate_to_v2() { let mut count = 0; log::info!("Updating types for the TotalSupply storage"); - v1::TotalSupply::drain().for_each(|(ticker, checkpoint_id, balance)| { + move_prefix( + &TotalSupply::final_prefix(), + &v1::OldTotalSupply::final_prefix(), + ); + v1::OldTotalSupply::drain().for_each(|(ticker, checkpoint_id, balance)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -75,7 +80,8 @@ pub(crate) fn migrate_to_v2() { let mut count = 0; log::info!("Updating types for the Balance storage"); - v1::Balance::drain().for_each(|((ticker, checkpoint_id), did, balance)| { + move_prefix(&Balance::final_prefix(), &v1::OldBalance::final_prefix()); + v1::OldBalance::drain().for_each(|((ticker, checkpoint_id), did, balance)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -86,7 +92,11 @@ pub(crate) fn migrate_to_v2() { let mut count = 0; log::info!("Updating types for the CheckpointIdSequence storage"); - v1::CheckpointIdSequence::drain().for_each(|(ticker, checkpoint_id)| { + move_prefix( + &CheckpointIdSequence::final_prefix(), + &v1::OldCheckpointIdSequence::final_prefix(), + ); + v1::OldCheckpointIdSequence::drain().for_each(|(ticker, checkpoint_id)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -97,7 +107,11 @@ pub(crate) fn migrate_to_v2() { let mut count = 0; log::info!("Updating types for the BalanceUpdates storage"); - v1::BalanceUpdates::drain().for_each(|(ticker, did, checkpoint_id)| { + move_prefix( + &BalanceUpdates::final_prefix(), + &v1::OldBalanceUpdates::final_prefix(), + ); + v1::OldBalanceUpdates::drain().for_each(|(ticker, did, checkpoint_id)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -108,7 +122,11 @@ pub(crate) fn migrate_to_v2() { let mut count = 0; log::info!("Updating types for the Timestamps storage"); - v1::Timestamps::drain().for_each(|(ticker, checkpoint_id, when)| { + move_prefix( + &Timestamps::final_prefix(), + &v1::OldTimestamps::final_prefix(), + ); + v1::OldTimestamps::drain().for_each(|(ticker, checkpoint_id, when)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -119,7 +137,11 @@ pub(crate) fn migrate_to_v2() { let mut count = 0; log::info!("Updating types for the ScheduleIdSequence storage"); - v1::ScheduleIdSequence::drain().for_each(|(ticker, schedule_id)| { + move_prefix( + &ScheduleIdSequence::final_prefix(), + &v1::OldScheduleIdSequence::final_prefix(), + ); + v1::OldScheduleIdSequence::drain().for_each(|(ticker, schedule_id)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -130,7 +152,11 @@ pub(crate) fn migrate_to_v2() { let mut count = 0; log::info!("Updating types for the CachedNextCheckpoints storage"); - v1::CachedNextCheckpoints::drain().for_each(|(ticker, next_checkpoint)| { + move_prefix( + &CachedNextCheckpoints::final_prefix(), + &v1::OldCachedNextCheckpoints::final_prefix(), + ); + v1::OldCachedNextCheckpoints::drain().for_each(|(ticker, next_checkpoint)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -141,7 +167,11 @@ pub(crate) fn migrate_to_v2() { let mut count = 0; log::info!("Updating types for the ScheduledCheckpoints storage"); - v1::ScheduledCheckpoints::drain().for_each(|(ticker, schedule_id, next_checkpoint)| { + move_prefix( + &ScheduledCheckpoints::final_prefix(), + &v1::OldScheduledCheckpoints::final_prefix(), + ); + v1::OldScheduledCheckpoints::drain().for_each(|(ticker, schedule_id, next_checkpoint)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -152,7 +182,11 @@ pub(crate) fn migrate_to_v2() { let mut count = 0; log::info!("Updating types for the ScheduleRefCount storage"); - v1::ScheduleRefCount::drain().for_each(|(ticker, schedule_id, ref_count)| { + move_prefix( + &ScheduleRefCount::final_prefix(), + &v1::OldScheduleRefCount::final_prefix(), + ); + v1::OldScheduleRefCount::drain().for_each(|(ticker, schedule_id, ref_count)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -163,7 +197,11 @@ pub(crate) fn migrate_to_v2() { let mut count = 0; log::info!("Updating types for the SchedulePoints storage"); - v1::SchedulePoints::drain().for_each(|(ticker, schedule_id, checkpoint_id)| { + move_prefix( + &SchedulePoints::final_prefix(), + &v1::OldSchedulePoints::final_prefix(), + ); + v1::OldSchedulePoints::drain().for_each(|(ticker, schedule_id, checkpoint_id)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) diff --git a/pallets/asset/src/migrations.rs b/pallets/asset/src/migrations.rs index 819fabd87d..ea67bac0c0 100644 --- a/pallets/asset/src/migrations.rs +++ b/pallets/asset/src/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use sp_std::collections::btree_map::BTreeMap; @@ -16,11 +17,11 @@ mod v4 { pub Tokens get(fn tokens): map hasher(blake2_128_concat) Ticker => Option; // This storage changed the Ticker key to AssetID. - pub AssetNames get(fn asset_names): + pub OldAssetNames get(fn asset_names): map hasher(blake2_128_concat) Ticker => Option; // This storage changed the Ticker key to AssetID. - pub BalanceOf get(fn balance_of): + pub OldBalanceOf get(fn balance_of): double_map hasher(blake2_128_concat) Ticker, hasher(identity) IdentityId => Balance; // This storage was renamed to AssetIdentifiers and changed the Ticker key to AssetID. @@ -28,46 +29,46 @@ mod v4 { map hasher(blake2_128_concat) Ticker => Vec; // This storage changed the Ticker key to AssetID. - pub FundingRound get(fn funding_round): + pub OldFundingRound get(fn funding_round): map hasher(blake2_128_concat) Ticker => FundingRoundName; // This storage changed the Ticker key to AssetID. - pub IssuedInFundingRound get(fn issued_in_funding_round): + pub OldIssuedInFundingRound get(fn issued_in_funding_round): map hasher(blake2_128_concat) (Ticker, FundingRoundName) => Balance; // This storage changed the Ticker key to AssetID. - pub Frozen get(fn frozen): map hasher(blake2_128_concat) Ticker => bool; + pub OldFrozen get(fn frozen): map hasher(blake2_128_concat) Ticker => bool; // This storage was split into TickersOwnedByUser and SecurityTokensOwnedByUser. pub AssetOwnershipRelations get(fn asset_ownership_relation): double_map hasher(identity) IdentityId, hasher(blake2_128_concat) Ticker => AssetOwnershipRelation; // This storage changed the Ticker key to AssetID. - pub AssetDocuments get(fn asset_documents): + pub OldAssetDocuments get(fn asset_documents): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) DocumentId => Option; // This storage changed the Ticker key to AssetID. - pub AssetDocumentsIdSequence get(fn asset_documents_id_sequence): + pub OldAssetDocumentsIdSequence get(fn asset_documents_id_sequence): map hasher(blake2_128_concat) Ticker => DocumentId; // This storage changed the Ticker key to AssetID. - pub AssetMetadataValues get(fn asset_metadata_values): + pub OldAssetMetadataValues get(fn asset_metadata_values): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) AssetMetadataKey => Option; // This storage changed the Ticker key to AssetID. - pub AssetMetadataValueDetails get(fn asset_metadata_value_details): + pub OldAssetMetadataValueDetails get(fn asset_metadata_value_details): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) AssetMetadataKey => Option>; // This storage changed the Ticker key to AssetID. - pub AssetMetadataLocalNameToKey get(fn asset_metadata_local_name_to_key): + pub OldAssetMetadataLocalNameToKey get(fn asset_metadata_local_name_to_key): double_map hasher(blake2_128_concat) Ticker, hasher(blake2_128_concat) AssetMetadataName => Option; // This storage changed the Ticker key to AssetID. - pub AssetMetadataLocalKeyToName get(fn asset_metadata_local_key_to_name): + pub OldAssetMetadataLocalKeyToName get(fn asset_metadata_local_key_to_name): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) AssetMetadataLocalKey => Option; // This storage changed the Ticker key to AssetID. - pub AssetMetadataLocalSpecs get(fn asset_metadata_local_specs): + pub OldAssetMetadataLocalSpecs get(fn asset_metadata_local_specs): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) AssetMetadataLocalKey => Option; // This storage has been removed. @@ -83,11 +84,11 @@ mod v4 { double_map hasher(identity) IdentityId, hasher(blake2_128_concat) Ticker => bool; // This storage changed the Ticker key to AssetID. - pub MandatoryMediators get(fn mandatory_mediators): + pub OldMandatoryMediators get(fn mandatory_mediators): map hasher(blake2_128_concat) Ticker => BoundedBTreeSet; // This storage changed the Ticker key to AssetID. - pub CurrentAssetMetadataLocalKey get(fn current_asset_metadata_local_key): + pub OldCurrentAssetMetadataLocalKey get(fn current_asset_metadata_local_key): map hasher(blake2_128_concat) Ticker => Option; // This storage has been removed. @@ -129,7 +130,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the AssetNames storage"); - v4::AssetNames::drain().for_each(|(ticker, asset_name)| { + move_prefix( + &AssetNames::final_prefix(), + &v4::OldAssetNames::final_prefix(), + ); + v4::OldAssetNames::drain().for_each(|(ticker, asset_name)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -140,7 +145,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the BalanceOf storage"); - v4::BalanceOf::drain().for_each(|(ticker, identity, balance)| { + move_prefix( + &BalanceOf::final_prefix(), + &v4::OldBalanceOf::final_prefix(), + ); + v4::OldBalanceOf::drain().for_each(|(ticker, identity, balance)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -162,7 +171,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the FundingRound storage"); - v4::FundingRound::drain().for_each(|(ticker, name)| { + move_prefix( + &FundingRound::final_prefix(), + &v4::OldFundingRound::final_prefix(), + ); + v4::OldFundingRound::drain().for_each(|(ticker, name)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -173,7 +186,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the IssuedInFundingRound storage"); - v4::IssuedInFundingRound::drain().for_each(|((ticker, name), balance)| { + move_prefix( + &IssuedInFundingRound::final_prefix(), + &v4::OldIssuedInFundingRound::final_prefix(), + ); + v4::OldIssuedInFundingRound::drain().for_each(|((ticker, name), balance)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -184,7 +201,8 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the Frozen storage"); - v4::Frozen::drain().for_each(|(ticker, frozen)| { + move_prefix(&Frozen::final_prefix(), &v4::OldFrozen::final_prefix()); + v4::OldFrozen::drain().for_each(|(ticker, frozen)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -216,7 +234,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the AssetDocuments storage"); - v4::AssetDocuments::drain().for_each(|(ticker, doc_id, doc)| { + move_prefix( + &AssetDocuments::final_prefix(), + &v4::OldAssetDocuments::final_prefix(), + ); + v4::OldAssetDocuments::drain().for_each(|(ticker, doc_id, doc)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -228,7 +250,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the AssetDocumentsIdSequence storage"); - v4::AssetDocumentsIdSequence::drain().for_each(|(ticker, seq)| { + move_prefix( + &AssetDocumentsIdSequence::final_prefix(), + &v4::OldAssetDocumentsIdSequence::final_prefix(), + ); + v4::OldAssetDocumentsIdSequence::drain().for_each(|(ticker, seq)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -240,7 +266,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the AssetMetadataValues storage"); - v4::AssetMetadataValues::drain().for_each(|(ticker, key, value)| { + move_prefix( + &AssetMetadataValues::final_prefix(), + &v4::OldAssetMetadataValues::final_prefix(), + ); + v4::OldAssetMetadataValues::drain().for_each(|(ticker, key, value)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -252,7 +282,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the AssetMetadataValueDetails storage"); - v4::AssetMetadataValueDetails::::drain().for_each(|(ticker, key, value)| { + move_prefix( + &AssetMetadataValueDetails::::final_prefix(), + &v4::OldAssetMetadataValueDetails::::final_prefix(), + ); + v4::OldAssetMetadataValueDetails::::drain().for_each(|(ticker, key, value)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -264,7 +298,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the AssetMetadataLocalNameToKey storage"); - v4::AssetMetadataLocalNameToKey::drain().for_each(|(ticker, name, local_key)| { + move_prefix( + &AssetMetadataLocalNameToKey::final_prefix(), + &v4::OldAssetMetadataLocalNameToKey::final_prefix(), + ); + v4::OldAssetMetadataLocalNameToKey::drain().for_each(|(ticker, name, local_key)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -276,7 +314,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the AssetMetadataLocalKeyToName storage"); - v4::AssetMetadataLocalKeyToName::drain().for_each(|(ticker, local_key, name)| { + move_prefix( + &AssetMetadataLocalKeyToName::final_prefix(), + &v4::OldAssetMetadataLocalKeyToName::final_prefix(), + ); + v4::OldAssetMetadataLocalKeyToName::drain().for_each(|(ticker, local_key, name)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -288,7 +330,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the AssetMetadataLocalSpecs storage"); - v4::AssetMetadataLocalSpecs::drain().for_each(|(ticker, local_key, spec)| { + move_prefix( + &AssetMetadataLocalSpecs::final_prefix(), + &v4::OldAssetMetadataLocalSpecs::final_prefix(), + ); + v4::OldAssetMetadataLocalSpecs::drain().for_each(|(ticker, local_key, spec)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -328,7 +374,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the MandatoryMediators storage"); - v4::MandatoryMediators::::drain().for_each(|(ticker, mediators)| { + move_prefix( + &MandatoryMediators::::final_prefix(), + &v4::OldMandatoryMediators::::final_prefix(), + ); + v4::OldMandatoryMediators::::drain().for_each(|(ticker, mediators)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -340,7 +390,11 @@ pub(crate) fn migrate_to_v5() { let mut count = 0; log::info!("Updating types for the CurrentAssetMetadataLocalKey storage"); - v4::CurrentAssetMetadataLocalKey::drain().for_each(|(ticker, current_key)| { + move_prefix( + &CurrentAssetMetadataLocalKey::final_prefix(), + &v4::OldCurrentAssetMetadataLocalKey::final_prefix(), + ); + v4::OldCurrentAssetMetadataLocalKey::drain().for_each(|(ticker, current_key)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) diff --git a/pallets/compliance-manager/src/migrations.rs b/pallets/compliance-manager/src/migrations.rs index b9202bcf14..30ede59b95 100644 --- a/pallets/compliance-manager/src/migrations.rs +++ b/pallets/compliance-manager/src/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use sp_std::collections::btree_map::BTreeMap; @@ -65,11 +66,11 @@ mod v0 { trait Store for Module as ComplianceManager { // This storage changed the Ticker key to AssetID. // The Scope type, which is inside the compliance codition, has also been changed. - pub AssetCompliances get(fn asset_compliance): + pub OldAssetCompliances get(fn asset_compliance): map hasher(blake2_128_concat) Ticker => AssetCompliance; // This storage changed the Ticker key to AssetID. - pub TrustedClaimIssuer get(fn trusted_claim_issuer): + pub OldTrustedClaimIssuer get(fn trusted_claim_issuer): map hasher(blake2_128_concat) Ticker => Vec; } } @@ -170,7 +171,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the AssetCompliances storage"); - v0::AssetCompliances::drain().for_each(|(ticker, compliance)| { + move_prefix( + &AssetCompliances::final_prefix(), + &v0::OldAssetCompliances::final_prefix(), + ); + v0::OldAssetCompliances::drain().for_each(|(ticker, compliance)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -181,7 +186,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the TrustedClaimIssuer storage"); - v0::TrustedClaimIssuer::drain().for_each(|(ticker, trusted_issuers)| { + move_prefix( + &TrustedClaimIssuer::final_prefix(), + &v0::OldTrustedClaimIssuer::final_prefix(), + ); + v0::OldTrustedClaimIssuer::drain().for_each(|(ticker, trusted_issuers)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) diff --git a/pallets/corporate-actions/src/ballot/migrations.rs b/pallets/corporate-actions/src/ballot/migrations.rs index 0c5e84443e..5805e11a71 100644 --- a/pallets/corporate-actions/src/ballot/migrations.rs +++ b/pallets/corporate-actions/src/ballot/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use super::*; @@ -8,25 +9,25 @@ mod v0 { decl_storage! { trait Store for Module as CorporateBallot { // The CAId type has changed. - pub Metas get(fn metas): + pub OldMetas get(fn metas): map hasher(blake2_128_concat) crate::migrations::v0::CAId => Option; // The CAId type has changed. - pub TimeRanges get(fn time_ranges): + pub OldTimeRanges get(fn time_ranges): map hasher(blake2_128_concat) crate::migrations::v0::CAId => Option; // The CAId type has changed. - pub MotionNumChoices get(fn motion_choices): + pub OldMotionNumChoices get(fn motion_choices): map hasher(blake2_128_concat) crate::migrations::v0::CAId => Vec; // The CAId type has changed. - pub RCV get(fn rcv): map hasher(blake2_128_concat) crate::migrations::v0::CAId => bool; + pub OldRCV get(fn rcv): map hasher(blake2_128_concat) crate::migrations::v0::CAId => bool; // The CAId type has changed. - pub Results get(fn results): map hasher(blake2_128_concat) crate::migrations::v0::CAId => Vec; + pub OldResults get(fn results): map hasher(blake2_128_concat) crate::migrations::v0::CAId => Vec; // The CAId type has changed. - pub Votes get(fn votes): + pub OldVotes get(fn votes): double_map hasher(blake2_128_concat) crate::migrations::v0::CAId, hasher(identity) IdentityId => Vec; } @@ -42,7 +43,8 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the Metas storage"); - v0::Metas::drain().for_each(|(ca_id, ballot)| { + move_prefix(&Metas::final_prefix(), &v0::OldMetas::final_prefix()); + v0::OldMetas::drain().for_each(|(ca_id, ballot)| { count += 1; Metas::insert(CAId::from(ca_id), ballot); }); @@ -50,7 +52,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the TimeRanges storage"); - v0::TimeRanges::drain().for_each(|(ca_id, range)| { + move_prefix( + &TimeRanges::final_prefix(), + &v0::OldTimeRanges::final_prefix(), + ); + v0::OldTimeRanges::drain().for_each(|(ca_id, range)| { count += 1; TimeRanges::insert(CAId::from(ca_id), range); }); @@ -58,7 +64,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the MotionNumChoices storage"); - v0::MotionNumChoices::drain().for_each(|(ca_id, choices)| { + move_prefix( + &MotionNumChoices::final_prefix(), + &v0::OldMotionNumChoices::final_prefix(), + ); + v0::OldMotionNumChoices::drain().for_each(|(ca_id, choices)| { count += 1; MotionNumChoices::insert(CAId::from(ca_id), choices); }); @@ -66,7 +76,8 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the RCV storage"); - v0::RCV::drain().for_each(|(ca_id, rcv)| { + move_prefix(&RCV::final_prefix(), &v0::OldRCV::final_prefix()); + v0::OldRCV::drain().for_each(|(ca_id, rcv)| { count += 1; RCV::insert(CAId::from(ca_id), rcv); }); @@ -74,7 +85,8 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the Results storage"); - v0::Results::drain().for_each(|(ca_id, balances)| { + move_prefix(&Results::final_prefix(), &v0::OldResults::final_prefix()); + v0::OldResults::drain().for_each(|(ca_id, balances)| { count += 1; Results::insert(CAId::from(ca_id), balances); }); @@ -82,7 +94,8 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the Votes storage"); - v0::Votes::drain().for_each(|(ca_id, did, vote)| { + move_prefix(&Votes::final_prefix(), &v0::OldVotes::final_prefix()); + v0::OldVotes::drain().for_each(|(ca_id, did, vote)| { count += 1; Votes::insert(CAId::from(ca_id), did, vote); }); diff --git a/pallets/corporate-actions/src/distribution/migrations.rs b/pallets/corporate-actions/src/distribution/migrations.rs index 5db9f1bfd5..bb881906cf 100644 --- a/pallets/corporate-actions/src/distribution/migrations.rs +++ b/pallets/corporate-actions/src/distribution/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use super::*; @@ -21,11 +22,11 @@ mod v0 { decl_storage! { trait Store for Module as CapitalDistribution { // CAId and Distribution have changed types. - pub(crate) Distributions get(fn distributions): + pub(crate) OldDistributions get(fn distributions): map hasher(blake2_128_concat) crate::migrations::v0::CAId => Option; // The CAId type has changed. - pub(crate) HolderPaid get(fn holder_paid): + pub(crate) OldHolderPaid get(fn holder_paid): map hasher(blake2_128_concat) (crate::migrations::v0::CAId, IdentityId) => bool; } } @@ -55,7 +56,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the Distributions storage"); - v0::Distributions::drain().for_each(|(ca_id, distribution)| { + move_prefix( + &Distributions::final_prefix(), + &v0::OldDistributions::final_prefix(), + ); + v0::OldDistributions::drain().for_each(|(ca_id, distribution)| { count += 1; Distributions::insert(CAId::from(ca_id), Distribution::from(distribution)); }); @@ -63,7 +68,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the HolderPaid storage"); - v0::HolderPaid::drain().for_each(|((ca_id, did), paid)| { + move_prefix( + &HolderPaid::final_prefix(), + &v0::OldHolderPaid::final_prefix(), + ); + v0::OldHolderPaid::drain().for_each(|((ca_id, did), paid)| { count += 1; HolderPaid::insert((CAId::from(ca_id), did), paid); }); diff --git a/pallets/corporate-actions/src/migrations.rs b/pallets/corporate-actions/src/migrations.rs index 241e421586..f5f8e108ba 100644 --- a/pallets/corporate-actions/src/migrations.rs +++ b/pallets/corporate-actions/src/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use sp_std::collections::btree_map::BTreeMap; @@ -16,31 +17,31 @@ pub(crate) mod v0 { decl_storage! { trait Store for Module as CorporateAction { // This storage changed the Ticker key to AssetID. - pub DefaultTargetIdentities get(fn default_target_identities): + pub OldDefaultTargetIdentities get(fn default_target_identities): map hasher(blake2_128_concat) Ticker => TargetIdentities; // This storage changed the Ticker key to AssetID. - pub DefaultWithholdingTax get(fn default_withholding_tax): + pub OldDefaultWithholdingTax get(fn default_withholding_tax): map hasher(blake2_128_concat) Ticker => Tax; // This storage changed the Ticker key to AssetID. - pub DidWithholdingTax get(fn did_withholding_tax): + pub OldDidWithholdingTax get(fn did_withholding_tax): map hasher(blake2_128_concat) Ticker => Vec<(IdentityId, Tax)>; // This storage changed the Ticker key to AssetID. - pub CAIdSequence get(fn ca_id_sequence): + pub OldCAIdSequence get(fn ca_id_sequence): map hasher(blake2_128_concat) Ticker => LocalCAId; // This storage changed the Ticker key to AssetID. - pub CorporateActions get(fn corporate_actions): + pub OldCorporateActions get(fn corporate_actions): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) LocalCAId => Option; // The CAId type has been updated. - pub CADocLink get(fn ca_doc_link): + pub OldCADocLink get(fn ca_doc_link): map hasher(blake2_128_concat) CAId => Vec; // The CAId type has been updated. - pub Details get(fn details): + pub OldDetails get(fn details): map hasher(blake2_128_concat) CAId => CADetails; } } @@ -65,7 +66,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the DefaultTargetIdentities storage"); - v0::DefaultTargetIdentities::drain().for_each(|(ticker, target_identities)| { + move_prefix( + &DefaultTargetIdentities::final_prefix(), + &v0::OldDefaultTargetIdentities::final_prefix(), + ); + v0::OldDefaultTargetIdentities::drain().for_each(|(ticker, target_identities)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -76,7 +81,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the DefaultWithholdingTax storage"); - v0::DefaultWithholdingTax::drain().for_each(|(ticker, tax)| { + move_prefix( + &DefaultWithholdingTax::final_prefix(), + &v0::OldDefaultWithholdingTax::final_prefix(), + ); + v0::OldDefaultWithholdingTax::drain().for_each(|(ticker, tax)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -87,7 +96,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the DidWithholdingTax storage"); - v0::DidWithholdingTax::drain().for_each(|(ticker, id_tax)| { + move_prefix( + &DidWithholdingTax::final_prefix(), + &v0::OldDidWithholdingTax::final_prefix(), + ); + v0::OldDidWithholdingTax::drain().for_each(|(ticker, id_tax)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -98,7 +111,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the CAIdSequence storage"); - v0::CAIdSequence::drain().for_each(|(ticker, id_tax)| { + move_prefix( + &CAIdSequence::final_prefix(), + &v0::OldCAIdSequence::final_prefix(), + ); + v0::OldCAIdSequence::drain().for_each(|(ticker, id_tax)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -109,7 +126,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the CorporateActions storage"); - v0::CorporateActions::drain().for_each(|(ticker, local_id, ca)| { + move_prefix( + &CorporateActions::final_prefix(), + &v0::OldCorporateActions::final_prefix(), + ); + v0::OldCorporateActions::drain().for_each(|(ticker, local_id, ca)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -120,7 +141,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the CADocLink storage"); - v0::CADocLink::drain().for_each(|(ca_id, docs)| { + move_prefix( + &CADocLink::final_prefix(), + &v0::OldCADocLink::final_prefix(), + ); + v0::OldCADocLink::drain().for_each(|(ca_id, docs)| { count += 1; CADocLink::insert(CAId::from(ca_id), docs); }); @@ -128,7 +153,8 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the Details storage"); - v0::Details::drain().for_each(|(ca_id, details)| { + move_prefix(&Details::final_prefix(), &v0::OldDetails::final_prefix()); + v0::OldDetails::drain().for_each(|(ca_id, details)| { count += 1; Details::insert(CAId::from(ca_id), details); }); diff --git a/pallets/external-agents/src/migrations.rs b/pallets/external-agents/src/migrations.rs index acad2d2b83..ba156156f4 100644 --- a/pallets/external-agents/src/migrations.rs +++ b/pallets/external-agents/src/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use sp_std::collections::btree_map::BTreeMap; @@ -10,23 +11,23 @@ mod v0 { decl_storage! { trait Store for Module as ExternalAgents { // This storage changed the Ticker key to AssetID. - pub AGIdSequence get(fn agent_group_id_sequence): + pub OldAGIdSequence get(fn agent_group_id_sequence): map hasher(blake2_128_concat) Ticker => AGId; // This storage changed the Ticker key to AssetID. - pub AgentOf get(fn agent_of): + pub OldAgentOf get(fn agent_of): double_map hasher(blake2_128_concat) IdentityId, hasher(blake2_128_concat) Ticker => (); // This storage changed the Ticker key to AssetID. - pub GroupOfAgent get(fn agents): + pub OldGroupOfAgent get(fn agents): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) IdentityId => Option; // This storage changed the Ticker key to AssetID. - pub NumFullAgents get(fn num_full_agents): + pub OldNumFullAgents get(fn num_full_agents): map hasher(blake2_128_concat) Ticker => u32; // This storage changed the Ticker key to AssetID. - pub GroupPermissions get(fn permissions): + pub OldGroupPermissions get(fn permissions): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) AGId => Option; } @@ -43,7 +44,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the AGIdSequence storage"); - v0::AGIdSequence::drain().for_each(|(ticker, ag_id)| { + move_prefix( + &AGIdSequence::final_prefix(), + &v0::OldAGIdSequence::final_prefix(), + ); + v0::OldAGIdSequence::drain().for_each(|(ticker, ag_id)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -54,7 +59,8 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the AgentOf storage"); - v0::AgentOf::drain().for_each(|(did, ticker, empty)| { + move_prefix(&AgentOf::final_prefix(), &v0::OldAgentOf::final_prefix()); + v0::OldAgentOf::drain().for_each(|(did, ticker, empty)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -65,7 +71,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the GroupOfAgent storage"); - v0::GroupOfAgent::drain().for_each(|(ticker, did, group)| { + move_prefix( + &GroupOfAgent::final_prefix(), + &v0::OldGroupOfAgent::final_prefix(), + ); + v0::OldGroupOfAgent::drain().for_each(|(ticker, did, group)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -76,7 +86,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the NumFullAgents storage"); - v0::NumFullAgents::drain().for_each(|(ticker, n)| { + move_prefix( + &NumFullAgents::final_prefix(), + &v0::OldNumFullAgents::final_prefix(), + ); + v0::OldNumFullAgents::drain().for_each(|(ticker, n)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -87,7 +101,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the GroupPermissions storage"); - v0::GroupPermissions::drain().for_each(|(ticker, ag_id, ext_perms)| { + move_prefix( + &GroupPermissions::final_prefix(), + &v0::OldGroupPermissions::final_prefix(), + ); + v0::OldGroupPermissions::drain().for_each(|(ticker, ag_id, ext_perms)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) diff --git a/pallets/identity/src/ticker_migrations.rs b/pallets/identity/src/ticker_migrations.rs index 7ed3f97909..ec12c7a0e9 100644 --- a/pallets/identity/src/ticker_migrations.rs +++ b/pallets/identity/src/ticker_migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use super::*; @@ -79,7 +80,7 @@ mod v6 { decl_storage! { trait Store for Module as Identity { // This storage changed the Ticker key to AssetID. - pub Claims: double_map hasher(twox_64_concat) Claim1stKey, hasher(blake2_128_concat) Claim2ndKey => Option; + pub OldClaims: double_map hasher(twox_64_concat) Claim1stKey, hasher(blake2_128_concat) Claim2ndKey => Option; pub KeyRecords get(fn key_records): map hasher(twox_64_concat) T::AccountId => Option>; @@ -197,7 +198,8 @@ pub(crate) fn migrate_to_v7() { // Removes all elements in the old storage and inserts it in the new storage log::info!("Updating types for the Claims storage"); - v6::Claims::drain().for_each(|(claim1key, claim2key, id_claim)| { + move_prefix(&Claims::final_prefix(), &v6::OldClaims::final_prefix()); + v6::OldClaims::drain().for_each(|(claim1key, claim2key, id_claim)| { Claims::insert( claim1key, Claim2ndKey::from(claim2key), diff --git a/pallets/multisig/src/lib.rs b/pallets/multisig/src/lib.rs index b1b91145c3..f93e7432ca 100644 --- a/pallets/multisig/src/lib.rs +++ b/pallets/multisig/src/lib.rs @@ -1300,7 +1300,9 @@ impl MultiSigSubTrait for Pallet { pub mod migration { use super::*; + use frame_support::storage::migration::move_prefix; use frame_support::storage::StorageMap; + use frame_support::storage::StoragePrefixedMap; use sp_runtime::runtime_logger::RuntimeLogger; mod v2 { @@ -1312,7 +1314,7 @@ pub mod migration { pub MultiSigToIdentity : map hasher(identity) T::AccountId => IdentityId; pub MultiSigTxDone: map hasher(identity) T::AccountId => u64; - pub MultiSigSigners: double_map hasher(identity) T::AccountId, hasher(twox_64_concat) Signatory => bool; + pub OldMultiSigSigners: double_map hasher(identity) T::AccountId, hasher(twox_64_concat) Signatory => bool; pub LostCreatorPrivileges: map hasher(identity) IdentityId => bool; } @@ -1339,7 +1341,11 @@ pub mod migration { let mut sig_count = 0; let mut reads = 0; let mut writes = 0; - v2::MultiSigSigners::::drain().for_each(|(ms, signer, value)| { + move_prefix( + &MultiSigSigners::::final_prefix(), + &v2::OldMultiSigSigners::::final_prefix(), + ); + v2::OldMultiSigSigners::::drain().for_each(|(ms, signer, value)| { reads += 1; sig_count += 1; match signer { diff --git a/pallets/nft/src/migrations.rs b/pallets/nft/src/migrations.rs index 2553d70d9d..043c16a3f8 100644 --- a/pallets/nft/src/migrations.rs +++ b/pallets/nft/src/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use sp_std::collections::btree_map::BTreeMap; @@ -18,7 +19,7 @@ mod v3 { decl_storage! { trait Store for Module as NFT { // This storage changed the Ticker key to AssetID. - pub NumberOfNFTs get(fn balance_of): + pub OldNumberOfNFTs get(fn balance_of): double_map hasher(blake2_128_concat) Ticker, hasher(identity) IdentityId => NFTCount; // This storage changed the Ticker key to AssetID. @@ -30,11 +31,11 @@ mod v3 { map hasher(blake2_128_concat) NFTCollectionId => NFTCollection; // This storage changed the Ticker key to AssetID. - pub NFTsInCollection get(fn nfts_in_collection): + pub OldNFTsInCollection get(fn nfts_in_collection): map hasher(blake2_128_concat) Ticker => NFTCount; // This storage changed the Ticker key to AssetID. - pub NFTOwner get(fn nft_owner): + pub OldNFTOwner get(fn nft_owner): double_map hasher(blake2_128_concat) Ticker, hasher(blake2_128_concat) NFTId => Option; // This storage has been removed. @@ -64,7 +65,11 @@ pub(crate) fn migrate_to_v4() { let mut count = 0; log::info!("Updating types for the NumberOfNFTs storage"); - v3::NumberOfNFTs::drain().for_each(|(ticker, did, n)| { + move_prefix( + &NumberOfNFTs::final_prefix(), + &v3::OldNumberOfNFTs::final_prefix(), + ); + v3::OldNumberOfNFTs::drain().for_each(|(ticker, did, n)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -94,7 +99,11 @@ pub(crate) fn migrate_to_v4() { let mut count = 0; log::info!("Updating types for the NFTsInCollection storage"); - v3::NFTsInCollection::drain().for_each(|(ticker, n)| { + move_prefix( + &NFTsInCollection::final_prefix(), + &v3::OldNFTsInCollection::final_prefix(), + ); + v3::OldNFTsInCollection::drain().for_each(|(ticker, n)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -105,7 +114,8 @@ pub(crate) fn migrate_to_v4() { let mut count = 0; log::info!("Updating types for the NFTOwner storage"); - v3::NFTOwner::drain().for_each(|(ticker, nft_id, portfolio)| { + move_prefix(&NFTOwner::final_prefix(), &v3::OldNFTOwner::final_prefix()); + v3::OldNFTOwner::drain().for_each(|(ticker, nft_id, portfolio)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) diff --git a/pallets/portfolio/src/migrations.rs b/pallets/portfolio/src/migrations.rs index dcbbc39377..f95a7fe8ac 100644 --- a/pallets/portfolio/src/migrations.rs +++ b/pallets/portfolio/src/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use sp_std::collections::btree_map::BTreeMap; @@ -10,23 +11,23 @@ mod v2 { decl_storage! { trait Store for Module as Portfolio { // This storage changed the Ticker key to AssetID. - pub PortfolioAssetBalances get(fn portfolio_asset_balances): + pub OldPortfolioAssetBalances get(fn portfolio_asset_balances): double_map hasher(twox_64_concat) PortfolioId, hasher(blake2_128_concat) Ticker => Balance; // This storage changed the Ticker key to AssetID. - pub PortfolioLockedAssets get(fn locked_assets): + pub OldPortfolioLockedAssets get(fn locked_assets): double_map hasher(twox_64_concat) PortfolioId, hasher(blake2_128_concat) Ticker => Balance; // This storage changed the Ticker key to AssetID. - pub PortfolioNFT get(fn portfolio_nft): + pub OldPortfolioNFT get(fn portfolio_nft): double_map hasher(twox_64_concat) PortfolioId, hasher(blake2_128_concat) (Ticker, NFTId) => bool; // This storage changed the Ticker key to AssetID. - pub PortfolioLockedNFT get(fn portfolio_locked_nft): + pub OldPortfolioLockedNFT get(fn portfolio_locked_nft): double_map hasher(twox_64_concat) PortfolioId, hasher(blake2_128_concat) (Ticker, NFTId) => bool; // This storage changed the Ticker key to AssetID. - pub PreApprovedPortfolios get(fn pre_approved_portfolios): + pub OldPreApprovedPortfolios get(fn pre_approved_portfolios): double_map hasher(twox_64_concat) PortfolioId, hasher(blake2_128_concat) Ticker => bool; } } @@ -44,7 +45,11 @@ pub(crate) fn migrate_to_v3() { let mut count = 0; log::info!("Updating types for the PortfolioAssetBalances storage"); - v2::PortfolioAssetBalances::drain().for_each(|(portfolio, ticker, balance)| { + move_prefix( + &PortfolioAssetBalances::final_prefix(), + &v2::OldPortfolioAssetBalances::final_prefix(), + ); + v2::OldPortfolioAssetBalances::drain().for_each(|(portfolio, ticker, balance)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -55,7 +60,11 @@ pub(crate) fn migrate_to_v3() { let mut count = 0; log::info!("Updating types for the PortfolioLockedAssets storage"); - v2::PortfolioLockedAssets::drain().for_each(|(portfolio, ticker, balance)| { + move_prefix( + &PortfolioLockedAssets::final_prefix(), + &v2::OldPortfolioLockedAssets::final_prefix(), + ); + v2::OldPortfolioLockedAssets::drain().for_each(|(portfolio, ticker, balance)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -66,7 +75,11 @@ pub(crate) fn migrate_to_v3() { let mut count = 0; log::info!("Updating types for the PortfolioNFT storage"); - v2::PortfolioNFT::drain().for_each(|(portfolio, (ticker, nft_id), v)| { + move_prefix( + &PortfolioNFT::final_prefix(), + &v2::OldPortfolioNFT::final_prefix(), + ); + v2::OldPortfolioNFT::drain().for_each(|(portfolio, (ticker, nft_id), v)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -77,7 +90,11 @@ pub(crate) fn migrate_to_v3() { let mut count = 0; log::info!("Updating types for the PortfolioLockedNFT storage"); - v2::PortfolioLockedNFT::drain().for_each(|(portfolio, (ticker, nft_id), v)| { + move_prefix( + &PortfolioLockedNFT::final_prefix(), + &v2::OldPortfolioLockedNFT::final_prefix(), + ); + v2::OldPortfolioLockedNFT::drain().for_each(|(portfolio, (ticker, nft_id), v)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -88,7 +105,11 @@ pub(crate) fn migrate_to_v3() { let mut count = 0; log::info!("Updating types for the PreApprovedPortfolios storage"); - v2::PreApprovedPortfolios::drain().for_each(|(portfolio, ticker, v)| { + move_prefix( + &PreApprovedPortfolios::final_prefix(), + &v2::OldPreApprovedPortfolios::final_prefix(), + ); + v2::OldPreApprovedPortfolios::drain().for_each(|(portfolio, ticker, v)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) diff --git a/pallets/settlement/src/migrations.rs b/pallets/settlement/src/migrations.rs index 4519e5a545..e5c3325710 100644 --- a/pallets/settlement/src/migrations.rs +++ b/pallets/settlement/src/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use sp_std::collections::btree_map::BTreeMap; @@ -50,11 +51,11 @@ mod v2 { decl_storage! { trait Store for Module as Settlement { // This storage changed the Ticker key to AssetID. - pub(crate) VenueFiltering get(fn venue_filtering): + pub(crate) OldVenueFiltering get(fn venue_filtering): map hasher(blake2_128_concat) Ticker => bool; // This storage changed the Ticker key to AssetID. - pub(crate) VenueAllowList get(fn venue_allow_list): + pub(crate) OldVenueAllowList get(fn venue_allow_list): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) VenueId => bool; // This storage changed the Leg type. @@ -130,7 +131,11 @@ pub(crate) fn migrate_to_v3() { let mut count = 0; log::info!("Updating types for the VenueFiltering storage"); - v2::VenueFiltering::drain().for_each(|(ticker, v)| { + move_prefix( + &VenueFiltering::final_prefix(), + &v2::OldVenueFiltering::final_prefix(), + ); + v2::OldVenueFiltering::drain().for_each(|(ticker, v)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -141,7 +146,11 @@ pub(crate) fn migrate_to_v3() { let mut count = 0; log::info!("Updating types for the VenueAllowList storage"); - v2::VenueAllowList::drain().for_each(|(ticker, id, v)| { + move_prefix( + &VenueAllowList::final_prefix(), + &v2::OldVenueAllowList::final_prefix(), + ); + v2::OldVenueAllowList::drain().for_each(|(ticker, id, v)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) diff --git a/pallets/statistics/src/migrations.rs b/pallets/statistics/src/migrations.rs index d8af9e680e..3a672126b7 100644 --- a/pallets/statistics/src/migrations.rs +++ b/pallets/statistics/src/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use frame_support::BoundedBTreeSet; use sp_runtime::runtime_logger::RuntimeLogger; @@ -40,19 +41,19 @@ mod v2 { decl_storage! { trait Store for Module as Statistics { // This storage changed the AssetScope type. - pub ActiveAssetStats get(fn active_asset_stats): + pub OldActiveAssetStats get(fn active_asset_stats): map hasher(blake2_128_concat) AssetScope => BoundedBTreeSet; // This storage changed the Stat1stKey type. - pub AssetStats get(fn asset_stats): + pub OldAssetStats get(fn asset_stats): double_map hasher(blake2_128_concat) Stat1stKey, hasher(blake2_128_concat) Stat2ndKey => u128; // This storage changed the AssetScope type. - pub AssetTransferCompliances get(fn asset_transfer_compliance): + pub OldAssetTransferCompliances get(fn asset_transfer_compliance): map hasher(blake2_128_concat) AssetScope => AssetTransferCompliance; // This storage changed the TransferConditionExemptKey type. - pub TransferConditionExemptEntities get(fn transfer_condition_exempt_entities): + pub OldTransferConditionExemptEntities get(fn transfer_condition_exempt_entities): double_map hasher(blake2_128_concat) TransferConditionExemptKey, hasher(blake2_128_concat) IdentityId => bool; } } @@ -105,7 +106,11 @@ pub(crate) fn migrate_to_v3() { let mut count = 0; log::info!("Updating types for the ActiveAssetStats storage"); - v2::ActiveAssetStats::::drain().for_each(|(scope, set)| { + move_prefix( + &ActiveAssetStats::::final_prefix(), + &v2::OldActiveAssetStats::::final_prefix(), + ); + v2::OldActiveAssetStats::::drain().for_each(|(scope, set)| { count += 1; let set: BTreeSet = set.into_iter().map(|v| v.into()).collect(); let bounded_set = BoundedBTreeSet::try_from(set).unwrap_or_default(); @@ -115,7 +120,11 @@ pub(crate) fn migrate_to_v3() { let mut count = 0; log::info!("Updating types for the AssetStats storage"); - v2::AssetStats::drain().for_each(|(stat1key, stat2key, v)| { + move_prefix( + &AssetStats::final_prefix(), + &v2::OldAssetStats::final_prefix(), + ); + v2::OldAssetStats::drain().for_each(|(stat1key, stat2key, v)| { count += 1; AssetStats::insert(Stat1stKey::from(stat1key), stat2key, v); }); @@ -123,7 +132,11 @@ pub(crate) fn migrate_to_v3() { let mut count = 0; log::info!("Updating types for the AssetTransferCompliances storage"); - v2::AssetTransferCompliances::::drain().for_each(|(scope, compliance)| { + move_prefix( + &AssetTransferCompliances::::final_prefix(), + &v2::OldAssetTransferCompliances::::final_prefix(), + ); + v2::OldAssetTransferCompliances::::drain().for_each(|(scope, compliance)| { count += 1; AssetTransferCompliances::::insert(AssetID::from(scope), compliance); }); @@ -131,7 +144,11 @@ pub(crate) fn migrate_to_v3() { let mut count = 0; log::info!("Updating types for the TransferConditionExemptEntities storage"); - v2::TransferConditionExemptEntities::drain().for_each(|(exemption_key, did, exempt)| { + move_prefix( + &TransferConditionExemptEntities::final_prefix(), + &v2::OldTransferConditionExemptEntities::final_prefix(), + ); + v2::OldTransferConditionExemptEntities::drain().for_each(|(exemption_key, did, exempt)| { count += 1; TransferConditionExemptEntities::insert( TransferConditionExemptKey::from(exemption_key), diff --git a/pallets/sto/src/migrations.rs b/pallets/sto/src/migrations.rs index 8987f7182a..2ca596dd3e 100644 --- a/pallets/sto/src/migrations.rs +++ b/pallets/sto/src/migrations.rs @@ -1,3 +1,4 @@ +use frame_support::storage::migration::move_prefix; use sp_runtime::runtime_logger::RuntimeLogger; use sp_std::collections::btree_map::BTreeMap; @@ -10,15 +11,15 @@ mod v0 { decl_storage! { trait Store for Module as Sto { // This storage changed the Ticker key to AssetID. - pub(crate) Fundraisers get(fn fundraisers): + pub(crate) OldFundraisers get(fn fundraisers): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) FundraiserId => Option>; // This storage changed the Ticker key to AssetID. - pub(crate) FundraiserCount get(fn fundraiser_count): + pub(crate) OldFundraiserCount get(fn fundraiser_count): map hasher(blake2_128_concat) Ticker => FundraiserId; // This storage changed the Ticker key to AssetID. - pub(crate) FundraiserNames get(fn fundraiser_name): + pub(crate) OldFundraiserNames get(fn fundraiser_name): double_map hasher(blake2_128_concat) Ticker, hasher(twox_64_concat) FundraiserId => Option; } } @@ -36,7 +37,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the Fundraisers storage"); - v0::Fundraisers::::drain().for_each(|(ticker, id, fundraiser)| { + move_prefix( + &Fundraisers::::final_prefix(), + &v0::OldFundraisers::::final_prefix(), + ); + v0::OldFundraisers::::drain().for_each(|(ticker, id, fundraiser)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -47,7 +52,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the FundraiserCount storage"); - v0::FundraiserCount::drain().for_each(|(ticker, id)| { + move_prefix( + &FundraiserCount::final_prefix(), + &v0::OldFundraiserCount::final_prefix(), + ); + v0::OldFundraiserCount::drain().for_each(|(ticker, id)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker) @@ -58,7 +67,11 @@ pub(crate) fn migrate_to_v1() { let mut count = 0; log::info!("Updating types for the FundraiserNames storage"); - v0::FundraiserNames::drain().for_each(|(ticker, id, name)| { + move_prefix( + &FundraiserNames::final_prefix(), + &v0::OldFundraiserNames::final_prefix(), + ); + v0::OldFundraiserNames::drain().for_each(|(ticker, id, name)| { count += 1; let asset_id = ticker_to_asset_id .entry(ticker)