1
// Copyright 2019-2022 PureStake Inc.
2
// This file is part of Moonbeam.
3

            
4
// Moonbeam 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
// Moonbeam 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 Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
use frame_support::{parameter_types, traits::ContainsPair, weights::Weight};
18
use xcm::latest::prelude::*;
19
use xcm_executor::traits::ConvertLocation;
20

            
21
// An xcm sender/receiver akin to > /dev/null
22
pub struct DevNull;
23
impl SendXcm for DevNull {
24
	type Ticket = ();
25

            
26
	fn validate(
27
		_destination: &mut Option<Location>,
28
		_message: &mut Option<opaque::Xcm>,
29
	) -> SendResult<Self::Ticket> {
30
		Ok(((), Assets::new()))
31
	}
32

            
33
	fn deliver(_: Self::Ticket) -> Result<XcmHash, SendError> {
34
		Ok(XcmHash::default())
35
	}
36
}
37

            
38
impl xcm_executor::traits::OnResponse for DevNull {
39
	fn expecting_response(_: &Location, _: u64, _: Option<&Location>) -> bool {
40
		false
41
	}
42
	fn on_response(
43
		_: &Location,
44
		_: u64,
45
		_: Option<&Location>,
46
		_: Response,
47
		_: Weight,
48
		_: &XcmContext,
49
	) -> Weight {
50
		Weight::zero()
51
	}
52
}
53

            
54
pub struct AccountIdConverter;
55
impl ConvertLocation<u64> for AccountIdConverter {
56
	fn convert_location(ml: &Location) -> Option<u64> {
57
		match ml.unpack() {
58
			(0, [Junction::AccountId32 { id, .. }]) => {
59
				Some(<u64 as parity_scale_codec::Decode>::decode(&mut &*id.to_vec()).unwrap())
60
			}
61
			_ => None,
62
		}
63
	}
64
}
65

            
66
parameter_types! {
67
	pub Ancestry: Location = Junction::Parachain(101).into();
68
	pub UnitWeightCost: u64 = 10;
69
	pub WeightPrice: (AssetId, u128, u128) = (AssetId(Location::parent()), 1_000_000, 1024);
70
}
71

            
72
pub struct AllAssetLocationsPass;
73
impl ContainsPair<Asset, Location> for AllAssetLocationsPass {
74
	fn contains(_: &Asset, _: &Location) -> bool {
75
		true
76
	}
77
}
78

            
79
#[cfg(feature = "runtime-benchmarks")]
80
pub fn mock_worst_case_holding() -> Assets {
81
	let assets: Vec<Asset> = vec![Asset {
82
		id: AssetId(Location::parent()),
83
		fun: Fungible(u128::MAX),
84
	}];
85
	assets.into()
86
}