emit event on remark (#8120)

Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Xiliang Chen
2021-02-28 23:02:46 +13:00
committed by GitHub
parent ed365da8b9
commit 8ac2cd57cc
3 changed files with 51 additions and 20 deletions
+17 -3
View File
@@ -292,8 +292,6 @@ pub mod pallet {
///
/// # <weight>
/// - `O(1)`
/// - Base Weight: 0.665 µs, independent of remark length.
/// - No DB operations.
/// # </weight>
#[pallet::weight(T::SystemWeightInfo::remark(_remark.len() as u32))]
pub(crate) fn remark(origin: OriginFor<T>, _remark: Vec<u8>) -> DispatchResultWithPostInfo {
@@ -450,11 +448,25 @@ pub mod pallet {
storage::unhashed::kill_prefix(&prefix);
Ok(().into())
}
/// Make some on-chain remark and emit event.
///
/// # <weight>
/// - `O(b)` where b is the length of the remark.
/// - 1 event.
/// # </weight>
#[pallet::weight(T::SystemWeightInfo::remark_with_event(remark.len() as u32))]
pub(crate) fn remark_with_event(origin: OriginFor<T>, remark: Vec<u8>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let hash = T::Hashing::hash(&remark[..]);
Self::deposit_event(Event::Remarked(who, hash));
Ok(().into())
}
}
/// Event for the System pallet.
#[pallet::event]
#[pallet::metadata(T::AccountId = "AccountId")]
#[pallet::metadata(T::AccountId = "AccountId", T::Hash = "Hash")]
pub enum Event<T: Config> {
/// An extrinsic completed successfully. \[info\]
ExtrinsicSuccess(DispatchInfo),
@@ -466,6 +478,8 @@ pub mod pallet {
NewAccount(T::AccountId),
/// An \[account\] was reaped.
KilledAccount(T::AccountId),
/// On on-chain remark happened. \[origin, remark_hash\]
Remarked(T::AccountId, T::Hash),
}
/// Old name generated by `decl_event`.