@@ -10,7 +10,6 @@ use polkadot_parachain::primitives::Sibling;
10
10
use serde:: { Deserialize , Serialize } ;
11
11
use sp_io:: TestExternalities ;
12
12
use sp_runtime:: AccountId32 ;
13
- use sp_std:: convert:: TryFrom ;
14
13
use xcm:: v0:: { Junction , MultiLocation :: * , NetworkId } ;
15
14
use xcm_builder:: {
16
15
AccountId32Aliases , LocationInverter , ParentIsDefault , RelayChainAsNative , SiblingParachainAsNative ,
@@ -33,48 +32,52 @@ pub enum CurrencyId {
33
32
B ,
34
33
}
35
34
36
- impl From < CurrencyId > for MultiLocation {
37
- fn from ( id : CurrencyId ) -> Self {
35
+ pub struct CurrencyIdConvert ;
36
+ impl Convert < CurrencyId , Option < MultiLocation > > for CurrencyIdConvert {
37
+ fn convert ( id : CurrencyId ) -> Option < MultiLocation > {
38
38
match id {
39
- CurrencyId :: R => Junction :: Parent . into ( ) ,
40
- CurrencyId :: A => (
41
- Junction :: Parent ,
42
- Junction :: Parachain { id : 1 } ,
43
- Junction :: GeneralKey ( "A" . into ( ) ) ,
44
- )
45
- . into ( ) ,
46
- CurrencyId :: B => (
47
- Junction :: Parent ,
48
- Junction :: Parachain { id : 2 } ,
49
- Junction :: GeneralKey ( "B" . into ( ) ) ,
50
- )
51
- . into ( ) ,
39
+ CurrencyId :: R => Some ( Junction :: Parent . into ( ) ) ,
40
+ CurrencyId :: A => Some (
41
+ (
42
+ Junction :: Parent ,
43
+ Junction :: Parachain { id : 1 } ,
44
+ Junction :: GeneralKey ( "A" . into ( ) ) ,
45
+ )
46
+ . into ( ) ,
47
+ ) ,
48
+ CurrencyId :: B => Some (
49
+ (
50
+ Junction :: Parent ,
51
+ Junction :: Parachain { id : 2 } ,
52
+ Junction :: GeneralKey ( "B" . into ( ) ) ,
53
+ )
54
+ . into ( ) ,
55
+ ) ,
52
56
}
53
57
}
54
58
}
55
-
56
- impl TryFrom < MultiLocation > for CurrencyId {
57
- type Error = ( ) ;
58
- fn try_from ( l : MultiLocation ) -> Result < Self , Self :: Error > {
59
+ impl Convert < MultiLocation , Option < CurrencyId > > for CurrencyIdConvert {
60
+ fn convert ( l : MultiLocation ) -> Option < CurrencyId > {
59
61
let a: Vec < u8 > = "A" . into ( ) ;
60
62
let b: Vec < u8 > = "B" . into ( ) ;
61
63
match l {
62
- X1 ( Parent ) => Ok ( CurrencyId :: R ) ,
63
- X3 ( Junction :: Parent , Junction :: Parachain { id : 1 } , Junction :: GeneralKey ( k) ) if k == a => Ok ( CurrencyId :: A ) ,
64
- X3 ( Junction :: Parent , Junction :: Parachain { id : 2 } , Junction :: GeneralKey ( k) ) if k == b => Ok ( CurrencyId :: B ) ,
65
-
66
- _ => Err ( ( ) ) ,
64
+ X1 ( Parent ) => Some ( CurrencyId :: R ) ,
65
+ X3 ( Junction :: Parent , Junction :: Parachain { id : 1 } , Junction :: GeneralKey ( k) ) if k == a => {
66
+ Some ( CurrencyId :: A )
67
+ }
68
+ X3 ( Junction :: Parent , Junction :: Parachain { id : 2 } , Junction :: GeneralKey ( k) ) if k == b => {
69
+ Some ( CurrencyId :: B )
70
+ }
71
+ _ => None ,
67
72
}
68
73
}
69
74
}
70
-
71
- impl TryFrom < MultiAsset > for CurrencyId {
72
- type Error = ( ) ;
73
- fn try_from ( a : MultiAsset ) -> Result < Self , Self :: Error > {
75
+ impl Convert < MultiAsset , Option < CurrencyId > > for CurrencyIdConvert {
76
+ fn convert ( a : MultiAsset ) -> Option < CurrencyId > {
74
77
if let MultiAsset :: ConcreteFungible { id, amount : _ } = a {
75
- Self :: try_from ( id)
78
+ Self :: convert ( id)
76
79
} else {
77
- Err ( ( ) )
80
+ None
78
81
}
79
82
}
80
83
}
@@ -110,10 +113,11 @@ decl_test_parachain! {
110
113
pub type LocalAssetTransactor = MultiCurrencyAdapter <
111
114
Tokens ,
112
115
( ) ,
113
- IsNativeConcrete <CurrencyId >,
114
- LocationConverter ,
116
+ IsNativeConcrete <CurrencyId , CurrencyIdConvert >,
115
117
AccountId ,
118
+ LocationConverter ,
116
119
CurrencyId ,
120
+ CurrencyIdConvert ,
117
121
>;
118
122
119
123
pub type LocalOriginConverter = (
@@ -173,6 +177,7 @@ decl_test_parachain! {
173
177
type Event = Event ;
174
178
type Balance = Balance ;
175
179
type CurrencyId = CurrencyId ;
180
+ type CurrencyIdConvert = CurrencyIdConvert ;
176
181
type AccountId32Convert = AccountId32Convert ;
177
182
type SelfLocation = SelfLocation ;
178
183
type XcmHandler = HandleXcm ;
@@ -213,10 +218,11 @@ decl_test_parachain! {
213
218
pub type LocalAssetTransactor = MultiCurrencyAdapter <
214
219
Tokens ,
215
220
( ) ,
216
- IsNativeConcrete <CurrencyId >,
217
- LocationConverter ,
221
+ IsNativeConcrete <CurrencyId , CurrencyIdConvert >,
218
222
AccountId ,
223
+ LocationConverter ,
219
224
CurrencyId ,
225
+ CurrencyIdConvert ,
220
226
>;
221
227
222
228
pub type LocalOriginConverter = (
@@ -276,6 +282,7 @@ decl_test_parachain! {
276
282
type Event = Event ;
277
283
type Balance = Balance ;
278
284
type CurrencyId = CurrencyId ;
285
+ type CurrencyIdConvert = CurrencyIdConvert ;
279
286
type AccountId32Convert = AccountId32Convert ;
280
287
type SelfLocation = SelfLocation ;
281
288
type XcmHandler = HandleXcm ;
@@ -316,10 +323,11 @@ decl_test_parachain! {
316
323
pub type LocalAssetTransactor = MultiCurrencyAdapter <
317
324
Tokens ,
318
325
( ) ,
319
- IsNativeConcrete <CurrencyId >,
320
- LocationConverter ,
326
+ IsNativeConcrete <CurrencyId , CurrencyIdConvert >,
321
327
AccountId ,
328
+ LocationConverter ,
322
329
CurrencyId ,
330
+ CurrencyIdConvert ,
323
331
>;
324
332
325
333
pub type LocalOriginConverter = (
@@ -379,6 +387,7 @@ decl_test_parachain! {
379
387
type Event = Event ;
380
388
type Balance = Balance ;
381
389
type CurrencyId = CurrencyId ;
390
+ type CurrencyIdConvert = CurrencyIdConvert ;
382
391
type AccountId32Convert = AccountId32Convert ;
383
392
type SelfLocation = SelfLocation ;
384
393
type XcmHandler = HandleXcm ;
0 commit comments