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
#![cfg_attr(not(feature = "std"), no_std)]
18

            
19
use frame_support::traits::Get;
20
use xcm::latest::prelude::*;
21

            
22
pub use dp_xcm_reserve::NativeAssetReserve;
23

            
24
/// Filter to ensure an ETH asset is coming from a trusted Ethereum location.
25
pub struct EthereumAssetReserve<EthereumLocation, EthereumNetwork>(
26
    core::marker::PhantomData<(EthereumLocation, EthereumNetwork)>,
27
);
28
impl<EthereumLocation, EthereumNetwork> frame_support::traits::ContainsPair<Asset, Location>
29
    for EthereumAssetReserve<EthereumLocation, EthereumNetwork>
30
where
31
    EthereumLocation: Get<Location>,
32
    EthereumNetwork: Get<NetworkId>,
33
{
34
72
    fn contains(asset: &Asset, origin: &Location) -> bool {
35
72
        log::trace!(target: "xcm::contains", "EthereumAssetReserve asset: {:?}, origin: {:?}", asset, origin);
36
72
        if *origin != EthereumLocation::get() {
37
4
            return false;
38
68
        }
39
68
        matches!((asset.id.0.parents, asset.id.0.first_interior()), (1, Some(GlobalConsensus(network))) if *network == EthereumNetwork::get())
40
72
    }
41
}
42

            
43
/// Filter to ensure an ETH asset is coming from a parent.
44
pub struct EthereumAssetReserveFromParent<EthereumLocation, EthereumNetwork>(
45
    core::marker::PhantomData<(EthereumLocation, EthereumNetwork)>,
46
);
47
impl<EthereumLocation, EthereumNetwork> frame_support::traits::ContainsPair<Asset, Location>
48
    for EthereumAssetReserveFromParent<EthereumLocation, EthereumNetwork>
49
where
50
    EthereumLocation: Get<Location>,
51
    EthereumNetwork: Get<NetworkId>,
52
{
53
18
    fn contains(asset: &Asset, origin: &Location) -> bool {
54
18
        log::trace!(target: "xcm::contains", "EthereumAssetReserveFromPara asset: {:?}, origin: {:?}, eth_network: {:?}", asset, origin, EthereumLocation::get());
55
18
        if *origin == EthereumLocation::get() || *origin == Location::parent() {
56
16
            return matches!((asset.id.0.parents, asset.id.0.first_interior()), (2, Some(GlobalConsensus(network))) if *network == EthereumNetwork::get());
57
2
        }
58
2
        return false;
59
18
    }
60
}