bridge_hub_common/xcm_version.rs
1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Custom XCM implementation.
17
18use frame_support::traits::Get;
19use xcm::{
20 latest::prelude::*,
21 prelude::{GetVersion, XcmVersion},
22};
23
24/// Adapter for the implementation of `GetVersion`, which attempts to find the minimal
25/// configured XCM version between the destination `dest` and the bridge hub location provided as
26/// `Get<Location>`.
27pub struct XcmVersionOfDestAndRemoteBridge<Version, RemoteBridge>(
28 sp_std::marker::PhantomData<(Version, RemoteBridge)>,
29);
30impl<Version: GetVersion, RemoteBridge: Get<Location>> GetVersion
31 for XcmVersionOfDestAndRemoteBridge<Version, RemoteBridge>
32{
33 fn get_version_for(dest: &Location) -> Option<XcmVersion> {
34 let dest_version = Version::get_version_for(dest);
35 let bridge_hub_version = Version::get_version_for(&RemoteBridge::get());
36
37 match (dest_version, bridge_hub_version) {
38 (Some(dv), Some(bhv)) => Some(sp_std::cmp::min(dv, bhv)),
39 (Some(dv), None) => Some(dv),
40 (None, Some(bhv)) => Some(bhv),
41 (None, None) => None,
42 }
43 }
44}