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
extern crate alloc;
18

            
19
use {
20
    alloc::collections::btree_set::BTreeSet,
21
    frame_support::{parameter_types, traits::Contains},
22
    xcm::latest::prelude::*,
23
};
24

            
25
/// The pallet index of the Ethereum inbound queue pallet in the Tanssi runtime.
26
pub const PARENT_INBOUND_QUEUE_PALLET_INDEX: u8 = 24;
27

            
28
parameter_types! {
29
    pub EthereumNetworkSepolia: NetworkId = NetworkId::Ethereum { chain_id: 11155111 };
30
    pub EthereumNetworkMainnet: NetworkId = NetworkId::Ethereum { chain_id: 1 };
31

            
32
    pub ParentWithEthereumInboundQueueInstance: Location = Location::new(
33
        1,
34
        [
35
            PalletInstance(PARENT_INBOUND_QUEUE_PALLET_INDEX)
36
        ]
37
    );
38

            
39
    /// Universal aliases common to frontier and simple templates.
40
    pub CommonUniversalAliases: BTreeSet<(Location, Junction)> = BTreeSet::from_iter(
41
        alloc::vec![
42
            (ParentWithEthereumInboundQueueInstance::get(), GlobalConsensus(EthereumNetworkSepolia::get())),
43
            (ParentWithEthereumInboundQueueInstance::get(), GlobalConsensus(EthereumNetworkMainnet::get()))
44
        ]
45
    );
46
}
47

            
48
impl Contains<(Location, Junction)> for CommonUniversalAliases {
49
46
    fn contains(alias: &(Location, Junction)) -> bool {
50
46
        CommonUniversalAliases::get().contains(alias)
51
46
    }
52
}
53

            
54
#[cfg(feature = "runtime-benchmarks")]
55
pub struct AliasingBenchmarksHelper;
56

            
57
#[cfg(feature = "runtime-benchmarks")]
58
impl AliasingBenchmarksHelper {
59
    pub fn prepare_universal_alias() -> Option<(Location, Junction)> {
60
        let alias = CommonUniversalAliases::get()
61
            .into_iter()
62
            .find_map(|(location, junction)| {
63
                match ParentWithEthereumInboundQueueInstance::get().eq(&location) {
64
                    true => Some((location, junction)),
65
                    false => None,
66
                }
67
            });
68
        Some(alias.expect("Tanssi's InboundQueue to container-chain mapping expected here"))
69
    }
70
}