assets_common/runtime_api.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//! Runtime API definition for fungibles.
17
18use codec::{Codec, Decode, Encode};
19use sp_runtime::RuntimeDebug;
20#[cfg(feature = "std")]
21use {alloc::vec::Vec, xcm::latest::Asset};
22
23/// The possible errors that can happen querying the storage of assets.
24#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)]
25pub enum FungiblesAccessError {
26 /// `Location` to `AssetId`/`ClassId` conversion failed.
27 AssetIdConversionFailed,
28 /// `u128` amount to currency `Balance` conversion failed.
29 AmountToBalanceConversionFailed,
30}
31
32sp_api::decl_runtime_apis! {
33 /// The API for querying account's balances from runtime.
34 #[api_version(2)]
35 pub trait FungiblesApi<AccountId>
36 where
37 AccountId: Codec,
38 {
39 /// Returns the list of all [`Asset`] that an `AccountId` has.
40 #[changed_in(2)]
41 fn query_account_balances(account: AccountId) -> Result<Vec<Asset>, FungiblesAccessError>;
42
43 /// Returns the list of all [`Asset`] that an `AccountId` has.
44 fn query_account_balances(account: AccountId) -> Result<xcm::VersionedAssets, FungiblesAccessError>;
45 }
46}