Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[xcm] Initial of runtime RPC for querying Fungibles from runtime #6777

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions xcm/xcm-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ scale-info = { version = "2.1.2", default-features = false, features = ["derive"
xcm = { path = "..", default-features = false }
xcm-executor = { path = "../xcm-executor", default-features = false }
sp-std = { git = "/~https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-api = { git = "/~https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-arithmetic = { git = "/~https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-io = { git = "/~https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "/~https://github.com/paritytech/substrate", branch = "master", default-features = false }
Expand Down Expand Up @@ -43,6 +44,7 @@ std = [
"xcm/std",
"xcm-executor/std",
"sp-std/std",
"sp-api/std",
"sp-arithmetic/std",
"sp-io/std",
"sp-runtime/std",
Expand Down
3 changes: 3 additions & 0 deletions xcm/xcm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ pub use universal_exports::{
HaulBlobError, HaulBlobExporter, NetworkExportTable, SovereignPaidRemoteExporter,
UnpaidLocalExporter, UnpaidRemoteExporter,
};

mod runtime_api;
pub use runtime_api::*;
44 changes: 44 additions & 0 deletions xcm/xcm-builder/src/runtime_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Runtime API definition for fungibles.
//!
//! (Initial version: /~https://github.com/paritytech/cumulus/pull/2180#issuecomment-1442952274)

use frame_support::RuntimeDebug;
use parity_scale_codec::{Codec, Decode, Encode};
use sp_std::vec::Vec;
use xcm::latest::MultiAsset;

/// The possible errors that can happen querying the storage of assets.
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug)]
pub enum FungiblesAccessError {
/// `MultiLocation` to `AssetId`/`ClassId` conversion failed.
AssetIdConversionFailed,
/// `u128` amount to currency `Balance` conversion failed.
AmountToBalanceConversionFailed,
}

sp_api::decl_runtime_apis! {
/// The API for querying account's balances from runtime.
pub trait FungiblesApi<AccountId>
where
AccountId: Codec,
{
/// Returns the list of all [`MultiAsset`] that an `AccountId` has.
fn query_account_balances(account: AccountId) -> Result<Vec<MultiAsset>, FungiblesAccessError>;
}
}