fn redeem_stake_for_account(
        &mut self,
        account: &mut RegisteredAccount,
        amount: domain::YoctoStake,
    ) -> BatchId {
        assert!(amount.value() > 0, ZERO_REDEEM_AMOUNT);

        self.claim_receipt_funds(account);

        assert!(
            account.can_redeem(amount),
            INSUFFICIENT_STAKE_FOR_REDEEM_REQUEST
        );

        // debit the amount of STAKE to redeem from the account
        let mut stake = account.stake.expect("account has zero STAKE token balance");
        if stake.debit(amount).value() > 0 {
            account.stake = Some(stake);
        } else {
            account.stake = None;
        }

        match self.redeem_stake_batch_lock {
            // use current batch
            None => {
                // apply at contract level
                let mut contract_batch = self
                    .redeem_stake_batch
                    .unwrap_or_else(|| self.new_redeem_stake_batch());
                contract_batch.add(amount);
                self.redeem_stake_batch = Some(contract_batch);

                // apply at account level
                // NOTE: account batch ID must match contract batch ID
                let mut account_batch = account
                    .redeem_stake_batch
                    .unwrap_or_else(|| contract_batch.id().new_redeem_stake_batch());
                account_batch.add(amount);
                account.redeem_stake_batch = Some(account_batch);

                account_batch.id().into()
            }
            // use next batch
            _ => {
                // apply at contract level
                let mut contract_batch = self
                    .next_redeem_stake_batch
                    .unwrap_or_else(|| self.new_redeem_stake_batch());
                contract_batch.add(amount);
                self.next_redeem_stake_batch = Some(contract_batch);

                // apply at account level
                // NOTE: account batch ID must match contract batch ID
                let mut account_batch = account
                    .next_redeem_stake_batch
                    .unwrap_or_else(|| contract_batch.id().new_redeem_stake_batch());
                account_batch.add(amount);
                account.next_redeem_stake_batch = Some(account_batch);

                account_batch.id().into()
            }
        }
    }
/// moves STAKE [amount] from account balance to redeem stake batch
///
/// ## Panics
/// - if amount == 0
/// - if STAKE account balance is too low to fulfill request
///
/// ## Notes
/// - before applying the deposit, batch receipts are processed [claim_receipt_funds]
moves STAKE [amount] from account balance to redeem stake batch
moves STAKE [ amount ] from account balance to redeem stake batch
fn redeem_stake_for_account(
        &mut self,
        account: &mut RegisteredAccount,
        amount: domain::YoctoStake,
    ) -> BatchId {
        assert!(amount.value() > 0, ZERO_REDEEM_AMOUNT);
        self.claim_receipt_funds(account);
        assert!(
            account.can_redeem(amount),
            INSUFFICIENT_STAKE_FOR_REDEEM_REQUEST
        );
        // debit the amount of STAKE to redeem from the account
        let mut stake = account.stake.expect("account has zero STAKE token balance");
        if stake.debit(amount).value() > 0 {
            account.stake = Some(stake);
        } else {
            account.stake = None;
        }
        match self.redeem_stake_batch_lock {
            // use current batch
            None => {
                // apply at contract level
                let mut contract_batch = self
                    .redeem_stake_batch
                    .unwrap_or_else(|| self.new_redeem_stake_batch());
                contract_batch.add(amount);
                self.redeem_stake_batch = Some(contract_batch);
                // apply at account level
                // NOTE: account batch ID must match contract batch ID
                let mut account_batch = account
                    .redeem_stake_batch
                    .unwrap_or_else(|| contract_batch.id().new_redeem_stake_batch());
                account_batch.add(amount);
                account.redeem_stake_batch = Some(account_batch);
                account_batch.id().into()
            }
            // use next batch
            _ => {
                // apply at contract level
                let mut contract_batch = self
                    .next_redeem_stake_batch
                    .unwrap_or_else(|| self.new_redeem_stake_batch());
                contract_batch.add(amount);
                self.next_redeem_stake_batch = Some(contract_batch);
                // apply at account level
                // NOTE: account batch ID must match contract batch ID
                let mut account_batch = account
                    .next_redeem_stake_batch
                    .unwrap_or_else(|| contract_batch.id().new_redeem_stake_batch());
                account_batch.add(amount);
                account.next_redeem_stake_batch = Some(account_batch);
                account_batch.id().into()
            }
        }
    }
fn redeem_stake_for_account ( & mut self , account : & mut RegisteredAccount , amount : domain :: YoctoStake , ) -> BatchId { assert ! ( amount value ( ) 0 ZERO_REDEEM_AMOUNT ) ; self . claim_receipt_funds ( account ) ; assert ! ( account can_redeem ( amount ) INSUFFICIENT_STAKE_FOR_REDEEM_REQUEST ) ; // debit the amount of STAKE to redeem from the account let mut stake = account . stake . expect ( " " ) ; if stake . debit ( amount ) . value ( ) > 0 { account . stake = Some ( stake ) ; } else { account . stake = None ; } match self . redeem_stake_batch_lock { // use current batch None => { // apply at contract level let mut contract_batch = self . redeem_stake_batch . unwrap_or_else ( | | self . new_redeem_stake_batch ( ) ) ; contract_batch . add ( amount ) ; self . redeem_stake_batch = Some ( contract_batch ) ; // apply at account level // NOTE: account batch ID must match contract batch ID let mut account_batch = account . redeem_stake_batch . unwrap_or_else ( | | contract_batch . id ( ) . new_redeem_stake_batch ( ) ) ; account_batch . add ( amount ) ; account . redeem_stake_batch = Some ( account_batch ) ; account_batch . id ( ) . into ( ) } // use next batch _ => { // apply at contract level let mut contract_batch = self . next_redeem_stake_batch . unwrap_or_else ( | | self . new_redeem_stake_batch ( ) ) ; contract_batch . add ( amount ) ; self . next_redeem_stake_batch = Some ( contract_batch ) ; // apply at account level // NOTE: account batch ID must match contract batch ID let mut account_batch = account . next_redeem_stake_batch . unwrap_or_else ( | | contract_batch . id ( ) . new_redeem_stake_batch ( ) ) ; account_batch . add ( amount ) ; account . next_redeem_stake_batch = Some ( account_batch ) ; account_batch . id ( ) . into ( ) } } }
moves STAKE [amount] from account balance to redeem stake batch
moves STAKE [ amount ] from account balance to redeem stake batch
&mut self
account
&mut RegisteredAccount
amount
domain::YoctoStake
panics
if amount == 0
if STAKE account balance is too low to fulfill request
if amount == 0 if STAKE account balance is too low to fulfill request
notes
before applying the deposit, batch receipts are processed [claim_receipt_funds]
before applying the deposit batch receipts are processed [ claim_receipt_funds ]