Skip to content
Draft
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
6 changes: 5 additions & 1 deletion polkadot/node/service/src/fake_runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use sp_runtime::{
use sp_version::RuntimeVersion;
use sp_weights::Weight;
use std::collections::BTreeMap;
use xcm::{VersionedAssetId, VersionedXcm};
use xcm::{latest::Assets, VersionedAssetId, VersionedLocation, VersionedXcm};
sp_api::decl_runtime_apis! {
/// This runtime API is only implemented for the test runtime!
pub trait GetLastTimestamp {
Expand Down Expand Up @@ -412,5 +412,9 @@ sp_api::impl_runtime_apis! {
fn query_xcm_weight(_: VersionedXcm<RuntimeCall>) -> Result<Weight, xcm_payment_runtime_api::Error> {
unimplemented!()
}

fn query_xcm_delivery_fees(_: VersionedLocation, _: VersionedXcm<()>) -> Result<Assets, xcm_payment_runtime_api::Error> {
unimplemented!()
}
}
}
17 changes: 17 additions & 0 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use runtime_common::{
},
paras_registrar, paras_sudo_wrapper, prod_or_fast, slots,
traits::Leaser,
xcm_sender::PriceForMessageDelivery as _,
BlockHashCount, BlockLength, SlowAdjustingFeeUpdate,
};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -1830,6 +1831,22 @@ sp_api::impl_runtime_apis! {
<xcm_config::XcmConfig as xcm_executor::Config>::Weigher::weight(&mut message)
.map_err(|_| XcmPaymentApiError::WeightNotComputable)
}

fn query_xcm_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<Assets, XcmPaymentApiError> {
let destination = destination
.into_version(4)
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
let VersionedLocation::V4(Location { parents: 0, interior: junctions}) = destination else {
return Err(XcmPaymentApiError::Unroutable);
};
let (Junctions::Here, Some(Junction::Parachain(para_id))) = junctions.split_first() else {
return Err(XcmPaymentApiError::Unroutable);
};
let message = message
.try_into()
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
Ok(xcm_config::PriceForChildParachainDelivery::price_for_delivery(para_id.into(), &message))
}
}

impl sp_api::Metadata<Block> for Runtime {
Expand Down
18 changes: 17 additions & 1 deletion polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*};
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use xcm::{
latest::{InteriorLocation, Junction, Junction::PalletInstance},
latest::{Assets, InteriorLocation, Junction, Junction::PalletInstance},
IntoVersion, VersionedAssetId, VersionedLocation, VersionedXcm,
};
use xcm_builder::PayOverXcm;
Expand Down Expand Up @@ -2287,6 +2287,22 @@ sp_api::impl_runtime_apis! {
<xcm_config::XcmConfig as xcm_executor::Config>::Weigher::weight(&mut message)
.map_err(|_| XcmPaymentApiError::WeightNotComputable)
}

fn query_xcm_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<Assets, XcmPaymentApiError> {
let destination = destination
.into_version(4)
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
let VersionedLocation::V4(Location { parents: 0, interior: junctions}) = destination else {
return Err(XcmPaymentApiError::Unroutable);
};
let (Junctions::Here, Some(Junction::Parachain(para_id))) = junctions.split_first() else {
return Err(XcmPaymentApiError::Unroutable);
};
let message = message
.try_into()
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
Ok(xcm_config::PriceForChildParachainDelivery::price_for_delivery(para_id.into(), &message))
}
}

impl pallet_nomination_pools_runtime_api::NominationPoolsApi<
Expand Down
13 changes: 12 additions & 1 deletion polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use codec::{Codec, Decode, Encode};
use frame_support::pallet_prelude::TypeInfo;
use sp_std::vec::Vec;
use sp_weights::Weight;
use xcm::{Version, VersionedAssetId, VersionedXcm};
use xcm::{latest::Assets, Version, VersionedAssetId, VersionedLocation, VersionedXcm};

sp_api::decl_runtime_apis! {
/// A trait of XCM payment API.
Expand Down Expand Up @@ -60,6 +60,14 @@ sp_api::decl_runtime_apis! {
/// * `weight`: convertible `Weight`.
/// * `asset`: `VersionedAssetId`.
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, Error>;

/// Returns a fee needed to deliver a XCM.
///
/// # Arguments
///
/// * `destination`: `VersionedLocation`.
/// * `message`: `VersionedXcm`.
fn query_xcm_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<Assets, Error>;
}
}

Expand All @@ -79,4 +87,7 @@ pub enum Error {
/// The given asset is not handled(as a fee payment).
#[codec(index = 4)]
AssetNotFound,
/// Destination is known to be unroutable.
#[codec(index = 5)]
Unroutable,
}