fn withdraw_bid(&mut self, public_key: PublicKey, amount: U512) -> Result<U512, Error> {
        let provided_account_hash = AccountHash::from_public_key(&public_key, |x| self.blake2b(x));

        if !self.is_allowed_session_caller(&provided_account_hash) {
            return Err(Error::InvalidContext);
        }

        let mut bid = self
            .read_bid(&provided_account_hash)?
            .ok_or(Error::ValidatorNotFound)?;

        let era_end_timestamp_millis = detail::get_era_end_timestamp_millis(self)?;

        // Fails if requested amount is greater than either the total stake or the amount of vested
        // stake.
        let updated_stake = bid.decrease_stake(amount, era_end_timestamp_millis)?;

        detail::create_unbonding_purse(
            self,
            public_key.clone(),
            public_key.clone(), // validator is the unbonder
            *bid.bonding_purse(),
            amount,
        )?;

        if updated_stake.is_zero() {
            // Automatically unbond delegators
            for (delegator_public_key, delegator) in bid.delegators() {
                detail::create_unbonding_purse(
                    self,
                    public_key.clone(),
                    delegator_public_key.clone(),
                    *delegator.bonding_purse(),
                    *delegator.staked_amount(),
                )?;
            }

            *bid.delegators_mut() = BTreeMap::new();

            bid.deactivate();
        }

        self.write_bid(provided_account_hash, bid)?;

        Ok(updated_stake)
    }
/// For a non-founder validator, this method simply decreases a stake.
///
/// For a founding validator, this function first checks whether they are released and fails if
/// they are not.
///
/// When a validator's stake reaches 0 all the delegators that bid their tokens to it are
/// automatically unbonded with their total staked amount and the bid is deactivated. A bid can
/// be activated again by staking tokens.
///
/// You can't withdraw higher amount than its currently staked. Withdrawing zero is allowed,
/// although it does not change the state of the auction.
///
/// The function returns the new amount of motes remaining in the bid. If the target bid does
/// not exist, the function call returns an error.
For a non-founder validator, this method simply decreases a stake.
For a founding validator, this function first checks whether they are released and fails if
they are not.

When a validator's stake reaches 0 all the delegators that bid their tokens to it are
automatically unbonded with their total staked amount and the bid is deactivated. A bid can
be activated again by staking tokens.

You can't withdraw higher amount than its currently staked. Withdrawing zero is allowed,
although it does not change the state of the auction.

The function returns the new amount of motes remaining in the bid. If the target bid does
not exist, the function call returns an error.
For a non - founder validator this method simply decreases a stake . For a founding validator this function first checks whether they are released and fails if they are not . When a validator ' s stake reaches 0 all the delegators that bid their tokens to it are automatically unbonded with their total staked amount and the bid is deactivated . A bid can be activated again by staking tokens . You can ' t withdraw higher amount than its currently staked . Withdrawing zero is allowed although it does not change the state of the auction . The function returns the new amount of motes remaining in the bid . If the target bid does not exist the function call returns an error .
fn withdraw_bid(&mut self, public_key: PublicKey, amount: U512) -> Result<U512, Error> {
        let provided_account_hash = AccountHash::from_public_key(&public_key, |x| self.blake2b(x));
        if !self.is_allowed_session_caller(&provided_account_hash) {
            return Err(Error::InvalidContext);
        }
        let mut bid = self
            .read_bid(&provided_account_hash)?
            .ok_or(Error::ValidatorNotFound)?;
        let era_end_timestamp_millis = detail::get_era_end_timestamp_millis(self)?;
        // Fails if requested amount is greater than either the total stake or the amount of vested
        // stake.
        let updated_stake = bid.decrease_stake(amount, era_end_timestamp_millis)?;
        detail::create_unbonding_purse(
            self,
            public_key.clone(),
            public_key.clone(), // validator is the unbonder
            *bid.bonding_purse(),
            amount,
        )?;
        if updated_stake.is_zero() {
            // Automatically unbond delegators
            for (delegator_public_key, delegator) in bid.delegators() {
                detail::create_unbonding_purse(
                    self,
                    public_key.clone(),
                    delegator_public_key.clone(),
                    *delegator.bonding_purse(),
                    *delegator.staked_amount(),
                )?;
            }
            *bid.delegators_mut() = BTreeMap::new();
            bid.deactivate();
        }
        self.write_bid(provided_account_hash, bid)?;
        Ok(updated_stake)
    }
fn withdraw_bid ( & mut self , public_key : PublicKey , amount : U512 ) -> Result < U512 , Error > { let provided_account_hash = AccountHash :: from_public_key ( & public_key , | x | self . blake2b ( x ) ) ; if ! self . is_allowed_session_caller ( & provided_account_hash ) { return Err ( Error :: InvalidContext ) ; } let mut bid = self . read_bid ( & provided_account_hash ) ? . ok_or ( Error :: ValidatorNotFound ) ? ; let era_end_timestamp_millis = detail :: get_era_end_timestamp_millis ( self ) ? ; // Fails if requested amount is greater than either the total stake or the amount of vested // stake. let updated_stake = bid . decrease_stake ( amount , era_end_timestamp_millis ) ? ; detail :: create_unbonding_purse ( self , public_key . clone ( ) , public_key . clone ( ) , // validator is the unbonder * bid . bonding_purse ( ) , amount , ) ? ; if updated_stake . is_zero ( ) { // Automatically unbond delegators for ( delegator_public_key , delegator ) in bid . delegators ( ) { detail :: create_unbonding_purse ( self , public_key . clone ( ) , delegator_public_key . clone ( ) , * delegator . bonding_purse ( ) , * delegator . staked_amount ( ) , ) ? ; } * bid . delegators_mut ( ) = BTreeMap :: new ( ) ; bid . deactivate ( ) ; } self . write_bid ( provided_account_hash , bid ) ? ; Ok ( updated_stake ) }
For a non-founder validator, this method simply decreases a stake.
For a non - founder validator this method simply decreases a stake .
&mut self
public_key
PublicKey
amount
U512
&mut self
public_key
PublicKey
amount
U512