9
9
#![ cfg_attr( not( feature = "std" ) , no_std) ]
10
10
#![ allow( clippy:: unused_unit) ]
11
11
12
- use frame_support:: {
13
- dispatch:: { DispatchError , DispatchResult } ,
14
- traits:: Get ,
15
- } ;
16
- use sp_runtime:: traits:: { CheckedConversion , Convert } ;
17
- use sp_std:: {
18
- collections:: btree_set:: BTreeSet ,
19
- convert:: { TryFrom , TryInto } ,
20
- marker:: PhantomData ,
21
- prelude:: * ,
22
- } ;
12
+ use frame_support:: dispatch:: { DispatchError , DispatchResult } ;
13
+ use sp_runtime:: traits:: CheckedConversion ;
14
+ use sp_std:: { convert:: TryFrom , marker:: PhantomData , prelude:: * } ;
23
15
24
- use xcm:: v0:: { Junction , MultiAsset , MultiLocation , Xcm } ;
25
- use xcm_executor:: traits:: { FilterAssetLocation , MatchesFungible , NativeAsset } ;
16
+ use xcm:: v0:: { MultiAsset , MultiLocation , Xcm } ;
17
+ use xcm_executor:: traits:: { FilterAssetLocation , MatchesFungible } ;
26
18
27
19
use orml_traits:: location:: Reserve ;
28
20
@@ -37,61 +29,24 @@ pub trait XcmHandler<AccountId> {
37
29
fn execute_xcm ( origin : AccountId , xcm : Xcm ) -> DispatchResult ;
38
30
}
39
31
40
- /// Convert `MultiAsset` to `CurrencyId`.
41
- pub trait CurrencyIdConversion < CurrencyId > {
42
- /// Get `CurrencyId` from `MultiAsset`. Returns `None` if conversion failed.
43
- fn from_asset ( asset : & MultiAsset ) -> Option < CurrencyId > ;
44
- }
45
-
46
- /// A `MatchesFungible` implementation. It matches relay chain tokens or
47
- /// parachain tokens that could be decoded from a general key.
48
- pub struct IsConcreteWithGeneralKey < CurrencyId , FromRelayChainBalance > (
49
- PhantomData < ( CurrencyId , FromRelayChainBalance ) > ,
50
- ) ;
51
- impl < CurrencyId , B , FromRelayChainBalance > MatchesFungible < B >
52
- for IsConcreteWithGeneralKey < CurrencyId , FromRelayChainBalance >
32
+ /// A `MatchesFungible` implementation. It matches concrete fungible assets
33
+ /// whose `id` could be converted into `CurrencyId`.
34
+ pub struct IsNativeConcrete < CurrencyId > ( PhantomData < CurrencyId > ) ;
35
+ impl < CurrencyId , Amount > MatchesFungible < Amount > for IsNativeConcrete < CurrencyId >
53
36
where
54
- CurrencyId : TryFrom < Vec < u8 > > ,
55
- B : TryFrom < u128 > ,
56
- FromRelayChainBalance : Convert < u128 , u128 > ,
37
+ CurrencyId : TryFrom < MultiLocation > ,
38
+ Amount : TryFrom < u128 > ,
57
39
{
58
- fn matches_fungible ( a : & MultiAsset ) -> Option < B > {
40
+ fn matches_fungible ( a : & MultiAsset ) -> Option < Amount > {
59
41
if let MultiAsset :: ConcreteFungible { id, amount } = a {
60
- if id == & MultiLocation :: X1 ( Junction :: Parent ) {
61
- // Convert relay chain decimals to local chain
62
- let local_amount = FromRelayChainBalance :: convert ( * amount) ;
63
- return CheckedConversion :: checked_from ( local_amount) ;
64
- }
65
- if let Some ( Junction :: GeneralKey ( key) ) = id. last ( ) {
66
- if TryInto :: < CurrencyId > :: try_into ( key. clone ( ) ) . is_ok ( ) {
67
- return CheckedConversion :: checked_from ( * amount) ;
68
- }
42
+ if CurrencyId :: try_from ( id. clone ( ) ) . is_ok ( ) {
43
+ return CheckedConversion :: checked_from ( * amount) ;
69
44
}
70
45
}
71
46
None
72
47
}
73
48
}
74
49
75
- /// A `FilterAssetLocation` implementation. Filters native assets and ORML
76
- /// tokens via provided general key to `MultiLocation` pairs.
77
- pub struct NativePalletAssetOr < Pairs > ( PhantomData < Pairs > ) ;
78
- impl < Pairs : Get < BTreeSet < ( Vec < u8 > , MultiLocation ) > > > FilterAssetLocation for NativePalletAssetOr < Pairs > {
79
- fn filter_asset_location ( asset : & MultiAsset , origin : & MultiLocation ) -> bool {
80
- if NativeAsset :: filter_asset_location ( asset, origin) {
81
- return true ;
82
- }
83
-
84
- // native orml-tokens with a general key
85
- if let MultiAsset :: ConcreteFungible { ref id, .. } = asset {
86
- if let Some ( Junction :: GeneralKey ( key) ) = id. last ( ) {
87
- return Pairs :: get ( ) . contains ( & ( key. clone ( ) , origin. clone ( ) ) ) ;
88
- }
89
- }
90
-
91
- false
92
- }
93
- }
94
-
95
50
/// A `FilterAssetLocation` implementation. Filters multi native assets whose
96
51
/// reserve is same with `origin`.
97
52
pub struct MultiNativeAsset ;
@@ -106,31 +61,6 @@ impl FilterAssetLocation for MultiNativeAsset {
106
61
}
107
62
}
108
63
109
- /// `CurrencyIdConversion` implementation. Converts relay chain tokens, or
110
- /// parachain tokens that could be decoded from a general key.
111
- pub struct CurrencyIdConverter < CurrencyId , RelayChainCurrencyId > (
112
- PhantomData < CurrencyId > ,
113
- PhantomData < RelayChainCurrencyId > ,
114
- ) ;
115
- impl < CurrencyId , RelayChainCurrencyId > CurrencyIdConversion < CurrencyId >
116
- for CurrencyIdConverter < CurrencyId , RelayChainCurrencyId >
117
- where
118
- CurrencyId : TryFrom < Vec < u8 > > ,
119
- RelayChainCurrencyId : Get < CurrencyId > ,
120
- {
121
- fn from_asset ( asset : & MultiAsset ) -> Option < CurrencyId > {
122
- if let MultiAsset :: ConcreteFungible { id : location, .. } = asset {
123
- if location == & MultiLocation :: X1 ( Junction :: Parent ) {
124
- return Some ( RelayChainCurrencyId :: get ( ) ) ;
125
- }
126
- if let Some ( Junction :: GeneralKey ( key) ) = location. last ( ) {
127
- return CurrencyId :: try_from ( key. clone ( ) ) . ok ( ) ;
128
- }
129
- }
130
- None
131
- }
132
- }
133
-
134
64
/// Handlers unknown asset deposit and withdraw.
135
65
pub trait UnknownAsset {
136
66
/// Deposit unknown asset.
0 commit comments