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
    tanssi_runtime_common::migrations::{
31
        PolkadotXcmMigrationFixVersion, XcmpQueueMigrationFixVersion, XcmpQueueMigrationV3,
32
        XcmpQueueMigrationV4,
33
    },
34
};
35

            
36
pub struct TemplateMigrations<Runtime, XcmpQueue, PolkadotXcm>(
37
    PhantomData<(Runtime, XcmpQueue, PolkadotXcm)>,
38
);
39

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

            
50
    fn migrate(&self, _available_weight: Weight) -> Weight {
51
        pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::on_runtime_upgrade()
52
    }
53

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

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

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