Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Add remove_proxies API for pallet-proxies #7557 (#12714)
Browse files Browse the repository at this point in the history
* Open
Add remove_proxies API for pallet-proxies
#7557

* added remove_all_proxy_delegates method

* remove all proxy implementation

* remove_all_proxy_delegate

* reverted changes

* fixed 7557

* fixed warnings

* removed println! causing build failure on ci/cd pipelines

* incorporated suggested changes

* minor change

* made suggested changes

* method comment

* Update frame/proxy/src/lib.rs

---------

Co-authored-by: Juan <juangirini@gmail.com>
Co-authored-by: parity-processbot <>
  • Loading branch information
vjgaur and juangirini committed May 26, 2023
1 parent f4cb21c commit 46127a9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions frame/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ use frame_support::{
traits::{Currency, Get, InstanceFilter, IsSubType, IsType, OriginTrait, ReservableCurrency},
RuntimeDebug,
};
use frame_system::{self as system};
use frame_system::{self as system, ensure_signed};
pub use pallet::*;
use scale_info::TypeInfo;
use sp_io::hashing::blake2_256;
use sp_runtime::{
Expand All @@ -50,8 +51,6 @@ use sp_runtime::{
use sp_std::prelude::*;
pub use weights::WeightInfo;

pub use pallet::*;

type CallHashOf<T> = <<T as Config>::CallHasher as Hash>::Output;

type BalanceOf<T> =
Expand Down Expand Up @@ -265,9 +264,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::remove_proxies(T::MaxProxies::get()))]
pub fn remove_proxies(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
let (_, old_deposit) = Proxies::<T>::take(&who);
T::Currency::unreserve(&who, old_deposit);

Self::remove_all_proxy_delegates(&who);
Ok(())
}

Expand Down Expand Up @@ -799,4 +796,13 @@ impl<T: Config> Pallet<T> {
let e = call.dispatch(origin);
Self::deposit_event(Event::ProxyExecuted { result: e.map(|_| ()).map_err(|e| e.error) });
}

/// Removes all proxy delegates for a given delegator.
///
/// Parameters:
/// - `delegator`: The delegator account.
pub fn remove_all_proxy_delegates(delegator: &T::AccountId) {
let (_, old_deposit) = Proxies::<T>::take(&delegator);
T::Currency::unreserve(&delegator, old_deposit);
}
}

0 comments on commit 46127a9

Please sign in to comment.