From 85c244f6e6e59db23bdfcfef903fd9145f0546ad Mon Sep 17 00:00:00 2001
From: Carlo Sala <carlosalag@protonmail.com>
Date: Tue, 14 Jan 2025 20:57:05 +0100
Subject: [PATCH] xcm: convert properly assets in xcmpayment apis (#7134)

Port #6459 changes to relays as well, which were probably forgotten in
that PR.
Thanks!

---------

Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: command-bot <>
---
 polkadot/runtime/rococo/src/lib.rs  |  3 ++-
 polkadot/runtime/westend/src/lib.rs |  3 ++-
 prdoc/pr_7134.prdoc                 | 11 +++++++++++
 3 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 prdoc/pr_7134.prdoc

diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs
index e5d703700fe..b3f2a003327 100644
--- a/polkadot/runtime/rococo/src/lib.rs
+++ b/polkadot/runtime/rococo/src/lib.rs
@@ -1885,7 +1885,8 @@ sp_api::impl_runtime_apis! {
 		}
 
 		fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
-			match asset.try_as::<AssetId>() {
+			let latest_asset_id: Result<AssetId, ()> = asset.clone().try_into();
+			match latest_asset_id {
 				Ok(asset_id) if asset_id.0 == xcm_config::TokenLocation::get() => {
 					// for native token
 					Ok(WeightToFee::weight_to_fee(&weight))
diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs
index 9d77a5e5eea..58d2bdcb7c7 100644
--- a/polkadot/runtime/westend/src/lib.rs
+++ b/polkadot/runtime/westend/src/lib.rs
@@ -2445,7 +2445,8 @@ sp_api::impl_runtime_apis! {
 		}
 
 		fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
-			match asset.try_as::<AssetId>() {
+			let latest_asset_id: Result<AssetId, ()> = asset.clone().try_into();
+			match latest_asset_id {
 				Ok(asset_id) if asset_id.0 == xcm_config::TokenLocation::get() => {
 					// for native token
 					Ok(WeightToFee::weight_to_fee(&weight))
diff --git a/prdoc/pr_7134.prdoc b/prdoc/pr_7134.prdoc
new file mode 100644
index 00000000000..095d4757f43
--- /dev/null
+++ b/prdoc/pr_7134.prdoc
@@ -0,0 +1,11 @@
+title: 'xcm: convert properly assets in xcmpayment apis'
+doc:
+- audience: Runtime User
+  description: |-
+    Port #6459 changes to relays as well, which were probably forgotten in that PR.
+    Thanks!
+crates:
+- name: rococo-runtime
+  bump: patch
+- name: westend-runtime
+  bump: patch
-- 
GitLab