@@ -26,78 +26,73 @@ use sp_runtime::traits::{AccountIdLookup, StaticLookup};
2626use sp_std:: prelude:: * ;
2727use xcm_primitives:: {
2828 AvailableStakeCalls , HrmpAvailableCalls , HrmpEncodeCall , StakeEncodeCall ,
29- UtilityAvailableCalls , UtilityEncodeCall ,
29+ UtilityAvailableCalls , UtilityEncodeCall , XcmTransact ,
3030} ;
3131
3232pub use crate :: pallet:: * ;
3333
3434pub use crate :: weights:: WeightInfo ;
3535
3636impl < T : Config > UtilityEncodeCall for Pallet < T > {
37- fn encode_call ( self , call : UtilityAvailableCalls ) -> Vec < u8 > {
37+ fn encode_call < Transactor : XcmTransact > (
38+ transactor : Transactor ,
39+ call : UtilityAvailableCalls ,
40+ ) -> Vec < u8 > {
41+ let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
42+ // pallet index
43+ encoded_call. push ( transactor. utility_pallet_index ( ) ) ;
44+
3845 match call {
3946 UtilityAvailableCalls :: AsDerivative ( a, b) => {
40- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
41- // pallet index
42- encoded_call. push ( RelayIndices :: < T > :: get ( ) . utility ) ;
4347 // call index
4448 encoded_call. push ( RelayIndices :: < T > :: get ( ) . as_derivative ) ;
4549 // encoded argument
4650 encoded_call. append ( & mut a. encode ( ) ) ;
4751 encoded_call. append ( & mut b. clone ( ) ) ;
48- encoded_call
4952 }
5053 }
54+
55+ encoded_call
5156 }
5257}
5358
5459impl < T : Config > HrmpEncodeCall for Pallet < T > {
5560 fn hrmp_encode_call ( call : HrmpAvailableCalls ) -> Result < Vec < u8 > , xcm:: latest:: Error > {
61+ let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
62+ // pallet index
63+ encoded_call. push ( RelayIndices :: < T > :: get ( ) . hrmp ) ;
64+
5665 match call {
5766 HrmpAvailableCalls :: InitOpenChannel ( a, b, c) => {
58- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
59- // pallet index
60- encoded_call. push ( RelayIndices :: < T > :: get ( ) . hrmp ) ;
6167 // call index
6268 encoded_call. push ( RelayIndices :: < T > :: get ( ) . init_open_channel ) ;
6369 // encoded arguments
6470 encoded_call. append ( & mut a. encode ( ) ) ;
6571 encoded_call. append ( & mut b. encode ( ) ) ;
6672 encoded_call. append ( & mut c. encode ( ) ) ;
67- Ok ( encoded_call)
6873 }
6974 HrmpAvailableCalls :: AcceptOpenChannel ( a) => {
70- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
71- // pallet index
72- encoded_call. push ( RelayIndices :: < T > :: get ( ) . hrmp ) ;
7375 // call index
7476 encoded_call. push ( RelayIndices :: < T > :: get ( ) . accept_open_channel ) ;
7577 // encoded argument
7678 encoded_call. append ( & mut a. encode ( ) ) ;
77- Ok ( encoded_call)
7879 }
7980 HrmpAvailableCalls :: CloseChannel ( a) => {
80- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
81- // pallet index
82- encoded_call. push ( RelayIndices :: < T > :: get ( ) . hrmp ) ;
8381 // call index
8482 encoded_call. push ( RelayIndices :: < T > :: get ( ) . close_channel ) ;
8583 // encoded argument
8684 encoded_call. append ( & mut a. encode ( ) ) ;
87- Ok ( encoded_call)
8885 }
8986 HrmpAvailableCalls :: CancelOpenRequest ( a, b) => {
90- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
91- // pallet index
92- encoded_call. push ( RelayIndices :: < T > :: get ( ) . hrmp ) ;
9387 // call index
9488 encoded_call. push ( RelayIndices :: < T > :: get ( ) . cancel_open_request ) ;
9589 // encoded argument
9690 encoded_call. append ( & mut a. encode ( ) ) ;
9791 encoded_call. append ( & mut b. encode ( ) ) ;
98- Ok ( encoded_call)
9992 }
10093 }
94+
95+ Ok ( encoded_call)
10196 }
10297}
10398
@@ -111,116 +106,76 @@ fn encode_compact_arg<T: parity_scale_codec::HasCompact>(input: T) -> Vec<u8> {
111106}
112107
113108impl < T : Config > StakeEncodeCall for Pallet < T > {
114- fn encode_call ( call : AvailableStakeCalls ) -> Vec < u8 > {
109+ fn encode_call < Transactor : XcmTransact > (
110+ transactor : Transactor ,
111+ call : AvailableStakeCalls ,
112+ ) -> Vec < u8 > {
113+ let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
114+ // pallet index
115+ encoded_call. push ( transactor. staking_pallet_index ( ) ) ;
116+
115117 match call {
116118 AvailableStakeCalls :: Bond ( b, c) => {
117- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
118- // pallet index
119- encoded_call. push ( RelayIndices :: < T > :: get ( ) . staking ) ;
120119 // call index
121120 encoded_call. push ( RelayIndices :: < T > :: get ( ) . bond ) ;
122121 // encoded arguments
123122 encoded_call. append ( & mut encode_compact_arg ( b) ) ;
124123 encoded_call. append ( & mut c. encode ( ) ) ;
125- encoded_call
126124 }
127-
128125 AvailableStakeCalls :: BondExtra ( a) => {
129- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
130- // pallet index
131- encoded_call. push ( RelayIndices :: < T > :: get ( ) . staking ) ;
132126 // call index
133127 encoded_call. push ( RelayIndices :: < T > :: get ( ) . bond_extra ) ;
134128 // encoded argument
135129 encoded_call. append ( & mut encode_compact_arg ( a) ) ;
136- encoded_call
137130 }
138-
139131 AvailableStakeCalls :: Unbond ( a) => {
140- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
141- // pallet index
142- encoded_call. push ( RelayIndices :: < T > :: get ( ) . staking ) ;
143132 // call index
144133 encoded_call. push ( RelayIndices :: < T > :: get ( ) . unbond ) ;
145134 // encoded argument
146135 encoded_call. append ( & mut encode_compact_arg ( a) ) ;
147- encoded_call
148136 }
149-
150137 AvailableStakeCalls :: WithdrawUnbonded ( a) => {
151- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
152- // pallet index
153- encoded_call. push ( RelayIndices :: < T > :: get ( ) . staking ) ;
154138 // call index
155139 encoded_call. push ( RelayIndices :: < T > :: get ( ) . withdraw_unbonded ) ;
156140 // encoded argument
157141 encoded_call. append ( & mut a. encode ( ) ) ;
158- encoded_call
159142 }
160-
161143 AvailableStakeCalls :: Validate ( a) => {
162- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
163- // pallet index
164- encoded_call. push ( RelayIndices :: < T > :: get ( ) . staking ) ;
165144 // call index
166145 encoded_call. push ( RelayIndices :: < T > :: get ( ) . validate ) ;
167146 // encoded argument
168147 encoded_call. append ( & mut a. encode ( ) ) ;
169- encoded_call
170148 }
171-
172149 AvailableStakeCalls :: Chill => {
173- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
174- // pallet index
175- encoded_call. push ( RelayIndices :: < T > :: get ( ) . staking ) ;
176150 // call index
177151 encoded_call. push ( RelayIndices :: < T > :: get ( ) . chill ) ;
178- encoded_call
179152 }
180-
181153 AvailableStakeCalls :: SetPayee ( a) => {
182- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
183- // pallet index
184- encoded_call. push ( RelayIndices :: < T > :: get ( ) . staking ) ;
185154 // call index
186155 encoded_call. push ( RelayIndices :: < T > :: get ( ) . set_payee ) ;
187156 // encoded argument
188157 encoded_call. append ( & mut a. encode ( ) ) ;
189- encoded_call
190158 }
191-
192159 AvailableStakeCalls :: SetController => {
193- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
194- // pallet index
195- encoded_call. push ( RelayIndices :: < T > :: get ( ) . staking ) ;
196160 // call index
197161 encoded_call. push ( RelayIndices :: < T > :: get ( ) . set_controller ) ;
198- encoded_call
199162 }
200-
201163 AvailableStakeCalls :: Rebond ( a) => {
202- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
203- // pallet index
204- encoded_call. push ( RelayIndices :: < T > :: get ( ) . staking ) ;
205164 // call index
206165 encoded_call. push ( RelayIndices :: < T > :: get ( ) . rebond ) ;
207166 // encoded argument
208167 encoded_call. append ( & mut encode_compact_arg ( a) ) ;
209- encoded_call
210168 }
211-
212169 AvailableStakeCalls :: Nominate ( a) => {
213- let mut encoded_call: Vec < u8 > = Vec :: new ( ) ;
214- // pallet index
215- encoded_call. push ( RelayIndices :: < T > :: get ( ) . staking ) ;
216170 // call index
217171 encoded_call. push ( RelayIndices :: < T > :: get ( ) . nominate ) ;
218172 let nominated: Vec <
219173 <AccountIdLookup < sp_runtime:: AccountId32 , ( ) > as StaticLookup >:: Source ,
220174 > = a. iter ( ) . map ( |add| ( * add) . clone ( ) . into ( ) ) . collect ( ) ;
221175 encoded_call. append ( & mut nominated. encode ( ) ) ;
222- encoded_call
223176 }
224177 }
178+
179+ encoded_call
225180 }
226181}
0 commit comments