fn increase_guarantee(
        v_stash: &T::AccountId,
        g_stash: &T::AccountId,
        bonded: BalanceOf<T>,
        votes: BalanceOf<T>
    ) -> Option<Guarantee<T::AccountId, BalanceOf<T>>> {
        // 1. Already guaranteed
        if let Some(guarantee) = Self::guarantors(g_stash) {
            let remains = bonded.saturating_sub(guarantee.total);
            let real_votes = remains.min(votes);
            let new_total = guarantee.total.saturating_add(real_votes);
            let mut new_targets: Vec<IndividualExposure<T::AccountId, BalanceOf<T>>> = vec![];
            let mut update = false;

            if real_votes <= Zero::zero() {
                log!(
                    debug,
                    "💸 Staking limit of validator {:?} is zero.",
                    v_stash
                );
                return None
            }

            // Fill in `new_targets`, always LOOP the `targets`
            // However, the TC is O(1) due to the `MAX_GUARANTEE` restriction 🤪
            for mut target in guarantee.targets {
                // a. Update an edge
                if &target.who == v_stash {
                    target.value += real_votes;
                    update = true;
                }
                new_targets.push(target.clone());
            }

            if !update {
                if new_targets.len() >= MAX_GUARANTEE {
                    return None
                } else {
                    // b. New an edge
                    new_targets.push(IndividualExposure {
                        who: v_stash.clone(),
                        value: real_votes
                    });
                }
            }

            Some(Guarantee {
                targets: new_targets.clone(),
                total: new_total,
                submitted_in: Self::current_era().unwrap_or(0),
                suppressed: false,
            })

        // 2. New guarantee
        } else {
            let real_votes = bonded.min(votes);
            let new_total = real_votes;

            // No need check with this case, votes and bonded all greater than 0

            let mut new_targets: Vec<IndividualExposure<T::AccountId, BalanceOf<T>>> = vec![];
            new_targets.push(IndividualExposure {
                who: v_stash.clone(),
                value: real_votes
            });

            Some(Guarantee {
                targets: new_targets.clone(),
                total: new_total,
                submitted_in: Self::current_era().unwrap_or(0),
                suppressed: false,
            })
        }
    }
/// Get the updated (increased) guarantee relationship
/// Basically, this function construct an updated edge or insert a new edge,
/// then returns the updated `Guarantee`
///
/// # <weight>
/// - Independent of the arguments. Insignificant complexity.
/// - O(1).
/// - 1 DB entry.
/// # </weight>
Get the updated (increased) guarantee relationship
Basically, this function construct an updated edge or insert a new edge,
then returns the updated `Guarantee`
Get the updated ( increased ) guarantee relationship Basically this function construct an updated edge or insert a new edge then returns the updated ` Guarantee `
fn increase_guarantee(
        v_stash: &T::AccountId,
        g_stash: &T::AccountId,
        bonded: BalanceOf<T>,
        votes: BalanceOf<T>
    ) -> Option<Guarantee<T::AccountId, BalanceOf<T>>> {
        // 1. Already guaranteed
        if let Some(guarantee) = Self::guarantors(g_stash) {
            let remains = bonded.saturating_sub(guarantee.total);
            let real_votes = remains.min(votes);
            let new_total = guarantee.total.saturating_add(real_votes);
            let mut new_targets: Vec<IndividualExposure<T::AccountId, BalanceOf<T>>> = vec![];
            let mut update = false;
            if real_votes <= Zero::zero() {
                log!(
                    debug,
                    "💸 Staking limit of validator {:?} is zero.",
                    v_stash
                );
                return None
            }
            // Fill in `new_targets`, always LOOP the `targets`
            // However, the TC is O(1) due to the `MAX_GUARANTEE` restriction 🤪
            for mut target in guarantee.targets {
                // a. Update an edge
                if &target.who == v_stash {
                    target.value += real_votes;
                    update = true;
                }
                new_targets.push(target.clone());
            }
            if !update {
                if new_targets.len() >= MAX_GUARANTEE {
                    return None
                } else {
                    // b. New an edge
                    new_targets.push(IndividualExposure {
                        who: v_stash.clone(),
                        value: real_votes
                    });
                }
            }
            Some(Guarantee {
                targets: new_targets.clone(),
                total: new_total,
                submitted_in: Self::current_era().unwrap_or(0),
                suppressed: false,
            })
        // 2. New guarantee
        } else {
            let real_votes = bonded.min(votes);
            let new_total = real_votes;
            // No need check with this case, votes and bonded all greater than 0
            let mut new_targets: Vec<IndividualExposure<T::AccountId, BalanceOf<T>>> = vec![];
            new_targets.push(IndividualExposure {
                who: v_stash.clone(),
                value: real_votes
            });
            Some(Guarantee {
                targets: new_targets.clone(),
                total: new_total,
                submitted_in: Self::current_era().unwrap_or(0),
                suppressed: false,
            })
        }
    }
fn increase_guarantee ( v_stash : & T :: AccountId , g_stash : & T :: AccountId , bonded : BalanceOf < T > , votes : BalanceOf < T > ) -> Option < Guarantee < T :: AccountId , BalanceOf < T > > > { // 1. Already guaranteed if let Some ( guarantee ) = Self :: guarantors ( g_stash ) { let remains = bonded . saturating_sub ( guarantee . total ) ; let real_votes = remains . min ( votes ) ; let new_total = guarantee . total . saturating_add ( real_votes ) ; let mut new_targets : Vec < IndividualExposure < T :: AccountId , BalanceOf < T > > > = vec ! [ ] ; let mut update = false ; if real_votes <= Zero :: zero ( ) { log ! ( debug " v_stash ) ; return None } // Fill in `new_targets`, always LOOP the `targets` // However, the TC is O(1) due to the `MAX_GUARANTEE` restriction 🤪 for mut target in guarantee . targets { // a. Update an edge if & target . who == v_stash { target . value += real_votes ; update = true ; } new_targets . push ( target . clone ( ) ) ; } if ! update { if new_targets . len ( ) >= MAX_GUARANTEE { return None } else { // b. New an edge new_targets . push ( IndividualExposure { who : v_stash . clone ( ) , value : real_votes } ) ; } } Some ( Guarantee { targets : new_targets . clone ( ) , total : new_total , submitted_in : Self :: current_era ( ) . unwrap_or ( 0 ) , suppressed : false , } ) // 2. New guarantee } else { let real_votes = bonded . min ( votes ) ; let new_total = real_votes ; // No need check with this case, votes and bonded all greater than 0 let mut new_targets : Vec < IndividualExposure < T :: AccountId , BalanceOf < T > > > = vec ! [ ] ; new_targets . push ( IndividualExposure { who : v_stash . clone ( ) , value : real_votes } ) ; Some ( Guarantee { targets : new_targets . clone ( ) , total : new_total , submitted_in : Self :: current_era ( ) . unwrap_or ( 0 ) , suppressed : false , } ) } }
Get the updated (increased) guarantee relationship
Basically, this function construct an updated edge or insert a new edge,
then returns the updated `Guarantee`
Get the updated ( increased ) guarantee relationship Basically this function construct an updated edge or insert a new edge then returns the updated ` Guarantee `
v_stash
&T::AccountId
g_stash
&T::AccountId
bonded
BalanceOf<T>
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