Skip to content

Commit

Permalink
rename storage Delegatees to Agents
Browse files Browse the repository at this point in the history
  • Loading branch information
Ank4n committed Mar 31, 2024
1 parent c5a5d32 commit f82b349
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions substrate/frame/delegated-staking/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<T: Config> StakingInterface for Pallet<T> {
}

fn bond_extra(who: &Self::AccountId, extra: Self::Balance) -> DispatchResult {
let ledger = <Delegatees<T>>::get(who).ok_or(Error::<T>::NotAgent)?;
let ledger = <Agents<T>>::get(who).ok_or(Error::<T>::NotAgent)?;
ensure!(ledger.stakeable_balance() >= extra, Error::<T>::NotEnoughFunds);

T::CoreStaking::bond_extra(who, extra)
Expand Down Expand Up @@ -277,7 +277,7 @@ impl<T: Config> OnStakingUpdate<T::AccountId, BalanceOf<T>> for Pallet<T> {
_slashed_unlocking: &sp_std::collections::btree_map::BTreeMap<EraIndex, BalanceOf<T>>,
slashed_total: BalanceOf<T>,
) {
<Delegatees<T>>::mutate(who, |maybe_register| match maybe_register {
<Agents<T>>::mutate(who, |maybe_register| match maybe_register {
// if delegatee, register the slashed amount as pending slash.
Some(register) => register.pending_slash.saturating_accrue(slashed_total),
None => {
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/delegated-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub mod pallet {

/// Map of `Agent` to their `Ledger`.
#[pallet::storage]
pub(crate) type Delegatees<T: Config> =
pub(crate) type Agents<T: Config> =
CountedStorageMap<_, Twox64Concat, T::AccountId, DelegateeLedger<T>, OptionQuery>;

// This pallet is not currently written with the intention of exposing any calls. But the
Expand Down Expand Up @@ -448,7 +448,7 @@ impl<T: Config> Pallet<T> {

/// Returns true if who is registered as a `Delegatee`.
fn is_agent(who: &T::AccountId) -> bool {
<Delegatees<T>>::contains_key(who)
<Agents<T>>::contains_key(who)
}

/// Returns true if who is delegating to a `Delegatee` account.
Expand Down Expand Up @@ -748,7 +748,7 @@ impl<T: Config> Pallet<T> {
pub(crate) fn do_try_state() -> Result<(), sp_runtime::TryRuntimeError> {
// build map to avoid reading storage multiple times.
let delegation_map = Delegators::<T>::iter().collect::<BTreeMap<_, _>>();
let ledger_map = Delegatees::<T>::iter().collect::<BTreeMap<_, _>>();
let ledger_map = Agents::<T>::iter().collect::<BTreeMap<_, _>>();

Self::check_delegates(ledger_map.clone())?;
Self::check_delegators(delegation_map, ledger_map)?;
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/delegated-staking/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<T: Config> Delegation<T> {
.map(|delegation| delegation.delegatee == delegatee.clone())
.unwrap_or(
// all good if its a new delegator except it should not be an existing delegatee.
!<Delegatees<T>>::contains_key(delegator),
!<Agents<T>>::contains_key(delegator),
)
}

Expand Down Expand Up @@ -128,12 +128,12 @@ impl<T: Config> DelegateeLedger<T> {

/// Get `DelegateeLedger` from storage.
pub(crate) fn get(key: &T::AccountId) -> Option<Self> {
<Delegatees<T>>::get(key)
<Agents<T>>::get(key)
}

/// Save self to storage with the given key.
pub(crate) fn save(self, key: &T::AccountId) {
<Delegatees<T>>::insert(key, self)
<Agents<T>>::insert(key, self)
}

/// Effective total balance of the `delegatee`.
Expand Down Expand Up @@ -280,7 +280,7 @@ impl<T: Config> Delegatee<T> {
self.ledger.pending_slash == Zero::zero(),
Error::<T>::BadState
);
<Delegatees<T>>::remove(key);
<Agents<T>>::remove(key);
} else {
self.ledger.save(&key)
}
Expand Down

0 comments on commit f82b349

Please sign in to comment.