referrerpolicy=no-referrer-when-downgrade

bp_xcm_bridge_hub_router/
lib.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//! Primitives of the `xcm-bridge-hub-router` pallet.
18
19#![cfg_attr(not(feature = "std"), no_std)]
20
21use codec::{Decode, Encode, MaxEncodedLen};
22use scale_info::TypeInfo;
23use sp_core::H256;
24use sp_runtime::{FixedU128, RuntimeDebug};
25use xcm::latest::prelude::Location;
26
27/// Minimal delivery fee factor.
28pub const MINIMAL_DELIVERY_FEE_FACTOR: FixedU128 = FixedU128::from_u32(1);
29
30/// XCM channel status provider that may report whether it is congested or not.
31///
32/// By channel we mean the physical channel that is used to deliver messages of one
33/// of the bridge queues.
34pub trait XcmChannelStatusProvider {
35	/// Returns true if the channel is currently congested.
36	fn is_congested(with: &Location) -> bool;
37}
38
39impl XcmChannelStatusProvider for () {
40	fn is_congested(_with: &Location) -> bool {
41		false
42	}
43}
44
45/// Current status of the bridge.
46#[derive(Clone, Decode, Encode, Eq, PartialEq, TypeInfo, MaxEncodedLen, RuntimeDebug)]
47pub struct BridgeState {
48	/// Current delivery fee factor.
49	pub delivery_fee_factor: FixedU128,
50	/// Bridge congestion flag.
51	pub is_congested: bool,
52}
53
54impl Default for BridgeState {
55	fn default() -> BridgeState {
56		BridgeState { delivery_fee_factor: MINIMAL_DELIVERY_FEE_FACTOR, is_congested: false }
57	}
58}
59
60/// A minimized version of `pallet-xcm-bridge-hub-router::Call` that can be used without a runtime.
61#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
62#[allow(non_camel_case_types)]
63pub enum XcmBridgeHubRouterCall {
64	/// `pallet-xcm-bridge-hub-router::Call::report_bridge_status`
65	#[codec(index = 0)]
66	report_bridge_status { bridge_id: H256, is_congested: bool },
67}