From 61347ee38b8bc094c039ef71ae561652a73dab83 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Wed, 25 Aug 2021 22:27:56 +1200 Subject: [PATCH] pallet-proxy: emit events on proxy added. (#9546) * pallet-proxy: emit events on proxy added. * Apply review suggestions. --- frame/proxy/src/lib.rs | 21 +++++++++++++++++++-- frame/proxy/src/tests.rs | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/frame/proxy/src/lib.rs b/frame/proxy/src/lib.rs index 6a853c8e2b8e1..0537ed4a32392 100644 --- a/frame/proxy/src/lib.rs +++ b/frame/proxy/src/lib.rs @@ -534,7 +534,12 @@ pub mod pallet { } #[pallet::event] - #[pallet::metadata(T::AccountId = "AccountId", T::ProxyType = "ProxyType", CallHashOf = "Hash")] + #[pallet::metadata( + T::AccountId = "AccountId", + T::ProxyType = "ProxyType", + CallHashOf = "Hash", + T::BlockNumber = "BlockNumber", + )] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { /// 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), + /// 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 Pallet { ) -> DispatchResult { ensure!(delegator != &delegatee, Error::::NoSelfProxy); Proxies::::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::::Duplicate)?; proxies.try_insert(i, proxy_def).map_err(|_| Error::::TooMany)?; let new_deposit = Self::deposit(proxies.len() as u32); @@ -656,6 +667,12 @@ impl Pallet { T::Currency::unreserve(delegator, *deposit - new_deposit); } *deposit = new_deposit; + Self::deposit_event(Event::::ProxyAdded( + delegator.clone(), + delegatee, + proxy_type, + delay, + )); Ok(()) }) } diff --git a/frame/proxy/src/tests.rs b/frame/proxy/src/tests.rs index f3fe1d674a87d..eb4193a18d935 100644 --- a/frame/proxy/src/tests.rs +++ b/frame/proxy/src/tests.rs @@ -194,6 +194,7 @@ fn expect_events(e: Vec) { 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);