1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
45// 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.
1617//! Helpers to deal with configuring the message queue in the runtime.
1819use core::marker::PhantomData;
20use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
21use frame_support::traits::{QueueFootprint, QueuePausedQuery};
22use pallet_message_queue::OnQueueChanged;
2324/// 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>
29for NarrowOriginToSibling<Inner>
30{
31fn is_paused(origin: &AggregateMessageOrigin) -> bool {
32match origin {
33 AggregateMessageOrigin::Sibling(id) => Inner::is_paused(id),
34_ => false,
35 }
36 }
37}
3839impl<Inner: OnQueueChanged<ParaId>> OnQueueChanged<AggregateMessageOrigin>
40for NarrowOriginToSibling<Inner>
41{
42fn on_queue_changed(origin: AggregateMessageOrigin, fp: QueueFootprint) {
43if let AggregateMessageOrigin::Sibling(id) = origin {
44 Inner::on_queue_changed(id, fp)
45 }
46 }
47}
4849/// Convert a sibling `ParaId` to an `AggregateMessageOrigin`.
50pub struct ParaIdToSibling;
51impl sp_runtime::traits::Convert<ParaId, AggregateMessageOrigin> for ParaIdToSibling {
52fn convert(para_id: ParaId) -> AggregateMessageOrigin {
53 AggregateMessageOrigin::Sibling(para_id)
54 }
55}