assets_common/
local_and_foreign_assets.rs1use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
17use core::marker::PhantomData;
18use frame_support::traits::Get;
19use sp_runtime::{
20 traits::{Convert, MaybeEquivalence},
21 Either,
22 Either::{Left, Right},
23};
24use xcm::latest::Location;
25
26#[derive(
28 Clone,
29 Debug,
30 Encode,
31 Decode,
32 DecodeWithMemTracking,
33 PartialEq,
34 Eq,
35 scale_info::TypeInfo,
36 MaxEncodedLen,
37 serde::Serialize,
38 serde::Deserialize,
39)]
40pub struct ForeignAssetReserveData {
41 pub reserve: Location,
43 pub teleportable: bool,
45}
46
47impl From<(Location, bool)> for ForeignAssetReserveData {
48 fn from((reserve, teleportable): (Location, bool)) -> Self {
49 ForeignAssetReserveData { reserve, teleportable }
50 }
51}
52
53pub struct TargetFromLeft<Target, L = Location>(PhantomData<(Target, L)>);
58impl<Target: Get<L>, L: PartialEq + Eq> Convert<L, Either<(), L>> for TargetFromLeft<Target, L> {
59 fn convert(l: L) -> Either<(), L> {
60 Target::get().eq(&l).then(|| Left(())).map_or(Right(l), |n| n)
61 }
62}
63
64pub struct LocalFromLeft<Equivalence, AssetId, L = Location>(
69 PhantomData<(Equivalence, AssetId, L)>,
70);
71impl<Equivalence, AssetId, L> Convert<L, Either<AssetId, L>>
72 for LocalFromLeft<Equivalence, AssetId, L>
73where
74 Equivalence: MaybeEquivalence<L, AssetId>,
75{
76 fn convert(l: L) -> Either<AssetId, L> {
77 match Equivalence::convert(&l) {
78 Some(id) => Left(id),
79 None => Right(l),
80 }
81 }
82}