@@ -133,22 +133,24 @@ decl_module! {
133
133
/// `BatchInterrupted` event is deposited, along with the number of successful calls made
134
134
/// and the error of the failed call. If all were successful, then the `BatchCompleted`
135
135
/// event is deposited.
136
- #[ weight = (
137
- calls. iter( )
138
- . map( |call| call. get_dispatch_info( ) . weight)
136
+ #[ weight = {
137
+ let dispatch_infos = calls. iter( ) . map( |call| call. get_dispatch_info( ) ) . collect:: <Vec <_>>( ) ;
138
+ let dispatch_weight = dispatch_infos. iter( )
139
+ . map( |di| di. weight)
139
140
. fold( 0 , |total: Weight , weight: Weight | total. saturating_add( weight) )
140
- . saturating_add( T :: WeightInfo :: batch( calls. len( ) as u32 ) ) ,
141
- {
142
- let all_operational = calls . iter( )
143
- . map( |call| call . get_dispatch_info ( ) . class)
141
+ . saturating_add( T :: WeightInfo :: batch( calls. len( ) as u32 ) ) ;
142
+ let dispatch_class = {
143
+ let all_operational = dispatch_infos . iter( )
144
+ . map( |di| di . class)
144
145
. all( |class| class == DispatchClass :: Operational ) ;
145
146
if all_operational {
146
147
DispatchClass :: Operational
147
148
} else {
148
149
DispatchClass :: Normal
149
150
}
150
- } ,
151
- ) ]
151
+ } ;
152
+ ( dispatch_weight, dispatch_class)
153
+ } ]
152
154
fn batch( origin, calls: Vec <<T as Config >:: Call >) -> DispatchResultWithPostInfo {
153
155
let is_root = ensure_root( origin. clone( ) ) . is_ok( ) ;
154
156
let calls_len = calls. len( ) ;
@@ -190,13 +192,16 @@ decl_module! {
190
192
/// NOTE: Prior to version *12, this was called `as_limited_sub`.
191
193
///
192
194
/// The dispatch origin for this call must be _Signed_.
193
- #[ weight = (
194
- T :: WeightInfo :: as_derivative( )
195
- . saturating_add( call. get_dispatch_info( ) . weight)
196
- // AccountData for inner call origin accountdata.
197
- . saturating_add( T :: DbWeight :: get( ) . reads_writes( 1 , 1 ) ) ,
198
- call. get_dispatch_info( ) . class,
199
- ) ]
195
+ #[ weight = {
196
+ let dispatch_info = call. get_dispatch_info( ) ;
197
+ (
198
+ T :: WeightInfo :: as_derivative( )
199
+ . saturating_add( dispatch_info. weight)
200
+ // AccountData for inner call origin accountdata.
201
+ . saturating_add( T :: DbWeight :: get( ) . reads_writes( 1 , 1 ) ) ,
202
+ dispatch_info. class,
203
+ )
204
+ } ]
200
205
fn as_derivative( origin, index: u16 , call: Box <<T as Config >:: Call >) -> DispatchResultWithPostInfo {
201
206
let mut origin = origin;
202
207
let who = ensure_signed( origin. clone( ) ) ?;
@@ -227,22 +232,24 @@ decl_module! {
227
232
/// # <weight>
228
233
/// - Complexity: O(C) where C is the number of calls to be batched.
229
234
/// # </weight>
230
- #[ weight = (
231
- calls. iter( )
232
- . map( |call| call. get_dispatch_info( ) . weight)
235
+ #[ weight = {
236
+ let dispatch_infos = calls. iter( ) . map( |call| call. get_dispatch_info( ) ) . collect:: <Vec <_>>( ) ;
237
+ let dispatch_weight = dispatch_infos. iter( )
238
+ . map( |di| di. weight)
233
239
. fold( 0 , |total: Weight , weight: Weight | total. saturating_add( weight) )
234
- . saturating_add( T :: WeightInfo :: batch_all( calls. len( ) as u32 ) ) ,
235
- {
236
- let all_operational = calls . iter( )
237
- . map( |call| call . get_dispatch_info ( ) . class)
240
+ . saturating_add( T :: WeightInfo :: batch_all( calls. len( ) as u32 ) ) ;
241
+ let dispatch_class = {
242
+ let all_operational = dispatch_infos . iter( )
243
+ . map( |di| di . class)
238
244
. all( |class| class == DispatchClass :: Operational ) ;
239
245
if all_operational {
240
246
DispatchClass :: Operational
241
247
} else {
242
248
DispatchClass :: Normal
243
249
}
244
- } ,
245
- ) ]
250
+ } ;
251
+ ( dispatch_weight, dispatch_class)
252
+ } ]
246
253
#[ transactional]
247
254
fn batch_all( origin, calls: Vec <<T as Config >:: Call >) -> DispatchResultWithPostInfo {
248
255
let is_root = ensure_root( origin. clone( ) ) . is_ok( ) ;
0 commit comments