Skip to content

Commit f18b27a

Browse files
bkonturbkchr
authored andcommitted
[xcm] runtime api for LocationToAccount conversions (paritytech#4857)
Closes: paritytech#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]>
1 parent 9110ada commit f18b27a

47 files changed

Lines changed: 546 additions & 208 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ members = [
226226
"polkadot/xcm/xcm-builder",
227227
"polkadot/xcm/xcm-executor",
228228
"polkadot/xcm/xcm-executor/integration-tests",
229-
"polkadot/xcm/xcm-fee-payment-runtime-api",
229+
"polkadot/xcm/xcm-runtime-apis",
230230
"polkadot/xcm/xcm-simulator",
231231
"polkadot/xcm/xcm-simulator/example",
232232
"polkadot/xcm/xcm-simulator/fuzzer",
@@ -1337,8 +1337,8 @@ xcm-builder = { path = "polkadot/xcm/xcm-builder", default-features = false, pac
13371337
xcm-docs = { path = "polkadot/xcm/docs" }
13381338
xcm-emulator = { path = "cumulus/xcm/xcm-emulator", default-features = false }
13391339
xcm-executor = { path = "polkadot/xcm/xcm-executor", default-features = false, package = "staging-xcm-executor" }
1340-
xcm-fee-payment-runtime-api = { path = "polkadot/xcm/xcm-fee-payment-runtime-api", default-features = false }
13411340
xcm-procedural = { path = "polkadot/xcm/procedural", default-features = false }
1341+
xcm-runtime-apis = { path = "polkadot/xcm/xcm-runtime-apis", default-features = false }
13421342
xcm-simulator = { path = "polkadot/xcm/xcm-simulator", default-features = false }
13431343
zeroize = { version = "1.7.0", default-features = false }
13441344
zstd = { version = "0.12.4", default-features = false }

cumulus/parachains/integration-tests/emulated/chains/relays/westend/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ polkadot-primitives = { workspace = true }
2626
westend-runtime-constants = { workspace = true }
2727
westend-runtime = { workspace = true }
2828
xcm = { workspace = true }
29-
xcm-fee-payment-runtime-api = { workspace = true }
29+
xcm-runtime-apis = { workspace = true }
3030

3131
# Cumulus
3232
parachains-common = { workspace = true, default-features = true }

cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ polkadot-runtime-common = { workspace = true, default-features = true }
3434
xcm = { workspace = true }
3535
xcm-executor = { workspace = true }
3636
pallet-xcm = { workspace = true }
37-
xcm-fee-payment-runtime-api = { workspace = true }
37+
xcm-runtime-apis = { workspace = true }
3838
westend-runtime = { workspace = true }
3939

4040
# Cumulus

cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/xcm_fee_estimation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use crate::imports::*;
1919

2020
use frame_system::RawOrigin;
21-
use xcm_fee_payment_runtime_api::{
21+
use xcm_runtime_apis::{
2222
dry_run::runtime_decl_for_dry_run_api::DryRunApiV1,
2323
fees::runtime_decl_for_xcm_payment_api::XcmPaymentApiV1,
2424
};

cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ polkadot-runtime-common = { workspace = true }
7070
xcm = { workspace = true }
7171
xcm-builder = { workspace = true }
7272
xcm-executor = { workspace = true }
73-
xcm-fee-payment-runtime-api = { workspace = true }
73+
xcm-runtime-apis = { workspace = true }
7474

7575
# Cumulus
7676
cumulus-pallet-aura-ext = { workspace = true }
@@ -139,7 +139,7 @@ runtime-benchmarks = [
139139
"sp-runtime/runtime-benchmarks",
140140
"xcm-builder/runtime-benchmarks",
141141
"xcm-executor/runtime-benchmarks",
142-
"xcm-fee-payment-runtime-api/runtime-benchmarks",
142+
"xcm-runtime-apis/runtime-benchmarks",
143143
]
144144
try-runtime = [
145145
"cumulus-pallet-aura-ext/try-runtime",
@@ -250,7 +250,7 @@ std = [
250250
"testnet-parachains-constants/std",
251251
"xcm-builder/std",
252252
"xcm-executor/std",
253-
"xcm-fee-payment-runtime-api/std",
253+
"xcm-runtime-apis/std",
254254
"xcm/std",
255255
]
256256

cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ use xcm::{
100100
latest::prelude::{AssetId, BodyId},
101101
VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
102102
};
103-
use xcm_fee_payment_runtime_api::{
103+
use xcm_runtime_apis::{
104104
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
105105
fees::Error as XcmPaymentApiError,
106106
};
@@ -1322,7 +1322,7 @@ impl_runtime_apis! {
13221322
}
13231323
}
13241324

1325-
impl xcm_fee_payment_runtime_api::fees::XcmPaymentApi<Block> for Runtime {
1325+
impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
13261326
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
13271327
let acceptable_assets = vec![AssetId(xcm_config::TokenLocation::get())];
13281328
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
@@ -1335,11 +1335,11 @@ impl_runtime_apis! {
13351335
Ok(WeightToFee::weight_to_fee(&weight))
13361336
},
13371337
Ok(asset_id) => {
1338-
log::trace!(target: "xcm::xcm_fee_payment_runtime_api", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
1338+
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
13391339
Err(XcmPaymentApiError::AssetNotFound)
13401340
},
13411341
Err(_) => {
1342-
log::trace!(target: "xcm::xcm_fee_payment_runtime_api", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
1342+
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
13431343
Err(XcmPaymentApiError::VersionedConversionFailed)
13441344
}
13451345
}
@@ -1354,7 +1354,7 @@ impl_runtime_apis! {
13541354
}
13551355
}
13561356

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

1367+
impl xcm_runtime_apis::conversions::LocationToAccountApi<Block, AccountId> for Runtime {
1368+
fn convert_location(location: VersionedLocation) -> Result<
1369+
AccountId,
1370+
xcm_runtime_apis::conversions::Error
1371+
> {
1372+
xcm_runtime_apis::conversions::LocationToAccountHelper::<
1373+
AccountId,
1374+
xcm_config::LocationToAccountId,
1375+
>::convert_location(location)
1376+
}
1377+
}
1378+
13671379
impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
13681380
fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
13691381
ParachainSystem::collect_collation_info(header)

cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ westend-runtime-constants = { workspace = true }
6969
xcm = { workspace = true }
7070
xcm-builder = { workspace = true }
7171
xcm-executor = { workspace = true }
72-
xcm-fee-payment-runtime-api = { workspace = true }
72+
xcm-runtime-apis = { workspace = true }
7373

7474
# Cumulus
7575
cumulus-pallet-aura-ext = { workspace = true }
@@ -138,7 +138,7 @@ runtime-benchmarks = [
138138
"sp-runtime/runtime-benchmarks",
139139
"xcm-builder/runtime-benchmarks",
140140
"xcm-executor/runtime-benchmarks",
141-
"xcm-fee-payment-runtime-api/runtime-benchmarks",
141+
"xcm-runtime-apis/runtime-benchmarks",
142142
]
143143
try-runtime = [
144144
"cumulus-pallet-aura-ext/try-runtime",
@@ -249,7 +249,7 @@ std = [
249249
"westend-runtime-constants/std",
250250
"xcm-builder/std",
251251
"xcm-executor/std",
252-
"xcm-fee-payment-runtime-api/std",
252+
"xcm-runtime-apis/std",
253253
"xcm/std",
254254
]
255255

0 commit comments

Comments
 (0)