AccountSub() removes tokens from an Account
(address crypto.AddressI, amountToSub uint64)
| 145 | |
| 146 | // AccountSub() removes tokens from an Account |
| 147 | func (s *StateMachine) AccountSub(address crypto.AddressI, amountToSub uint64) lib.ErrorI { |
| 148 | // ensure no unnecessary database updates |
| 149 | if amountToSub == 0 { |
| 150 | return nil |
| 151 | } |
| 152 | // get the account from the state |
| 153 | account, err := s.GetAccount(address) |
| 154 | if err != nil { |
| 155 | return err |
| 156 | } |
| 157 | // if the account amount is less than the amount to subtract; return insufficient funds |
| 158 | if account.Amount < amountToSub { |
| 159 | return ErrInsufficientFunds() |
| 160 | } |
| 161 | // subtract from the account amount |
| 162 | account.Amount -= amountToSub |
| 163 | // set the account in state |
| 164 | return s.SetAccount(account) |
| 165 | } |
| 166 | |
| 167 | // maybeFaucetTopUpForSendTx mints just-enough tokens to cover `required` when the sender is configured as a faucet. |
| 168 | // Faucet mode is disabled when config.faucetAddress is empty or omitted. |