1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Tanssi is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>
16

            
17
//! # Migrations
18
//!
19
//! This module acts as a registry where each migration is defined. Each migration should implement
20
//! the "Migration" trait declared in the pallet-migrations crate.
21

            
22
use {
23
    frame_support::{
24
        pallet_prelude::GetStorageVersion,
25
        traits::{OnRuntimeUpgrade, PalletInfoAccess},
26
        weights::Weight,
27
    },
28
    pallet_migrations::{GetMigrations, Migration},
29
    sp_std::{marker::PhantomData, prelude::*},
30
};
31

            
32
pub struct TemplateMigrations<Runtime, XcmpQueue, PolkadotXcm>(
33
    PhantomData<(Runtime, XcmpQueue, PolkadotXcm)>,
34
);
35

            
36
pub struct MigrateToLatestXcmVersion<Runtime>(PhantomData<Runtime>);
37
impl<Runtime> Migration for MigrateToLatestXcmVersion<Runtime>
38
where
39
    pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>:
40
        frame_support::traits::OnRuntimeUpgrade,
41
{
42
    fn friendly_name(&self) -> &str {
43
        "MM_MigrateToLatestXcmVersion5"
44
    }
45

            
46
    fn migrate(&self, _available_weight: Weight) -> Weight {
47
        pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::on_runtime_upgrade()
48
    }
49

            
50
    #[cfg(feature = "try-runtime")]
51
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
52
        pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::pre_upgrade()
53
    }
54

            
55
    #[cfg(feature = "try-runtime")]
56
    fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
57
        pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::post_upgrade(state)
58
    }
59
}
60

            
61
impl<Runtime, XcmpQueue, PolkadotXcm> GetMigrations
62
    for TemplateMigrations<Runtime, XcmpQueue, PolkadotXcm>
63
where
64
    PolkadotXcm: GetStorageVersion + PalletInfoAccess + 'static,
65
    XcmpQueue: GetStorageVersion + PalletInfoAccess + 'static,
66
    Runtime: frame_system::Config,
67
    Runtime: cumulus_pallet_xcmp_queue::Config,
68
    Runtime: pallet_xcm_executor_utils::Config,
69
    Runtime: pallet_xcm::Config,
70
    Runtime: pallet_foreign_asset_creator::Config,
71
{
72
937
    fn get_migrations() -> Vec<Box<dyn Migration>> {
73
937
        //let migrate_polkadot_xcm_v1 =
74
937
        //    PolkadotXcmMigrationFixVersion::<Runtime, PolkadotXcm>(Default::default());
75
937
        //let migrate_xcmp_queue_v2 =
76
937
        //    XcmpQueueMigrationFixVersion::<Runtime, XcmpQueue>(Default::default());
77
937
        //let migrate_xcmp_queue_v3 = XcmpQueueMigrationV3::<Runtime>(Default::default());
78
937
        //let migrate_xcmp_queue_v4 = XcmpQueueMigrationV4::<Runtime>(Default::default());
79
937
        //let migrate_xcm_executor_utils_v4 =
80
937
        //    pallet_xcm_executor_utils::migrations::MigrateToV1::<Runtime>(Default::default());
81
937
        // let migrate_pallet_xcm_v4 = MigrateToLatestXcmVersion::<Runtime>(Default::default());
82
937
        //let foreign_asset_creator_migration =
83
937
        //    ForeignAssetCreatorMigration::<Runtime>(Default::default());
84
937
        //let migrate_pallet_xcm_v5 = MigrateToLatestXcmVersion::<Runtime>(Default::default());
85
937
        vec![
86
937
            // Box::new(migrate_polkadot_xcm_v1),
87
937
            // Box::new(migrate_xcmp_queue_v2),
88
937
            // Box::new(migrate_xcmp_queue_v3),
89
937
            // Box::new(migrate_xcmp_queue_v4),
90
937
            //Box::new(migrate_xcm_executor_utils_v4),
91
937
            // Box::new(migrate_pallet_xcm_v4),
92
937
            //Box::new(foreign_asset_creator_migration),
93
937
            // Applied in runtime 1200
94
937
            //Box::new(migrate_pallet_xcm_v5),
95
937
        ]
96
937
    }
97
}