Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
XCM: Utility struct for AccountId conversion (#7321)
Browse files Browse the repository at this point in the history
* XCM: Utility struct for AccountId conversion

* Update conversion.rs
  • Loading branch information
gavofyork authored Jun 2, 2023
1 parent 48982ae commit 2af0d30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
18 changes: 6 additions & 12 deletions xcm/xcm-builder/src/location_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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(())
}
}
Expand Down
10 changes: 5 additions & 5 deletions xcm/xcm-builder/src/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {}

0 comments on commit 2af0d30

Please sign in to comment.