@@ -55,7 +55,7 @@ use xcm_executor::traits::WeightBounds;
55
55
pub use module:: * ;
56
56
use orml_traits:: {
57
57
location:: { Parse , Reserve } ,
58
- xcm_transfer:: Transferred ,
58
+ xcm_transfer:: { Transferred , XtokensWeightInfo } ,
59
59
GetByKey , XcmTransfer ,
60
60
} ;
61
61
@@ -211,7 +211,7 @@ pub mod module {
211
211
/// by the network, and if the receiving chain would handle
212
212
/// messages correctly.
213
213
#[ pallet:: call_index( 0 ) ]
214
- #[ pallet:: weight( Pallet :: <T >:: weight_of_transfer( currency_id. clone( ) , * amount, dest) ) ]
214
+ #[ pallet:: weight( XtokensWeight :: <T >:: weight_of_transfer( currency_id. clone( ) , * amount, dest) ) ]
215
215
pub fn transfer (
216
216
origin : OriginFor < T > ,
217
217
currency_id : T :: CurrencyId ,
@@ -237,7 +237,7 @@ pub mod module {
237
237
/// by the network, and if the receiving chain would handle
238
238
/// messages correctly.
239
239
#[ pallet:: call_index( 1 ) ]
240
- #[ pallet:: weight( Pallet :: <T >:: weight_of_transfer_multiasset( asset, dest) ) ]
240
+ #[ pallet:: weight( XtokensWeight :: <T >:: weight_of_transfer_multiasset( asset, dest) ) ]
241
241
pub fn transfer_multiasset (
242
242
origin : OriginFor < T > ,
243
243
asset : Box < VersionedMultiAsset > ,
@@ -272,7 +272,7 @@ pub mod module {
272
272
/// by the network, and if the receiving chain would handle
273
273
/// messages correctly.
274
274
#[ pallet:: call_index( 2 ) ]
275
- #[ pallet:: weight( Pallet :: <T >:: weight_of_transfer( currency_id. clone( ) , * amount, dest) ) ]
275
+ #[ pallet:: weight( XtokensWeight :: <T >:: weight_of_transfer( currency_id. clone( ) , * amount, dest) ) ]
276
276
pub fn transfer_with_fee (
277
277
origin : OriginFor < T > ,
278
278
currency_id : T :: CurrencyId ,
@@ -309,7 +309,7 @@ pub mod module {
309
309
/// by the network, and if the receiving chain would handle
310
310
/// messages correctly.
311
311
#[ pallet:: call_index( 3 ) ]
312
- #[ pallet:: weight( Pallet :: <T >:: weight_of_transfer_multiasset( asset, dest) ) ]
312
+ #[ pallet:: weight( XtokensWeight :: <T >:: weight_of_transfer_multiasset( asset, dest) ) ]
313
313
pub fn transfer_multiasset_with_fee (
314
314
origin : OriginFor < T > ,
315
315
asset : Box < VersionedMultiAsset > ,
@@ -341,7 +341,7 @@ pub mod module {
341
341
/// by the network, and if the receiving chain would handle
342
342
/// messages correctly.
343
343
#[ pallet:: call_index( 4 ) ]
344
- #[ pallet:: weight( Pallet :: <T >:: weight_of_transfer_multicurrencies( currencies, fee_item, dest) ) ]
344
+ #[ pallet:: weight( XtokensWeight :: <T >:: weight_of_transfer_multicurrencies( currencies, fee_item, dest) ) ]
345
345
pub fn transfer_multicurrencies (
346
346
origin : OriginFor < T > ,
347
347
currencies : Vec < ( T :: CurrencyId , T :: Balance ) > ,
@@ -371,7 +371,7 @@ pub mod module {
371
371
/// by the network, and if the receiving chain would handle
372
372
/// messages correctly.
373
373
#[ pallet:: call_index( 5 ) ]
374
- #[ pallet:: weight( Pallet :: <T >:: weight_of_transfer_multiassets( assets, fee_item, dest) ) ]
374
+ #[ pallet:: weight( XtokensWeight :: <T >:: weight_of_transfer_multiassets( assets, fee_item, dest) ) ]
375
375
pub fn transfer_multiassets (
376
376
origin : OriginFor < T > ,
377
377
assets : Box < VersionedMultiAssets > ,
@@ -831,17 +831,31 @@ pub mod module {
831
831
} ;
832
832
Ok ( ( transfer_kind, dest, reserve, recipient) )
833
833
}
834
+
835
+ /// Get reserve location by `assets` and `fee_item`. the `assets`
836
+ /// includes fee asset and non fee asset. make sure assets have ge one
837
+ /// asset. all non fee asset should share same reserve location.
838
+ fn get_reserve_location ( assets : & MultiAssets , fee_item : & u32 ) -> Option < MultiLocation > {
839
+ let reserve_idx = if assets. len ( ) == 1 {
840
+ 0
841
+ } else {
842
+ ( * fee_item == 0 ) as usize
843
+ } ;
844
+ let asset = assets. get ( reserve_idx) ;
845
+ asset. and_then ( T :: ReserveProvider :: reserve)
846
+ }
834
847
}
835
848
849
+ pub struct XtokensWeight < T > ( PhantomData < T > ) ;
836
850
// weights
837
- impl < T : Config > Pallet < T > {
851
+ impl < T : Config > XtokensWeightInfo < T :: AccountId , T :: Balance , T :: CurrencyId > for XtokensWeight < T > {
838
852
/// Returns weight of `transfer_multiasset` call.
839
853
fn weight_of_transfer_multiasset ( asset : & VersionedMultiAsset , dest : & VersionedMultiLocation ) -> Weight {
840
854
let asset: Result < MultiAsset , _ > = asset. clone ( ) . try_into ( ) ;
841
855
let dest = dest. clone ( ) . try_into ( ) ;
842
856
if let ( Ok ( asset) , Ok ( dest) ) = ( asset, dest) {
843
857
if let Ok ( ( transfer_kind, dest, _, reserve) ) =
844
- Self :: transfer_kind ( T :: ReserveProvider :: reserve ( & asset) , & dest)
858
+ Pallet :: < T > :: transfer_kind ( T :: ReserveProvider :: reserve ( & asset) , & dest)
845
859
{
846
860
let mut msg = match transfer_kind {
847
861
SelfReserveAsset => Xcm ( vec ! [ TransferReserveAsset {
@@ -904,8 +918,8 @@ pub mod module {
904
918
let assets: Result < MultiAssets , ( ) > = assets. clone ( ) . try_into ( ) ;
905
919
let dest = dest. clone ( ) . try_into ( ) ;
906
920
if let ( Ok ( assets) , Ok ( dest) ) = ( assets, dest) {
907
- let reserve_location = Self :: get_reserve_location ( & assets, fee_item) ;
908
- if let Ok ( ( transfer_kind, dest, _, reserve) ) = Self :: transfer_kind ( reserve_location, & dest) {
921
+ let reserve_location = Pallet :: < T > :: get_reserve_location ( & assets, fee_item) ;
922
+ if let Ok ( ( transfer_kind, dest, _, reserve) ) = Pallet :: < T > :: transfer_kind ( reserve_location, & dest) {
909
923
let mut msg = match transfer_kind {
910
924
SelfReserveAsset => Xcm ( vec ! [ TransferReserveAsset {
911
925
assets,
@@ -928,19 +942,6 @@ pub mod module {
928
942
}
929
943
Weight :: zero ( )
930
944
}
931
-
932
- /// Get reserve location by `assets` and `fee_item`. the `assets`
933
- /// includes fee asset and non fee asset. make sure assets have ge one
934
- /// asset. all non fee asset should share same reserve location.
935
- fn get_reserve_location ( assets : & MultiAssets , fee_item : & u32 ) -> Option < MultiLocation > {
936
- let reserve_idx = if assets. len ( ) == 1 {
937
- 0
938
- } else {
939
- ( * fee_item == 0 ) as usize
940
- } ;
941
- let asset = assets. get ( reserve_idx) ;
942
- asset. and_then ( T :: ReserveProvider :: reserve)
943
- }
944
945
}
945
946
946
947
impl < T : Config > XcmTransfer < T :: AccountId , T :: Balance , T :: CurrencyId > for Pallet < T > {
0 commit comments