Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Remove indexes of utility,BatchCompletedWithErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
jasl committed Apr 6, 2022
1 parent e5a7a56 commit c1141ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 7 additions & 7 deletions frame/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> },
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.
Expand Down Expand Up @@ -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<u32> = 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 {
Expand All @@ -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);
}
Expand Down
8 changes: 2 additions & 6 deletions frame/utility/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand All @@ -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());
});
}

0 comments on commit c1141ca

Please sign in to comment.