fn unstake(&mut self, current_era: EraIndex, value: Balance) -> Result<(), &str> {
		if let Some(era_stake) = self.stakes.last_mut() {
			if era_stake.era > current_era {
				return Err("Unexpected era".into())
			}

			let new_stake_value = era_stake.staked.saturating_sub(value);
			if current_era == era_stake.era {
				*era_stake = EraStake::new(new_stake_value, current_era)
			} else {
				self.stakes.push(EraStake::new(new_stake_value, current_era))
			}

			// Removes unstaked values if they're no longer valid for comprehension
			if !self.stakes.is_empty() && self.stakes[0].staked.is_zero() {
				self.stakes.remove(0);
			}
		}

		Ok(())
	}
/// Unstakes some value in the specified era.
///
/// User should ensure that given era is either equal or greater than the
/// latest available era in the staking info.
///
/// # Example 1
///
/// `stakes: [<5, 1000>, <7, 1300>]`
/// * `unstake(7, 100)` will result in `[<5, 1000>, <7, 1200>]`
/// * `unstake(9, 400)` will result in `[<5, 1000>, <7, 1200>, <9, 800>]`
/// * `unstake(10, 800)` will result in `[<5, 1000>, <7, 1200>, <9, 800>, <0, 10>]`
///
/// # Example 2
///
/// `stakes: [<5, 1000>]`
/// * `unstake(1000, 0)` will result in `[]`
///
/// Note that if no unclaimed eras remain, vector will be cleared.
Unstakes some value in the specified era.
User should ensure that given era is either equal or greater than the
latest available era in the staking info.
Unstakes some value in the specified era . User should ensure that given era is either equal or greater than the latest available era in the staking info .
fn unstake(&mut self, current_era: EraIndex, value: Balance) -> Result<(), &str> {
		if let Some(era_stake) = self.stakes.last_mut() {
			if era_stake.era > current_era {
				return Err("Unexpected era".into())
			}
			let new_stake_value = era_stake.staked.saturating_sub(value);
			if current_era == era_stake.era {
				*era_stake = EraStake::new(new_stake_value, current_era)
			} else {
				self.stakes.push(EraStake::new(new_stake_value, current_era))
			}
			// Removes unstaked values if they're no longer valid for comprehension
			if !self.stakes.is_empty() && self.stakes[0].staked.is_zero() {
				self.stakes.remove(0);
			}
		}
		Ok(())
	}
fn unstake ( & mut self , current_era : EraIndex , value : Balance ) -> Result < ( ) , & str > { if let Some ( era_stake ) = self . stakes . last_mut ( ) { if era_stake . era > current_era { return Err ( " " . into ( ) ) } let new_stake_value = era_stake . staked . saturating_sub ( value ) ; if current_era == era_stake . era { * era_stake = EraStake :: new ( new_stake_value , current_era ) } else { self . stakes . push ( EraStake :: new ( new_stake_value , current_era ) ) } // Removes unstaked values if they're no longer valid for comprehension if ! self . stakes . is_empty ( ) && self . stakes [ 0 ] . staked . is_zero ( ) { self . stakes . remove ( 0 ) ; } } Ok ( ( ) ) }
Unstakes some value in the specified era.
Unstakes some value in the specified era .
&mut self
current_era
EraIndex
value
Balance
example 1
None
example 2


Note that if no unclaimed eras remain, vector will be cleared.
Note that if no unclaimed eras remain vector will be cleared .