pub fn debit_allowance(
        &mut self,
        owner: &TokenHolder,
        spender: &TokenHolder,
        value: Nat,
    ) -> CommonResult<()> {
        // get spenders allowance
        let spender_allowance = self._allowance(owner, spender);
        // check allowance
        if spender_allowance < value {
            return Err(DFTError::InsufficientAllowance);
        }
        let new_spender_allowance = spender_allowance - value.clone();
        match self.allowances.get(&owner) {
            Some(inner) => {
                let mut temp = inner.clone();
                if value == 0 {
                    temp.remove(&spender);
                    if temp.len() > 0 {
                        self.allowances.insert(owner.clone(), temp);
                    } else {
                        self.allowances.remove(&owner);
                    }
                } else {
                    temp.insert(spender.clone(), new_spender_allowance);
                    self.allowances.insert(owner.clone(), temp);
                }
            }
            None => {
                if value.gt(&Nat::from(0)) {
                    let mut inner = HashMap::new();
                    inner.insert(spender.clone(), new_spender_allowance);
                    self.allowances.insert(owner.clone(), inner);
                }
            }
        };
        Ok(())
    }
//debit token holder's allowance
debit token holder's allowance
debit token holder ' s allowance
pub fn debit_allowance(
        &mut self,
        owner: &TokenHolder,
        spender: &TokenHolder,
        value: Nat,
    ) -> CommonResult<()> {
        // get spenders allowance
        let spender_allowance = self._allowance(owner, spender);
        // check allowance
        if spender_allowance < value {
            return Err(DFTError::InsufficientAllowance);
        }
        let new_spender_allowance = spender_allowance - value.clone();
        match self.allowances.get(&owner) {
            Some(inner) => {
                let mut temp = inner.clone();
                if value == 0 {
                    temp.remove(&spender);
                    if temp.len() > 0 {
                        self.allowances.insert(owner.clone(), temp);
                    } else {
                        self.allowances.remove(&owner);
                    }
                } else {
                    temp.insert(spender.clone(), new_spender_allowance);
                    self.allowances.insert(owner.clone(), temp);
                }
            }
            None => {
                if value.gt(&Nat::from(0)) {
                    let mut inner = HashMap::new();
                    inner.insert(spender.clone(), new_spender_allowance);
                    self.allowances.insert(owner.clone(), inner);
                }
            }
        };
        Ok(())
    }
pub fn debit_allowance ( & mut self , owner : & TokenHolder , spender : & TokenHolder , value : Nat , ) -> CommonResult < ( ) > { // get spenders allowance let spender_allowance = self . _allowance ( owner , spender ) ; // check allowance if spender_allowance < value { return Err ( DFTError :: InsufficientAllowance ) ; } let new_spender_allowance = spender_allowance - value . clone ( ) ; match self . allowances . get ( & owner ) { Some ( inner ) => { let mut temp = inner . clone ( ) ; if value == 0 { temp . remove ( & spender ) ; if temp . len ( ) > 0 { self . allowances . insert ( owner . clone ( ) , temp ) ; } else { self . allowances . remove ( & owner ) ; } } else { temp . insert ( spender . clone ( ) , new_spender_allowance ) ; self . allowances . insert ( owner . clone ( ) , temp ) ; } } None => { if value . gt ( & Nat :: from ( 0 ) ) { let mut inner = HashMap :: new ( ) ; inner . insert ( spender . clone ( ) , new_spender_allowance ) ; self . allowances . insert ( owner . clone ( ) , inner ) ; } } } ; Ok ( ( ) ) }
debit token holder's allowance
debit token holder ' s allowance
&mut self
owner
&TokenHolder
spender
&TokenHolder
value
Nat
&mut self
owner
&TokenHolder
spender
&TokenHolder
value
Nat