pub fn decrease_stake(
        &mut self,
        amount: U512,
        era_end_timestamp_millis: u64,
    ) -> Result<U512, Error> {
        let updated_staked_amount = self
            .staked_amount
            .checked_sub(amount)
            .ok_or(Error::InvalidAmount)?;

        let vesting_schedule = match self.vesting_schedule.as_ref() {
            Some(vesting_schedule) => vesting_schedule,
            None => {
                self.staked_amount = updated_staked_amount;
                return Ok(updated_staked_amount);
            }
        };

        match vesting_schedule.locked_amount(era_end_timestamp_millis) {
            Some(locked_amount) if updated_staked_amount < locked_amount => {
                Err(Error::DelegatorFundsLocked)
            }
            None => {
                // If `None`, then the locked amounts table has yet to be initialized (likely
                // pre-90 day mark)
                Err(Error::DelegatorFundsLocked)
            }
            Some(_) => {
                self.staked_amount = updated_staked_amount;
                Ok(updated_staked_amount)
            }
        }
    }
/// Decreases the stake of the provided bid
Decreases the stake of the provided bid
Decreases the stake of the provided bid
pub fn decrease_stake(
        &mut self,
        amount: U512,
        era_end_timestamp_millis: u64,
    ) -> Result<U512, Error> {
        let updated_staked_amount = self
            .staked_amount
            .checked_sub(amount)
            .ok_or(Error::InvalidAmount)?;
        let vesting_schedule = match self.vesting_schedule.as_ref() {
            Some(vesting_schedule) => vesting_schedule,
            None => {
                self.staked_amount = updated_staked_amount;
                return Ok(updated_staked_amount);
            }
        };
        match vesting_schedule.locked_amount(era_end_timestamp_millis) {
            Some(locked_amount) if updated_staked_amount < locked_amount => {
                Err(Error::DelegatorFundsLocked)
            }
            None => {
                // If `None`, then the locked amounts table has yet to be initialized (likely
                // pre-90 day mark)
                Err(Error::DelegatorFundsLocked)
            }
            Some(_) => {
                self.staked_amount = updated_staked_amount;
                Ok(updated_staked_amount)
            }
        }
    }
pub fn decrease_stake ( & mut self , amount : U512 , era_end_timestamp_millis : u64 , ) -> Result < U512 , Error > { let updated_staked_amount = self . staked_amount . checked_sub ( amount ) . ok_or ( Error :: InvalidAmount ) ? ; let vesting_schedule = match self . vesting_schedule . as_ref ( ) { Some ( vesting_schedule ) => vesting_schedule , None => { self . staked_amount = updated_staked_amount ; return Ok ( updated_staked_amount ) ; } } ; match vesting_schedule . locked_amount ( era_end_timestamp_millis ) { Some ( locked_amount ) if updated_staked_amount < locked_amount => { Err ( Error :: DelegatorFundsLocked ) } None => { // If `None`, then the locked amounts table has yet to be initialized (likely // pre-90 day mark) Err ( Error :: DelegatorFundsLocked ) } Some ( _ ) => { self . staked_amount = updated_staked_amount ; Ok ( updated_staked_amount ) } } }
Decreases the stake of the provided bid
Decreases the stake of the provided bid
&mut self
amount
U512
era_end_timestamp_millis
u64
&mut self
amount
U512
era_end_timestamp_millis
u64