@@ -13,6 +13,7 @@ use sp_runtime::traits::Bounded;
13
13
use sp_runtime:: { traits:: Member , DispatchResult } ;
14
14
use sp_std:: prelude:: * ;
15
15
use xcm:: latest:: prelude:: * ;
16
+ use xcm:: VersionedMultiLocation ;
16
17
use xcm_builder:: TakeRevenue ;
17
18
use xcm_executor:: { traits:: WeightTrader , Assets } ;
18
19
@@ -26,7 +27,7 @@ pub struct AssetMetadata<Balance, CustomMetadata: Parameter + Member + TypeInfo>
26
27
pub name : Vec < u8 > ,
27
28
pub symbol : Vec < u8 > ,
28
29
pub existential_deposit : Balance ,
29
- pub location : Option < MultiLocation > ,
30
+ pub location : Option < VersionedMultiLocation > ,
30
31
pub additional : CustomMetadata ,
31
32
}
32
33
@@ -62,6 +63,9 @@ pub mod module {
62
63
pub enum Error < T > {
63
64
/// Asset was not found
64
65
AssetNotFound ,
66
+ /// The version of the `Versioned` value used is not able to be
67
+ /// interpreted.
68
+ BadVersion ,
65
69
}
66
70
67
71
#[ pallet:: event]
@@ -128,11 +132,15 @@ pub mod module {
128
132
) -> DispatchResult {
129
133
let _ = T :: AuthorityOrigin :: ensure_origin ( origin) ?;
130
134
135
+ let location: Option < MultiLocation > = metadata
136
+ . location
137
+ . map ( |location| location. try_into ( ) . map_err ( |( ) | Error :: < T > :: BadVersion ) )
138
+ . transpose ( ) ?;
139
+
131
140
// if assetid is explicitly passed, use that. Otherwise, if the location is
132
141
// already registered, use the existing id
133
142
let unprocessed_asset_id = asset_id. or_else ( || {
134
- metadata
135
- . location
143
+ location
136
144
. as_ref ( )
137
145
. and_then ( |location| MultiLocationLookup :: < T > :: get ( location) )
138
146
} ) ;
@@ -142,7 +150,7 @@ pub mod module {
142
150
Metadata :: < T > :: insert ( & processed_asset_id, & metadata) ;
143
151
144
152
// If it included a multilocation, add it to the lookup
145
- if let Some ( ref location) = metadata . location {
153
+ if let Some ( ref location) = location {
146
154
MultiLocationLookup :: < T > :: insert ( location, & processed_asset_id) ;
147
155
}
148
156
@@ -158,7 +166,7 @@ pub mod module {
158
166
pub fn set_asset_location (
159
167
origin : OriginFor < T > ,
160
168
asset_id : T :: AssetId ,
161
- location : MultiLocation ,
169
+ location : VersionedMultiLocation ,
162
170
) -> DispatchResult {
163
171
let _ = T :: AuthorityOrigin :: ensure_origin ( origin) ?;
164
172
0 commit comments