fn flush(&mut self) -> Result<(), ApiError> {
        let trans_err = |msg| {
            let msg = format!("Bad transaction: {}", msg);
            let err = ApiError::InvalidTransaction(false, msg.into());
            Err(err)
        };

        if self.cr.is_none() && self.db.is_none() && self.fee.is_none() {
            return Ok(());
        }

        // If you're preprocessing just continue with the default fee
        if self.preprocessing && self.fee.is_none() && self.db.is_some() {
            self.fee = Some((TRANSACTION_FEE, self.db.unwrap().1))
        }

        if self.cr.is_none() || self.db.is_none() || self.fee.is_none() {
            return trans_err(
                "Operations do not combine to make a recognizable transaction".to_string(),
            );
        }
        let (cr_amount, mut to) = self.cr.take().unwrap();
        let (db_amount, mut from) = self.db.take().unwrap();
        let (fee_amount, fee_acc) = self.fee.take().unwrap();

        if fee_acc != from {
            if cr_amount == Tokens::ZERO && fee_acc == to {
                std::mem::swap(&mut from, &mut to);
            } else {
                let msg = format!("Fee should be taken from {}", from);
                return trans_err(msg);
            }
        }
        if cr_amount != db_amount {
            return trans_err("Debit_amount should be equal -credit_amount".to_string());
        }

        self.actions
            .push(Request::Transfer(LedgerOperation::Transfer {
                from,
                to,
                amount: cr_amount,
                fee: fee_amount,
            }));

        Ok(())
    }
/// Create a `Transfer` from the credit/debit/fee operations seen
/// previously.
Create a `Transfer` from the credit/debit/fee operations seen
previously.
Create a ` Transfer ` from the credit / debit / fee operations seen previously .
fn flush(&mut self) -> Result<(), ApiError> {
        let trans_err = |msg| {
            let msg = format!("Bad transaction: {}", msg);
            let err = ApiError::InvalidTransaction(false, msg.into());
            Err(err)
        };
        if self.cr.is_none() && self.db.is_none() && self.fee.is_none() {
            return Ok(());
        }
        // If you're preprocessing just continue with the default fee
        if self.preprocessing && self.fee.is_none() && self.db.is_some() {
            self.fee = Some((TRANSACTION_FEE, self.db.unwrap().1))
        }
        if self.cr.is_none() || self.db.is_none() || self.fee.is_none() {
            return trans_err(
                "Operations do not combine to make a recognizable transaction".to_string(),
            );
        }
        let (cr_amount, mut to) = self.cr.take().unwrap();
        let (db_amount, mut from) = self.db.take().unwrap();
        let (fee_amount, fee_acc) = self.fee.take().unwrap();
        if fee_acc != from {
            if cr_amount == Tokens::ZERO && fee_acc == to {
                std::mem::swap(&mut from, &mut to);
            } else {
                let msg = format!("Fee should be taken from {}", from);
                return trans_err(msg);
            }
        }
        if cr_amount != db_amount {
            return trans_err("Debit_amount should be equal -credit_amount".to_string());
        }
        self.actions
            .push(Request::Transfer(LedgerOperation::Transfer {
                from,
                to,
                amount: cr_amount,
                fee: fee_amount,
            }));
        Ok(())
    }
fn flush ( & mut self ) -> Result < ( ) , ApiError > { let trans_err = | msg | { let msg = format ! ( " " msg ) ; let err = ApiError :: InvalidTransaction ( false , msg . into ( ) ) ; Err ( err ) } ; if self . cr . is_none ( ) && self . db . is_none ( ) && self . fee . is_none ( ) { return Ok ( ( ) ) ; } // If you're preprocessing just continue with the default fee if self . preprocessing && self . fee . is_none ( ) && self . db . is_some ( ) { self . fee = Some ( ( TRANSACTION_FEE , self . db . unwrap ( ) . 1 ) ) } if self . cr . is_none ( ) || self . db . is_none ( ) || self . fee . is_none ( ) { return trans_err ( " " . to_string ( ) , ) ; } let ( cr_amount , mut to ) = self . cr . take ( ) . unwrap ( ) ; let ( db_amount , mut from ) = self . db . take ( ) . unwrap ( ) ; let ( fee_amount , fee_acc ) = self . fee . take ( ) . unwrap ( ) ; if fee_acc != from { if cr_amount == Tokens :: ZERO && fee_acc == to { std :: mem :: swap ( & mut from , & mut to ) ; } else { let msg = format ! ( " " from ) ; return trans_err ( msg ) ; } } if cr_amount != db_amount { return trans_err ( " " . to_string ( ) ) ; } self . actions . push ( Request :: Transfer ( LedgerOperation :: Transfer { from , to , amount : cr_amount , fee : fee_amount , } ) ) ; Ok ( ( ) ) }
Create a `Transfer` from the credit/debit/fee operations seen
previously.
Create a ` Transfer ` from the credit / debit / fee operations seen previously .
&mut self
&mut self