xcm_config.rs 2.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Copyright 2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.

Shawn Tabrizi's avatar
Shawn Tabrizi committed
17
use frame_support::{parameter_types, traits::Everything, weights::Weight};
18
use xcm::latest::prelude::*;
19
20
21
22
23
24
25
26
use xcm_builder::{AllowUnpaidExecutionFrom, FixedWeightBounds, SignedToAccountId32};
use xcm_executor::{
	traits::{InvertLocation, TransactAsset, WeightTrader},
	Assets,
};

parameter_types! {
	pub const OurNetwork: NetworkId = NetworkId::Polkadot;
27
	pub const MaxInstructions: u32 = 100;
28
29
30
31
32
33
34
35
36
37
38
}

/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location
/// of this chain.
pub type LocalOriginToLocation = (
	// And a usual Signed origin to be used in XCM as a corresponding AccountId32
	SignedToAccountId32<crate::Origin, crate::AccountId, OurNetwork>,
);

pub struct DoNothingRouter;
impl SendXcm for DoNothingRouter {
39
	fn send_xcm(_dest: MultiLocation, _msg: Xcm<()>) -> SendResult {
40
41
42
43
		Ok(())
	}
}

Shawn Tabrizi's avatar
Shawn Tabrizi committed
44
pub type Barrier = AllowUnpaidExecutionFrom<Everything>;
45
46
47
48
49
50
51
52

pub struct DummyAssetTransactor;
impl TransactAsset for DummyAssetTransactor {
	fn deposit_asset(_what: &MultiAsset, _who: &MultiLocation) -> XcmResult {
		Ok(())
	}

	fn withdraw_asset(_what: &MultiAsset, _who: &MultiLocation) -> Result<Assets, XcmError> {
53
		let asset: MultiAsset = (Parent, 100_000).into();
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
		Ok(asset.into())
	}
}

pub struct DummyWeightTrader;
impl WeightTrader for DummyWeightTrader {
	fn new() -> Self {
		DummyWeightTrader
	}

	fn buy_weight(&mut self, _weight: Weight, _payment: Assets) -> Result<Assets, XcmError> {
		Ok(Assets::default())
	}
}

pub struct InvertNothing;
impl InvertLocation for InvertNothing {
	fn invert_location(_: &MultiLocation) -> MultiLocation {
72
		Here.into()
73
74
75
76
77
78
79
80
81
82
83
84
85
	}
}

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
	type Call = super::Call;
	type XcmSender = DoNothingRouter;
	type AssetTransactor = DummyAssetTransactor;
	type OriginConverter = pallet_xcm::XcmPassthrough<super::Origin>;
	type IsReserve = ();
	type IsTeleporter = ();
	type LocationInverter = InvertNothing;
	type Barrier = Barrier;
86
	type Weigher = FixedWeightBounds<super::BaseXcmWeight, super::Call, MaxInstructions>;
87
	type Trader = DummyWeightTrader;
88
	type ResponseHandler = super::Xcm;
89
}