mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
pallet-proxy: emit events on proxy added. (#9546)
* pallet-proxy: emit events on proxy added. * Apply review suggestions.
This commit is contained in:
@@ -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(())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user