mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-22 01:01:03 +00:00
Replace T::AccountId with <T::Lookup as StaticLookup>::Source (#11670)
* initial * update * update * update * cargo fmt * update * update benchmarks * AccountIdLookupOf<T> * cargo fmt * fix conflits * cargo fmt * update Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -156,7 +156,7 @@
|
||||
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::traits::{CheckedAdd, CheckedMul, Dispatchable, SaturatedConversion};
|
||||
use sp_runtime::traits::{CheckedAdd, CheckedMul, Dispatchable, SaturatedConversion, StaticLookup};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
use frame_support::{
|
||||
@@ -182,6 +182,7 @@ type BalanceOf<T> =
|
||||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
||||
|
||||
type FriendsOf<T> = BoundedVec<<T as frame_system::Config>::AccountId, <T as Config>::MaxFriends>;
|
||||
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
|
||||
|
||||
/// An active recovery process.
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, Default, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
@@ -382,10 +383,11 @@ pub mod pallet {
|
||||
)})]
|
||||
pub fn as_recovered(
|
||||
origin: OriginFor<T>,
|
||||
account: T::AccountId,
|
||||
account: AccountIdLookupOf<T>,
|
||||
call: Box<<T as Config>::Call>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let account = T::Lookup::lookup(account)?;
|
||||
// Check `who` is allowed to make a call on behalf of `account`
|
||||
let target = Self::proxy(&who).ok_or(Error::<T>::NotAllowed)?;
|
||||
ensure!(target == account, Error::<T>::NotAllowed);
|
||||
@@ -405,10 +407,12 @@ pub mod pallet {
|
||||
#[pallet::weight(T::WeightInfo::set_recovered())]
|
||||
pub fn set_recovered(
|
||||
origin: OriginFor<T>,
|
||||
lost: T::AccountId,
|
||||
rescuer: T::AccountId,
|
||||
lost: AccountIdLookupOf<T>,
|
||||
rescuer: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
let lost = T::Lookup::lookup(lost)?;
|
||||
let rescuer = T::Lookup::lookup(rescuer)?;
|
||||
// Create the recovery storage item.
|
||||
<Proxy<T>>::insert(&rescuer, &lost);
|
||||
Self::deposit_event(Event::<T>::AccountRecovered {
|
||||
@@ -486,8 +490,12 @@ pub mod pallet {
|
||||
/// - `account`: The lost account that you want to recover. This account needs to be
|
||||
/// recoverable (i.e. have a recovery configuration).
|
||||
#[pallet::weight(T::WeightInfo::initiate_recovery())]
|
||||
pub fn initiate_recovery(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
|
||||
pub fn initiate_recovery(
|
||||
origin: OriginFor<T>,
|
||||
account: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let account = T::Lookup::lookup(account)?;
|
||||
// Check that the account is recoverable
|
||||
ensure!(<Recoverable<T>>::contains_key(&account), Error::<T>::NotRecoverable);
|
||||
// Check that the recovery process has not already been started
|
||||
@@ -528,10 +536,12 @@ pub mod pallet {
|
||||
#[pallet::weight(T::WeightInfo::vouch_recovery(T::MaxFriends::get()))]
|
||||
pub fn vouch_recovery(
|
||||
origin: OriginFor<T>,
|
||||
lost: T::AccountId,
|
||||
rescuer: T::AccountId,
|
||||
lost: AccountIdLookupOf<T>,
|
||||
rescuer: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let lost = T::Lookup::lookup(lost)?;
|
||||
let rescuer = T::Lookup::lookup(rescuer)?;
|
||||
// Get the recovery configuration for the lost account.
|
||||
let recovery_config = Self::recovery_config(&lost).ok_or(Error::<T>::NotRecoverable)?;
|
||||
// Get the active recovery process for the rescuer.
|
||||
@@ -567,8 +577,12 @@ pub mod pallet {
|
||||
/// - `account`: The lost account that you want to claim has been successfully recovered by
|
||||
/// you.
|
||||
#[pallet::weight(T::WeightInfo::claim_recovery(T::MaxFriends::get()))]
|
||||
pub fn claim_recovery(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
|
||||
pub fn claim_recovery(
|
||||
origin: OriginFor<T>,
|
||||
account: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let account = T::Lookup::lookup(account)?;
|
||||
// Get the recovery configuration for the lost account
|
||||
let recovery_config =
|
||||
Self::recovery_config(&account).ok_or(Error::<T>::NotRecoverable)?;
|
||||
@@ -610,8 +624,12 @@ pub mod pallet {
|
||||
/// Parameters:
|
||||
/// - `rescuer`: The account trying to rescue this recoverable account.
|
||||
#[pallet::weight(T::WeightInfo::close_recovery(T::MaxFriends::get()))]
|
||||
pub fn close_recovery(origin: OriginFor<T>, rescuer: T::AccountId) -> DispatchResult {
|
||||
pub fn close_recovery(
|
||||
origin: OriginFor<T>,
|
||||
rescuer: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let rescuer = T::Lookup::lookup(rescuer)?;
|
||||
// Take the active recovery process started by the rescuer for this account.
|
||||
let active_recovery =
|
||||
<ActiveRecoveries<T>>::take(&who, &rescuer).ok_or(Error::<T>::NotStarted)?;
|
||||
@@ -665,8 +683,12 @@ pub mod pallet {
|
||||
/// Parameters:
|
||||
/// - `account`: The recovered account you are able to call on-behalf-of.
|
||||
#[pallet::weight(T::WeightInfo::cancel_recovered())]
|
||||
pub fn cancel_recovered(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
|
||||
pub fn cancel_recovered(
|
||||
origin: OriginFor<T>,
|
||||
account: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let account = T::Lookup::lookup(account)?;
|
||||
// Check `who` is allowed to make a call on behalf of `account`
|
||||
ensure!(Self::proxy(&who) == Some(account), Error::<T>::NotAllowed);
|
||||
Proxy::<T>::remove(&who);
|
||||
|
||||
Reference in New Issue
Block a user