pallet-proxy: emit events on proxy added. (#9546)

* pallet-proxy: emit events on proxy added.

* Apply review suggestions.
This commit is contained in:
Shaun Wang
2021-08-25 22:27:56 +12:00
committed by GitHub
parent 5a347adad2
commit a7e714aeb1
2 changed files with 20 additions and 2 deletions
+19 -2
View File
@@ -534,7 +534,12 @@ pub mod pallet {
}
#[pallet::event]
#[pallet::metadata(T::AccountId = "AccountId", T::ProxyType = "ProxyType", CallHashOf<T> = "Hash")]
#[pallet::metadata(
T::AccountId = "AccountId",
T::ProxyType = "ProxyType",
CallHashOf<T> = "Hash",
T::BlockNumber = "BlockNumber",
)]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A proxy was executed correctly, with the given \[result\].
@@ -545,6 +550,8 @@ pub mod pallet {
AnonymousCreated(T::AccountId, T::AccountId, T::ProxyType, u16),
/// An announcement was placed to make a call in the future. \[real, proxy, call_hash\]
Announced(T::AccountId, T::AccountId, CallHashOf<T>),
/// A proxy was added. \[delegator, delegatee, proxy_type, delay\]
ProxyAdded(T::AccountId, T::AccountId, T::ProxyType, T::BlockNumber),
}
/// Old name generated by `decl_event`.
@@ -646,7 +653,11 @@ impl<T: Config> Pallet<T> {
) -> DispatchResult {
ensure!(delegator != &delegatee, Error::<T>::NoSelfProxy);
Proxies::<T>::try_mutate(delegator, |(ref mut proxies, ref mut deposit)| {
let proxy_def = ProxyDefinition { delegate: delegatee, proxy_type, delay };
let proxy_def = ProxyDefinition {
delegate: delegatee.clone(),
proxy_type: proxy_type.clone(),
delay,
};
let i = proxies.binary_search(&proxy_def).err().ok_or(Error::<T>::Duplicate)?;
proxies.try_insert(i, proxy_def).map_err(|_| Error::<T>::TooMany)?;
let new_deposit = Self::deposit(proxies.len() as u32);
@@ -656,6 +667,12 @@ impl<T: Config> Pallet<T> {
T::Currency::unreserve(delegator, *deposit - new_deposit);
}
*deposit = new_deposit;
Self::deposit_event(Event::<T>::ProxyAdded(
delegator.clone(),
delegatee,
proxy_type,
delay,
));
Ok(())
})
}
+1
View File
@@ -194,6 +194,7 @@ fn expect_events(e: Vec<Event>) {
fn announcement_works() {
new_test_ext().execute_with(|| {
assert_ok!(Proxy::add_proxy(Origin::signed(1), 3, ProxyType::Any, 1));
System::assert_last_event(ProxyEvent::ProxyAdded(1, 3, ProxyType::Any, 1).into());
assert_ok!(Proxy::add_proxy(Origin::signed(2), 3, ProxyType::Any, 1));
assert_eq!(Balances::reserved_balance(3), 0);