referrerpolicy=no-referrer-when-downgrade

bridge_runtime_common/
messages_api.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Parity Bridges Common.
3
4// Parity Bridges Common 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// Parity Bridges Common 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 Parity Bridges Common.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Helpers for implementing various message-related runtime API methods.
18
19use bp_messages::{InboundMessageDetails, MessageNonce, MessagePayload, OutboundMessageDetails};
20use sp_std::vec::Vec;
21
22/// Implementation of the `To*OutboundLaneApi::message_details`.
23pub fn outbound_message_details<Runtime, MessagesPalletInstance>(
24	lane: Runtime::LaneId,
25	begin: MessageNonce,
26	end: MessageNonce,
27) -> Vec<OutboundMessageDetails>
28where
29	Runtime: pallet_bridge_messages::Config<MessagesPalletInstance>,
30	MessagesPalletInstance: 'static,
31{
32	(begin..=end)
33		.filter_map(|nonce| {
34			let message_data =
35				pallet_bridge_messages::Pallet::<Runtime, MessagesPalletInstance>::outbound_message_data(lane, nonce)?;
36			Some(OutboundMessageDetails {
37				nonce,
38				// dispatch message weight is always zero at the source chain, since we're paying for
39				// dispatch at the target chain
40				dispatch_weight: frame_support::weights::Weight::zero(),
41				size: message_data.len() as _,
42			})
43		})
44		.collect()
45}
46
47/// Implementation of the `To*InboundLaneApi::message_details`.
48pub fn inbound_message_details<Runtime, MessagesPalletInstance>(
49	lane: Runtime::LaneId,
50	messages: Vec<(MessagePayload, OutboundMessageDetails)>,
51) -> Vec<InboundMessageDetails>
52where
53	Runtime: pallet_bridge_messages::Config<MessagesPalletInstance>,
54	MessagesPalletInstance: 'static,
55{
56	messages
57		.into_iter()
58		.map(|(payload, details)| {
59			pallet_bridge_messages::Pallet::<Runtime, MessagesPalletInstance>::inbound_message_data(
60				lane, payload, details,
61			)
62		})
63		.collect()
64}