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
    alloc::{boxed::Box, vec, vec::Vec},
24
    core::marker::PhantomData,
25
    frame_support::{
26
        pallet_prelude::GetStorageVersion,
27
        traits::{OnRuntimeUpgrade, PalletInfoAccess},
28
        weights::Weight,
29
    },
30
    pallet_migrations::{GetMigrations, Migration},
31
};
32

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

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

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

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

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

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