git.delta.rocks / unique-network / refs/commits / e96d1c2510ca

difftreelog

source

runtime/common/construct_runtime/util.rs6.6 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#[macro_export]18macro_rules! construct_runtime_impl {19    (20        select_runtime($select_runtime:ident);2122        pub enum Runtime where23            $($where_ident:ident = $where_ty:ty),* $(,)?24        {25            $(26                $(#[runtimes($($pallet_runtimes:ident),+ $(,)?)])?27                $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal28            ),*29            $(,)?30        }31    ) => {32        $crate::construct_runtime_helper! {33            select_runtime($select_runtime),34            selected_pallets(),3536            where_clause($($where_ident = $where_ty),*),37            pallets(38                $(39                    $(#[runtimes($($pallet_runtimes),+)])?40                    $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index41                ),*,42            )43        }44    }45}4647#[macro_export]48macro_rules! construct_runtime_helper {49    (50        select_runtime($select_runtime:ident),51        selected_pallets($($selected_pallets:tt)*),5253        where_clause($($where_clause:tt)*),54        pallets(55            #[runtimes($($pallet_runtimes:ident),+)]56            $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal,5758            $($pallets_tl:tt)*59        )60    ) => {61        $crate::add_runtime_specific_pallets! {62            select_runtime($select_runtime),63            runtimes($($pallet_runtimes),+,),64            selected_pallets($($selected_pallets)*),6566            where_clause($($where_clause)*),67            pallets(68                $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,69                $($pallets_tl)*70            )71        }72    };7374    (75        select_runtime($select_runtime:ident),76        selected_pallets($($selected_pallets:tt)*),7778        where_clause($($where_clause:tt)*),79        pallets(80            $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal,8182            $($pallets_tl:tt)*83        )84    ) => {85        $crate::construct_runtime_helper! {86            select_runtime($select_runtime),87            selected_pallets(88                $($selected_pallets)*89                $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,90            ),9192            where_clause($($where_clause)*),93            pallets($($pallets_tl)*)94        }95    };9697    (98        select_runtime($select_runtime:ident),99        selected_pallets($($selected_pallets:tt)*),100101        where_clause($($where_clause:tt)*),102        pallets()103    ) => {104        frame_support::construct_runtime! {105            pub enum Runtime where106                $($where_clause)*107            {108                $($selected_pallets)*109            }110        }111    };112}113114#[macro_export]115macro_rules! add_runtime_specific_pallets {116    (117        select_runtime(opal),118        runtimes(opal, $($_runtime_tl:tt)*),119        selected_pallets($($selected_pallets:tt)*),120121        where_clause($($where_clause:tt)*),122        pallets(123            $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal,124            $($pallets_tl:tt)*125        )126    ) => {127        $crate::construct_runtime_helper! {128            select_runtime(opal),129            selected_pallets(130                $($selected_pallets)*131                $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,132            ),133134            where_clause($($where_clause)*),135            pallets($($pallets_tl)*)136        }137    };138139    (140        select_runtime(quartz),141        runtimes(quartz, $($_runtime_tl:tt)*),142        selected_pallets($($selected_pallets:tt)*),143144        where_clause($($where_clause:tt)*),145        pallets(146            $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal,147            $($pallets_tl:tt)*148        )149    ) => {150        $crate::construct_runtime_helper! {151            select_runtime(quartz),152            selected_pallets(153                $($selected_pallets)*154                $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,155            ),156157            where_clause($($where_clause)*),158            pallets($($pallets_tl)*)159        }160    };161162    (163        select_runtime(unique),164        runtimes(unique, $($_runtime_tl:tt)*),165        selected_pallets($($selected_pallets:tt)*),166167        where_clause($($where_clause:tt)*),168        pallets(169            $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal,170            $($pallets_tl:tt)*171        )172    ) => {173        $crate::construct_runtime_helper! {174            select_runtime(unique),175            selected_pallets(176                $($selected_pallets)*177                $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,178            ),179180            where_clause($($where_clause)*),181            pallets($($pallets_tl)*)182        }183    };184185    (186        select_runtime($select_runtime:ident),187        runtimes($_current_runtime:ident, $($runtime_tl:tt)*),188        selected_pallets($($selected_pallets:tt)*),189190        where_clause($($where_clause:tt)*),191        pallets($($pallets:tt)*)192    ) => {193        $crate::add_runtime_specific_pallets! {194            select_runtime($select_runtime),195            runtimes($($runtime_tl)*),196            selected_pallets($($selected_pallets)*),197198            where_clause($($where_clause)*),199            pallets($($pallets)*)200        }201    };202203    (204        select_runtime($select_runtime:ident),205        runtimes(),206        selected_pallets($($selected_pallets:tt)*),207208        where_clause($($where_clause:tt)*),209        pallets(210            $_pallet_name:ident: $_pallet_mod:ident$(::{$($_pallet_parts:ty),*})? = $_index:literal,211            $($pallets_tl:tt)*212        )213    ) => {214        $crate::construct_runtime_helper! {215            select_runtime($select_runtime),216            selected_pallets($($selected_pallets)*),217218            where_clause($($where_clause)*),219            pallets($($pallets_tl)*)220        }221    };222}