fn decrease_guarantee(
        v_stash: &T::AccountId,
        g_stash: &T::AccountId,
        votes: BalanceOf<T>,
    ) -> Option<Guarantee<T::AccountId, BalanceOf<T>>> {
        if let Some(guarantee) = Self::guarantors(g_stash) {
            // `decreased_votes` = min(votes, target.value)
            // `new_targets` means the targets after decreased
            // `exists` means the targets contains `v_stash`
            let mut decreased_votes = Zero::zero();
            let mut new_targets: Vec<IndividualExposure<T::AccountId, BalanceOf<T>>> = vec![];
            let mut exists = false;

            // Always LOOP the targets
            // However, the TC is O(1), due to the `MAX_GUARANTEE` restriction 🤪
            for target in guarantee.targets {
                if &target.who == v_stash {
                    // 1. Mark it really exists (BRAVO), and update the decreased votes
                    exists = true;
                    decreased_votes = target.value.min(votes);

                    if target.value <= votes{
                        // 2. Remove this target
                    } else {
                        // 3. Decrease the value
                        let new_target = IndividualExposure {
                            who: v_stash.clone(),
                            value: target.value - votes
                        };
                        new_targets.push(new_target);
                    }
                } else {
                    // 4. Push target with no change
                    new_targets.push(target.clone());
                }
            }

            if exists  {
                // 5. Update `new_total` with saturating sub the decreased_votes
                let new_total = guarantee.total.saturating_sub(decreased_votes);

                // TODO: `submitted_in` and `suppressed` should not be change?
                return Some(Guarantee {
                    targets: new_targets.clone(),
                    total: new_total,
                    submitted_in: guarantee.submitted_in,
                    suppressed: guarantee.suppressed
                })
            }
        }

        None
    }
/// Get the updated (decreased) guarantee relationship
/// Basically, this function construct an updated edge,
/// then returns the updated `Guarantee`
///
/// # <weight>
/// - Independent of the arguments. Insignificant complexity.
/// - O(1).
/// - 1 DB entry.
/// # </weight>
Get the updated (decreased) guarantee relationship
Basically, this function construct an updated edge,
then returns the updated `Guarantee`
Get the updated ( decreased ) guarantee relationship Basically this function construct an updated edge then returns the updated ` Guarantee `
fn decrease_guarantee(
        v_stash: &T::AccountId,
        g_stash: &T::AccountId,
        votes: BalanceOf<T>,
    ) -> Option<Guarantee<T::AccountId, BalanceOf<T>>> {
        if let Some(guarantee) = Self::guarantors(g_stash) {
            // `decreased_votes` = min(votes, target.value)
            // `new_targets` means the targets after decreased
            // `exists` means the targets contains `v_stash`
            let mut decreased_votes = Zero::zero();
            let mut new_targets: Vec<IndividualExposure<T::AccountId, BalanceOf<T>>> = vec![];
            let mut exists = false;
            // Always LOOP the targets
            // However, the TC is O(1), due to the `MAX_GUARANTEE` restriction 🤪
            for target in guarantee.targets {
                if &target.who == v_stash {
                    // 1. Mark it really exists (BRAVO), and update the decreased votes
                    exists = true;
                    decreased_votes = target.value.min(votes);
                    if target.value <= votes{
                        // 2. Remove this target
                    } else {
                        // 3. Decrease the value
                        let new_target = IndividualExposure {
                            who: v_stash.clone(),
                            value: target.value - votes
                        };
                        new_targets.push(new_target);
                    }
                } else {
                    // 4. Push target with no change
                    new_targets.push(target.clone());
                }
            }
            if exists  {
                // 5. Update `new_total` with saturating sub the decreased_votes
                let new_total = guarantee.total.saturating_sub(decreased_votes);
                // TODO: `submitted_in` and `suppressed` should not be change?
                return Some(Guarantee {
                    targets: new_targets.clone(),
                    total: new_total,
                    submitted_in: guarantee.submitted_in,
                    suppressed: guarantee.suppressed
                })
            }
        }
        None
    }
fn decrease_guarantee ( v_stash : & T :: AccountId , g_stash : & T :: AccountId , votes : BalanceOf < T > , ) -> Option < Guarantee < T :: AccountId , BalanceOf < T > > > { if let Some ( guarantee ) = Self :: guarantors ( g_stash ) { // `decreased_votes` = min(votes, target.value) // `new_targets` means the targets after decreased // `exists` means the targets contains `v_stash` let mut decreased_votes = Zero :: zero ( ) ; let mut new_targets : Vec < IndividualExposure < T :: AccountId , BalanceOf < T > > > = vec ! [ ] ; let mut exists = false ; // Always LOOP the targets // However, the TC is O(1), due to the `MAX_GUARANTEE` restriction 🤪 for target in guarantee . targets { if & target . who == v_stash { // 1. Mark it really exists (BRAVO), and update the decreased votes exists = true ; decreased_votes = target . value . min ( votes ) ; if target . value <= votes { // 2. Remove this target } else { // 3. Decrease the value let new_target = IndividualExposure { who : v_stash . clone ( ) , value : target . value - votes } ; new_targets . push ( new_target ) ; } } else { // 4. Push target with no change new_targets . push ( target . clone ( ) ) ; } } if exists { // 5. Update `new_total` with saturating sub the decreased_votes let new_total = guarantee . total . saturating_sub ( decreased_votes ) ; // TODO: `submitted_in` and `suppressed` should not be change? return Some ( Guarantee { targets : new_targets . clone ( ) , total : new_total , submitted_in : guarantee . submitted_in , suppressed : guarantee . suppressed } ) } } None }
Get the updated (decreased) guarantee relationship
Basically, this function construct an updated edge,
then returns the updated `Guarantee`
Get the updated ( decreased ) guarantee relationship Basically this function construct an updated edge then returns the updated ` Guarantee `
v_stash
&T::AccountId
g_stash
&T::AccountId
votes
BalanceOf<T>
<weight>
Independent of the arguments. Insignificant complexity.
O(1).
1 DB entry.
Independent of the arguments . Insignificant complexity . O ( 1 ) . 1 DB entry .
</weight>
None