5
5
6
6
use frame_support:: { pallet_prelude:: * , traits:: EnsureOrigin } ;
7
7
use frame_system:: pallet_prelude:: * ;
8
- use sp_std:: boxed:: Box ;
9
-
10
- use xcm:: latest:: prelude:: * ;
8
+ use sp_std:: {
9
+ boxed:: Box ,
10
+ convert:: { TryFrom , TryInto } ,
11
+ } ;
12
+ use xcm:: { latest:: prelude:: * , VersionedMultiLocation , VersionedXcm } ;
11
13
12
14
pub use module:: * ;
13
15
@@ -43,6 +45,9 @@ pub mod module {
43
45
/// The message and destination was recognized as being reachable but
44
46
/// the operation could not be completed.
45
47
SendFailure ,
48
+ /// The version of the `Versioned` value used is not able to be
49
+ /// interpreted.
50
+ BadVersion ,
46
51
}
47
52
48
53
#[ pallet:: call]
@@ -51,15 +56,18 @@ pub mod module {
51
56
#[ pallet:: weight( 100_000_000 ) ]
52
57
pub fn send_as_sovereign (
53
58
origin : OriginFor < T > ,
54
- dest : Box < MultiLocation > ,
55
- message : Box < Xcm < ( ) > > ,
59
+ dest : Box < VersionedMultiLocation > ,
60
+ message : Box < VersionedXcm < ( ) > > ,
56
61
) -> DispatchResult {
57
62
let _ = T :: SovereignOrigin :: ensure_origin ( origin) ?;
58
- pallet_xcm:: Pallet :: < T > :: send_xcm ( Here , * dest. clone ( ) , * message. clone ( ) ) . map_err ( |e| match e {
63
+ let dest = MultiLocation :: try_from ( * dest) . map_err ( |( ) | Error :: < T > :: BadVersion ) ?;
64
+ let message: Xcm < ( ) > = ( * message) . try_into ( ) . map_err ( |( ) | Error :: < T > :: BadVersion ) ?;
65
+
66
+ pallet_xcm:: Pallet :: < T > :: send_xcm ( Here , dest. clone ( ) , message. clone ( ) ) . map_err ( |e| match e {
59
67
SendError :: CannotReachDestination ( ..) => Error :: < T > :: Unreachable ,
60
68
_ => Error :: < T > :: SendFailure ,
61
69
} ) ?;
62
- Self :: deposit_event ( Event :: Sent ( * dest, * message) ) ;
70
+ Self :: deposit_event ( Event :: Sent ( dest, message) ) ;
63
71
Ok ( ( ) )
64
72
}
65
73
}
0 commit comments