xcm_runtime_apis/trusted_query.rs
1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot 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// Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>.
16
17//! Runtime API definition for checking if given <Asset, Location> is trusted reserve or teleporter.
18
19use codec::{Decode, Encode};
20use frame_support::pallet_prelude::TypeInfo;
21use xcm::{VersionedAsset, VersionedLocation};
22
23/// Result of [`TrustedQueryApi`] functions.
24pub type XcmTrustedQueryResult = Result<bool, Error>;
25
26sp_api::decl_runtime_apis! {
27 // API for querying trusted reserves and trusted teleporters.
28 pub trait TrustedQueryApi {
29 /// Returns if the location is a trusted reserve for the asset.
30 ///
31 /// # Arguments
32 /// * `asset`: `VersionedAsset`.
33 /// * `location`: `VersionedLocation`.
34 fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> XcmTrustedQueryResult;
35 /// Returns if the asset can be teleported to the location.
36 ///
37 /// # Arguments
38 /// * `asset`: `VersionedAsset`.
39 /// * `location`: `VersionedLocation`.
40 fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> XcmTrustedQueryResult;
41 }
42}
43
44#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)]
45pub enum Error {
46 /// Converting a versioned Asset structure from one version to another failed.
47 VersionedAssetConversionFailed,
48 /// Converting a versioned Location structure from one version to another failed.
49 VersionedLocationConversionFailed,
50}