Skip to content

Commit

Permalink
pallet-proxy: emit events on proxy added. (paritytech#9546)
Browse files Browse the repository at this point in the history
* pallet-proxy: emit events on proxy added.

* Apply review suggestions.
  • Loading branch information
shaunxw authored and Wizdave97 committed Aug 25, 2021
1 parent 0a4c546 commit 61347ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
21 changes: 19 additions & 2 deletions frame/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\].
Expand All @@ -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`.
Expand Down Expand Up @@ -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);
Expand All @@ -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(())
})
}
Expand Down
1 change: 1 addition & 0 deletions frame/proxy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 61347ee

Please sign in to comment.