referrerpolicy=no-referrer-when-downgrade

xcm_docs/cookbook/relay_token_transactor/relay_chain/
mod.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
3// This file is part of Polkadot.
4
5// Polkadot is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9
10// Polkadot is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
17
18//! Relay chain runtime mock.
19
20use frame::{
21	deps::{frame_support::weights::WeightMeter, sp_runtime::AccountId32},
22	prelude::*,
23	runtime::prelude::*,
24	traits::{IdentityLookup, ProcessMessage, ProcessMessageError},
25};
26use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};
27use xcm::latest::prelude::*;
28
29mod xcm_config;
30pub use xcm_config::LocationToAccountId;
31use xcm_config::XcmConfig;
32
33pub type AccountId = AccountId32;
34pub type Balance = u64;
35
36parameter_types! {
37	pub const BlockHashCount: u64 = 250;
38}
39
40#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
41impl frame_system::Config for Runtime {
42	type AccountId = AccountId;
43	type Lookup = IdentityLookup<Self::AccountId>;
44	type Block = Block;
45	type AccountData = pallet_balances::AccountData<Balance>;
46}
47
48#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
49impl pallet_balances::Config for Runtime {
50	type AccountStore = System;
51}
52
53type Block = frame_system::mocking::MockBlock<Runtime>;
54
55parameter_types! {
56	/// Amount of weight that can be spent per block to service messages.
57	pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000);
58	pub const MessageQueueHeapSize: u32 = 65_536;
59	pub const MessageQueueMaxStale: u32 = 16;
60}
61
62/// Message processor to handle any messages that were enqueued into the `MessageQueue` pallet.
63pub struct MessageProcessor;
64impl ProcessMessage for MessageProcessor {
65	type Origin = AggregateMessageOrigin;
66
67	fn process_message(
68		message: &[u8],
69		origin: Self::Origin,
70		meter: &mut WeightMeter,
71		id: &mut [u8; 32],
72	) -> Result<bool, ProcessMessageError> {
73		let para = match origin {
74			AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para,
75		};
76		xcm_builder::ProcessXcmMessage::<
77			Junction,
78			xcm_executor::XcmExecutor<XcmConfig>,
79			RuntimeCall,
80		>::process_message(message, Junction::Parachain(para.into()), meter, id)
81	}
82}
83
84impl pallet_message_queue::Config for Runtime {
85	type RuntimeEvent = RuntimeEvent;
86	type Size = u32;
87	type HeapSize = MessageQueueHeapSize;
88	type MaxStale = MessageQueueMaxStale;
89	type ServiceWeight = MessageQueueServiceWeight;
90	type MessageProcessor = MessageProcessor;
91	type QueueChangeHandler = ();
92	type QueuePausedQuery = ();
93	type WeightInfo = ();
94	type IdleMaxServiceWeight = MessageQueueServiceWeight;
95}
96
97construct_runtime! {
98	pub struct Runtime {
99		System: frame_system,
100		Balances: pallet_balances,
101		MessageQueue: pallet_message_queue,
102		XcmPallet: pallet_xcm,
103	}
104}