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

            
21
use parity_scale_codec::{Decode, Encode, FullCodec, MaxEncodedLen};
22
use scale_info::TypeInfo;
23
use sp_core::sp_std::fmt::Debug;
24
use sp_runtime::{FixedU128, RuntimeDebug};
25
use xcm::latest::prelude::{InteriorLocation, Location, NetworkId};
26

            
27
/// Current status of the bridge.
28
#[derive(Clone, Decode, Encode, Eq, PartialEq, TypeInfo, MaxEncodedLen, RuntimeDebug)]
29
pub struct BridgeState {
30
	/// Current delivery fee factor.
31
	pub delivery_fee_factor: FixedU128,
32
	/// Bridge congestion flag.
33
	pub is_congested: bool,
34
}
35

            
36
/// Trait that resolves a specific `BridgeId` for `dest`.
37
pub trait ResolveBridgeId {
38
	/// Bridge identifier.
39
	type BridgeId: FullCodec + MaxEncodedLen + TypeInfo + Debug + Clone + PartialEq + Eq;
40
	/// Resolves `Self::BridgeId` for `dest`. If `None`, it means there is no supported bridge ID.
41
	fn resolve_for_dest(bridged_dest: &Location) -> Option<Self::BridgeId>;
42

            
43
	/// Resolves `Self::BridgeId` for `bridged_network` and `bridged_dest`. If `None`, it means
44
	/// there is no supported bridge ID.
45
	fn resolve_for(
46
		bridged_network: &NetworkId,
47
		bridged_dest: &InteriorLocation,
48
	) -> Option<Self::BridgeId>;
49
}
50

            
51
/// The default implementation of `ResolveBridgeId` for `()` returns `None`.
52
impl ResolveBridgeId for () {
53
	type BridgeId = ();
54

            
55
	fn resolve_for_dest(_dest: &Location) -> Option<Self::BridgeId> {
56
		None
57
	}
58

            
59
	fn resolve_for(
60
		_bridged_network: &NetworkId,
61
		_bridged_dest: &InteriorLocation,
62
	) -> Option<Self::BridgeId> {
63
		None
64
	}
65
}
66

            
67
/// A minimized version of `pallet-xcm-bridge-router::Call` that can be used without a runtime.
68
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
69
#[allow(non_camel_case_types)]
70
pub enum XcmBridgeHubCall<BridgeId> {
71
	/// `pallet-xcm-bridge-router::Call::update_bridge_status`
72
	#[codec(index = 0)]
73
	update_bridge_status {
74
		bridge_id: BridgeId,
75
		is_congested: bool,
76
	},
77
}