referrerpolicy=no-referrer-when-downgrade

parachains_common/
message_queue.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
4
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// 	http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17//! Helpers to deal with configuring the message queue in the runtime.
18
19use core::marker::PhantomData;
20use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
21use frame_support::traits::{QueueFootprint, QueuePausedQuery};
22use pallet_message_queue::OnQueueChanged;
23
24/// Narrow the scope of the `Inner` query from `AggregateMessageOrigin` to `ParaId`.
25///
26/// All non-`Sibling` variants will be ignored.
27pub struct NarrowOriginToSibling<Inner>(PhantomData<Inner>);
28impl<Inner: QueuePausedQuery<ParaId>> QueuePausedQuery<AggregateMessageOrigin>
29	for NarrowOriginToSibling<Inner>
30{
31	fn is_paused(origin: &AggregateMessageOrigin) -> bool {
32		match origin {
33			AggregateMessageOrigin::Sibling(id) => Inner::is_paused(id),
34			_ => false,
35		}
36	}
37}
38
39impl<Inner: OnQueueChanged<ParaId>> OnQueueChanged<AggregateMessageOrigin>
40	for NarrowOriginToSibling<Inner>
41{
42	fn on_queue_changed(origin: AggregateMessageOrigin, fp: QueueFootprint) {
43		if let AggregateMessageOrigin::Sibling(id) = origin {
44			Inner::on_queue_changed(id, fp)
45		}
46	}
47}
48
49/// Convert a sibling `ParaId` to an `AggregateMessageOrigin`.
50pub struct ParaIdToSibling;
51impl sp_runtime::traits::Convert<ParaId, AggregateMessageOrigin> for ParaIdToSibling {
52	fn convert(para_id: ParaId) -> AggregateMessageOrigin {
53		AggregateMessageOrigin::Sibling(para_id)
54	}
55}