From 2651dce9fd53ad72fc8b0116b790f3859cdbbc9d Mon Sep 17 00:00:00 2001 From: Gavin Wood <gavin@parity.io> Date: Fri, 2 Jun 2023 09:10:07 +0100 Subject: [PATCH] XCM: Utility struct for AccountId conversion (#7321) * XCM: Utility struct for AccountId conversion * Update conversion.rs --- .../xcm/xcm-builder/src/location_conversion.rs | 18 ++++++------------ polkadot/xcm/xcm-builder/src/pay.rs | 10 +++++----- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/polkadot/xcm/xcm-builder/src/location_conversion.rs b/polkadot/xcm/xcm-builder/src/location_conversion.rs index bafec5da4a3..a5e6b55824e 100644 --- a/polkadot/xcm/xcm-builder/src/location_conversion.rs +++ b/polkadot/xcm/xcm-builder/src/location_conversion.rs @@ -237,18 +237,11 @@ impl<Network: Get<Option<NetworkId>>, AccountId: From<[u8; 32]> + Into<[u8; 32]> /// network (provided by `Network`) and the `AccountId`'s `[u8; 32]` datum for the `id`. pub struct AliasesIntoAccountId32<Network, AccountId>(PhantomData<(Network, AccountId)>); impl<'a, Network: Get<Option<NetworkId>>, AccountId: Clone + Into<[u8; 32]> + Clone> - Convert<&'a AccountId, MultiLocation> for AliasesIntoAccountId32<Network, AccountId> + sp_runtime::traits::Convert<&'a AccountId, MultiLocation> + for AliasesIntoAccountId32<Network, AccountId> { - fn convert(who: &AccountId) -> Result<MultiLocation, &'a AccountId> { - Ok(AccountId32 { network: Network::get(), id: who.clone().into() }.into()) - } -} - -impl<Network: Get<Option<NetworkId>>, AccountId: Into<[u8; 32]> + Clone> - Convert<AccountId, MultiLocation> for AliasesIntoAccountId32<Network, AccountId> -{ - fn convert(who: AccountId) -> Result<MultiLocation, AccountId> { - Ok(AccountId32 { network: Network::get(), id: who.into() }.into()) + fn convert(who: &AccountId) -> MultiLocation { + AccountId32 { network: Network::get(), id: who.clone().into() }.into() } } @@ -313,7 +306,8 @@ impl<UniversalLocation: Get<InteriorMultiLocation>, AccountId: From<[u8; 32]> + } fn reverse_ref(_: impl Borrow<AccountId>) -> Result<MultiLocation, ()> { - // if this will be needed, we could implement some kind of guessing, if we have configuration for supported networkId+paraId + // if this is ever be needed, we could implement some kind of guessing, if we have + // configuration for supported networkId+paraId Err(()) } } diff --git a/polkadot/xcm/xcm-builder/src/pay.rs b/polkadot/xcm/xcm-builder/src/pay.rs index e8cd2b2bb28..504ec837751 100644 --- a/polkadot/xcm/xcm-builder/src/pay.rs +++ b/polkadot/xcm/xcm-builder/src/pay.rs @@ -28,8 +28,11 @@ use xcm_executor::traits::{QueryHandler, QueryResponseStatus}; /// Implementation of the `frame_support::traits::tokens::Pay` trait, to allow /// for XCM-based payments of a given `Balance` of some asset ID existing on some chain under /// ownership of some `Interior` location of the local chain to a particular `Beneficiary`. The -/// `AssetKind` value can be converted into both the XCM `AssetId` (via and `Into` bound) and the -/// the destination chain's location, via the `AssetKindToLocatableAsset` type parameter. +/// `AssetKind` value is not itself bounded (to avoid the issue of needing to wrap some preexisting +/// datatype), however a converter type `AssetKindToLocatableAsset` must be provided in order to +/// translate it into a `LocatableAsset`, which comprises both an XCM `MultiLocation` describing +/// the XCM endpoint on which the asset to be paid resides and an XCM `AssetId` to identify the +/// specific asset at that endpoint. /// /// This relies on the XCM `TransferAsset` instruction. A trait `BeneficiaryRefToLocation` must be /// provided in order to convert the `Beneficiary` reference into a location usable by @@ -200,6 +203,3 @@ impl<Location: Get<MultiLocation>, AssetKind: Into<AssetId>> Convert<AssetKind, LocatableAssetId { asset_id: value.into(), location: Location::get() } } } - -#[test] -fn it_builds() {} -- GitLab