From c1141caebb8799a130d8db03dc5a997aea843720 Mon Sep 17 00:00:00 2001 From: jasl Date: Wed, 6 Apr 2022 05:35:42 +0800 Subject: [PATCH] Remove indexes of utility,BatchCompletedWithErrors --- frame/utility/src/lib.rs | 14 +++++++------- frame/utility/src/tests.rs | 8 ++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index e72a2ca29b971..494ba685690cc 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -114,7 +114,7 @@ pub mod pallet { /// Batch of dispatches completed fully with no error. BatchCompleted, /// Batch of dispatches complete but has errors. Index of failing dispatches. - BatchCompletedWithErrors { indexes: Vec }, + BatchCompletedWithErrors, /// A single item within a Batch of dispatches has completed with no error. ItemCompleted, /// A single item within a Batch of dispatches has completed with error. @@ -432,9 +432,9 @@ pub mod pallet { // Track the actual weight of each of the batch calls. let mut weight: Weight = 0; - // Track failed dispatches' index. - let mut error_indexes: Vec = Vec::new(); - for (index, call) in calls.into_iter().enumerate() { + // Track failed dispatch occur. + let mut has_error: bool = false; + for call in calls.into_iter() { let info = call.get_dispatch_info(); // If origin is root, don't apply any dispatch filters; root can call anything. let result = if is_root { @@ -445,14 +445,14 @@ pub mod pallet { // Add the weight of this call. weight = weight.saturating_add(extract_actual_weight(&result, &info)); if let Err(e) = result { - error_indexes.push(index as u32); + has_error = true; Self::deposit_event(Event::ItemFailed { error: e.error }); } else { Self::deposit_event(Event::ItemCompleted); } } - if error_indexes.len() > 0 { - Self::deposit_event(Event::BatchCompletedWithErrors { indexes: error_indexes }); + if has_error { + Self::deposit_event(Event::BatchCompletedWithErrors); } else { Self::deposit_event(Event::BatchCompleted); } diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 8a1e8a068da42..f53459a707b54 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -621,9 +621,7 @@ fn force_batch_works() { call_transfer(2, 5), ] ),); - System::assert_last_event( - utility::Event::BatchCompletedWithErrors { indexes: vec![1, 2] }.into(), - ); + System::assert_last_event(utility::Event::BatchCompletedWithErrors.into()); System::assert_has_event( utility::Event::ItemFailed { error: DispatchError::Other("") }.into(), ); @@ -637,8 +635,6 @@ fn force_batch_works() { System::assert_last_event(utility::Event::BatchCompleted.into()); assert_ok!(Utility::force_batch(Origin::signed(1), vec![call_transfer(2, 50),]),); - System::assert_last_event( - utility::Event::BatchCompletedWithErrors { indexes: vec![0] }.into(), - ); + System::assert_last_event(utility::Event::BatchCompletedWithErrors.into()); }); }