Skip to content

Commit

Permalink
[xcm] runtime api for LocationToAccount conversions (#4857)
Browse files Browse the repository at this point in the history
Closes: #4298

This PR also merges `xcm-fee-payment-runtime-api` module to the
`xcm-runtime-api`.


## TODO

- [x] rename `convert` to `convert_location` and add new one
`convert_account` (opposite direction)
- [x] add to the all testnet runtimes
- [x] check polkadot-js if supports that automatically or if needs to be
added manually polkadot-js/api#5917
- [ ] backport/patch for fellows and release (asap)

## Open questions
- [x] should we merge `xcm-runtime-api` and
`xcm-fee-payment-runtime-api` to the one module `xcm-runtime-api` ?

## Usage
Input:
 - `location:  VersionedLocation`
 
Output:
 - account_id bytes


![image](https://github.com/paritytech/polkadot-sdk/assets/8159517/4607b15a-77d2-462b-806c-606107776c0d)

---------

Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
bkontur and bkchr authored Jun 26, 2024
1 parent 7084463 commit 7506956
Show file tree
Hide file tree
Showing 47 changed files with 546 additions and 208 deletions.
64 changes: 32 additions & 32 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ members = [
"polkadot/xcm/xcm-builder",
"polkadot/xcm/xcm-executor",
"polkadot/xcm/xcm-executor/integration-tests",
"polkadot/xcm/xcm-fee-payment-runtime-api",
"polkadot/xcm/xcm-runtime-apis",
"polkadot/xcm/xcm-simulator",
"polkadot/xcm/xcm-simulator/example",
"polkadot/xcm/xcm-simulator/fuzzer",
Expand Down Expand Up @@ -1337,8 +1337,8 @@ xcm-builder = { path = "polkadot/xcm/xcm-builder", default-features = false, pac
xcm-docs = { path = "polkadot/xcm/docs" }
xcm-emulator = { path = "cumulus/xcm/xcm-emulator", default-features = false }
xcm-executor = { path = "polkadot/xcm/xcm-executor", default-features = false, package = "staging-xcm-executor" }
xcm-fee-payment-runtime-api = { path = "polkadot/xcm/xcm-fee-payment-runtime-api", default-features = false }
xcm-procedural = { path = "polkadot/xcm/procedural", default-features = false }
xcm-runtime-apis = { path = "polkadot/xcm/xcm-runtime-apis", default-features = false }
xcm-simulator = { path = "polkadot/xcm/xcm-simulator", default-features = false }
zeroize = { version = "1.7.0", default-features = false }
zstd = { version = "0.12.4", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ polkadot-primitives = { workspace = true }
westend-runtime-constants = { workspace = true }
westend-runtime = { workspace = true }
xcm = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }
xcm-runtime-apis = { workspace = true }

# Cumulus
parachains-common = { workspace = true, default-features = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ polkadot-runtime-common = { workspace = true, default-features = true }
xcm = { workspace = true }
xcm-executor = { workspace = true }
pallet-xcm = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }
xcm-runtime-apis = { workspace = true }
westend-runtime = { workspace = true }

# Cumulus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::imports::*;

use frame_system::RawOrigin;
use xcm_fee_payment_runtime_api::{
use xcm_runtime_apis::{
dry_run::runtime_decl_for_dry_run_api::DryRunApiV1,
fees::runtime_decl_for_xcm_payment_api::XcmPaymentApiV1,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ polkadot-runtime-common = { workspace = true }
xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }
xcm-runtime-apis = { workspace = true }

# Cumulus
cumulus-pallet-aura-ext = { workspace = true }
Expand Down Expand Up @@ -139,7 +139,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm-fee-payment-runtime-api/runtime-benchmarks",
"xcm-runtime-apis/runtime-benchmarks",
]
try-runtime = [
"cumulus-pallet-aura-ext/try-runtime",
Expand Down Expand Up @@ -250,7 +250,7 @@ std = [
"testnet-parachains-constants/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm-fee-payment-runtime-api/std",
"xcm-runtime-apis/std",
"xcm/std",
]

Expand Down
22 changes: 17 additions & 5 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ use xcm::{
latest::prelude::{AssetId, BodyId},
VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
};
use xcm_fee_payment_runtime_api::{
use xcm_runtime_apis::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
};
Expand Down Expand Up @@ -1322,7 +1322,7 @@ impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::fees::XcmPaymentApi<Block> for Runtime {
impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
let acceptable_assets = vec![AssetId(xcm_config::TokenLocation::get())];
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
Expand All @@ -1335,11 +1335,11 @@ impl_runtime_apis! {
Ok(WeightToFee::weight_to_fee(&weight))
},
Ok(asset_id) => {
log::trace!(target: "xcm::xcm_fee_payment_runtime_api", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
Err(XcmPaymentApiError::AssetNotFound)
},
Err(_) => {
log::trace!(target: "xcm::xcm_fee_payment_runtime_api", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
Err(XcmPaymentApiError::VersionedConversionFailed)
}
}
Expand All @@ -1354,7 +1354,7 @@ impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call)
}
Expand All @@ -1364,6 +1364,18 @@ impl_runtime_apis! {
}
}

impl xcm_runtime_apis::conversions::LocationToAccountApi<Block, AccountId> for Runtime {
fn convert_location(location: VersionedLocation) -> Result<
AccountId,
xcm_runtime_apis::conversions::Error
> {
xcm_runtime_apis::conversions::LocationToAccountHelper::<
AccountId,
xcm_config::LocationToAccountId,
>::convert_location(location)
}
}

impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
ParachainSystem::collect_collation_info(header)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ westend-runtime-constants = { workspace = true }
xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }
xcm-runtime-apis = { workspace = true }

# Cumulus
cumulus-pallet-aura-ext = { workspace = true }
Expand Down Expand Up @@ -138,7 +138,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm-fee-payment-runtime-api/runtime-benchmarks",
"xcm-runtime-apis/runtime-benchmarks",
]
try-runtime = [
"cumulus-pallet-aura-ext/try-runtime",
Expand Down Expand Up @@ -249,7 +249,7 @@ std = [
"westend-runtime-constants/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm-fee-payment-runtime-api/std",
"xcm-runtime-apis/std",
"xcm/std",
]

Expand Down
Loading

0 comments on commit 7506956

Please sign in to comment.