Add pallet names to Events (#10296)

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* fix: add fix to tests for event variants

* chore: modified comments for event variants

* chore: modified comments for event variants

* chore: modified comments for event variants

* chore: modified comments for event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: updated transaction-storage pallet event variants

* chore: updated transaction-storage pallet event variants

* chore: formatted contracts pallet

* chore: update treasury event variants
This commit is contained in:
Enoch Chejieh
2021-11-30 21:03:06 +01:00
committed by GitHub
parent b5ed64684d
commit d58aeb040a
15 changed files with 209 additions and 184 deletions
+15 -15
View File
@@ -458,7 +458,7 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let hash = T::Hashing::hash(&remark[..]);
Self::deposit_event(Event::Remarked(who, hash));
Self::deposit_event(Event::Remarked { sender: who, hash });
Ok(().into())
}
}
@@ -466,18 +466,18 @@ pub mod pallet {
/// Event for the System pallet.
#[pallet::event]
pub enum Event<T: Config> {
/// An extrinsic completed successfully. \[info\]
ExtrinsicSuccess(DispatchInfo),
/// An extrinsic failed. \[error, info\]
ExtrinsicFailed(DispatchError, DispatchInfo),
/// An extrinsic completed successfully.
ExtrinsicSuccess { dispatch_info: DispatchInfo },
/// An extrinsic failed.
ExtrinsicFailed { dispatch_error: DispatchError, dispatch_info: DispatchInfo },
/// `:code` was updated.
CodeUpdated,
/// A new \[account\] was created.
NewAccount(T::AccountId),
/// An \[account\] was reaped.
KilledAccount(T::AccountId),
/// On on-chain remark happened. \[origin, remark_hash\]
Remarked(T::AccountId, T::Hash),
/// A new account was created.
NewAccount { account: T::AccountId },
/// An account was reaped.
KilledAccount { account: T::AccountId },
/// On on-chain remark happened.
Remarked { sender: T::AccountId, hash: T::Hash },
}
/// Old name generated by `decl_event`.
@@ -1486,7 +1486,7 @@ impl<T: Config> Pallet<T> {
pub fn note_applied_extrinsic(r: &DispatchResultWithPostInfo, mut info: DispatchInfo) {
info.weight = extract_actual_weight(r, &info);
Self::deposit_event(match r {
Ok(_) => Event::ExtrinsicSuccess(info),
Ok(_) => Event::ExtrinsicSuccess { dispatch_info: info },
Err(err) => {
log::trace!(
target: "runtime::system",
@@ -1494,7 +1494,7 @@ impl<T: Config> Pallet<T> {
Self::block_number(),
err,
);
Event::ExtrinsicFailed(err.error, info)
Event::ExtrinsicFailed { dispatch_error: err.error, dispatch_info: info }
},
});
@@ -1522,13 +1522,13 @@ impl<T: Config> Pallet<T> {
/// An account is being created.
pub fn on_created_account(who: T::AccountId, _a: &mut AccountInfo<T::Index, T::AccountData>) {
T::OnNewAccount::on_new_account(&who);
Self::deposit_event(Event::NewAccount(who));
Self::deposit_event(Event::NewAccount { account: who });
}
/// Do anything that needs to be done after an account has been killed.
fn on_killed_account(who: T::AccountId) {
T::OnKilledAccount::on_killed_account(&who);
Self::deposit_event(Event::KilledAccount(who));
Self::deposit_event(Event::KilledAccount { account: who });
}
/// Determine whether or not it is possible to update the code.
+30 -33
View File
@@ -168,44 +168,44 @@ fn deposit_event_should_work() {
);
System::initialize(&2, &[0u8; 32].into(), &Default::default(), InitKind::Full);
System::deposit_event(SysEvent::NewAccount(32));
System::deposit_event(SysEvent::NewAccount { account: 32 });
System::note_finished_initialize();
System::deposit_event(SysEvent::KilledAccount(42));
System::deposit_event(SysEvent::KilledAccount { account: 42 });
System::note_applied_extrinsic(&Ok(().into()), Default::default());
System::note_applied_extrinsic(&Err(DispatchError::BadOrigin.into()), Default::default());
System::note_finished_extrinsics();
System::deposit_event(SysEvent::NewAccount(3));
System::deposit_event(SysEvent::NewAccount { account: 3 });
System::finalize();
assert_eq!(
System::events(),
vec![
EventRecord {
phase: Phase::Initialization,
event: SysEvent::NewAccount(32).into(),
event: SysEvent::NewAccount { account: 32 }.into(),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: SysEvent::KilledAccount(42).into(),
event: SysEvent::KilledAccount { account: 42 }.into(),
topics: vec![]
},
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: SysEvent::ExtrinsicSuccess(Default::default()).into(),
event: SysEvent::ExtrinsicSuccess { dispatch_info: Default::default() }.into(),
topics: vec![]
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: SysEvent::ExtrinsicFailed(
DispatchError::BadOrigin.into(),
Default::default()
)
event: SysEvent::ExtrinsicFailed {
dispatch_error: DispatchError::BadOrigin.into(),
dispatch_info: Default::default()
}
.into(),
topics: vec![]
},
EventRecord {
phase: Phase::Finalization,
event: SysEvent::NewAccount(3).into(),
event: SysEvent::NewAccount { account: 3 }.into(),
topics: vec![]
},
]
@@ -234,37 +234,34 @@ fn deposit_event_uses_actual_weight() {
vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: SysEvent::ExtrinsicSuccess(DispatchInfo {
weight: 300,
..Default::default()
},)
event: SysEvent::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: 300, ..Default::default() },
}
.into(),
topics: vec![]
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: SysEvent::ExtrinsicSuccess(DispatchInfo {
weight: 1000,
..Default::default()
},)
event: SysEvent::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: 1000, ..Default::default() },
}
.into(),
topics: vec![]
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: SysEvent::ExtrinsicSuccess(DispatchInfo {
weight: 1000,
..Default::default()
},)
event: SysEvent::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: 1000, ..Default::default() },
}
.into(),
topics: vec![]
},
EventRecord {
phase: Phase::ApplyExtrinsic(3),
event: SysEvent::ExtrinsicFailed(
DispatchError::BadOrigin.into(),
DispatchInfo { weight: 999, ..Default::default() },
)
event: SysEvent::ExtrinsicFailed {
dispatch_error: DispatchError::BadOrigin.into(),
dispatch_info: DispatchInfo { weight: 999, ..Default::default() },
}
.into(),
topics: vec![]
},
@@ -284,9 +281,9 @@ fn deposit_event_topics() {
let topics = vec![H256::repeat_byte(1), H256::repeat_byte(2), H256::repeat_byte(3)];
// We deposit a few events with different sets of topics.
System::deposit_event_indexed(&topics[0..3], SysEvent::NewAccount(1).into());
System::deposit_event_indexed(&topics[0..1], SysEvent::NewAccount(2).into());
System::deposit_event_indexed(&topics[1..2], SysEvent::NewAccount(3).into());
System::deposit_event_indexed(&topics[0..3], SysEvent::NewAccount { account: 1 }.into());
System::deposit_event_indexed(&topics[0..1], SysEvent::NewAccount { account: 2 }.into());
System::deposit_event_indexed(&topics[1..2], SysEvent::NewAccount { account: 3 }.into());
System::finalize();
@@ -296,17 +293,17 @@ fn deposit_event_topics() {
vec![
EventRecord {
phase: Phase::Finalization,
event: SysEvent::NewAccount(1).into(),
event: SysEvent::NewAccount { account: 1 }.into(),
topics: topics[0..3].to_vec(),
},
EventRecord {
phase: Phase::Finalization,
event: SysEvent::NewAccount(2).into(),
event: SysEvent::NewAccount { account: 2 }.into(),
topics: topics[0..1].to_vec(),
},
EventRecord {
phase: Phase::Finalization,
event: SysEvent::NewAccount(3).into(),
event: SysEvent::NewAccount { account: 3 }.into(),
topics: topics[1..2].to_vec(),
}
]