MCPcopy
hub / github.com/canopy-network/canopy / AccountSub

Method AccountSub

fsm/account.go:147–165  ·  view source on GitHub ↗

AccountSub() removes tokens from an Account

(address crypto.AddressI, amountToSub uint64)

Source from the content-addressed store, hash-verified

145
146// AccountSub() removes tokens from an Account
147func (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.

Callers 11

AccountDeductFeesMethod · 0.95
HandleMessageSendMethod · 0.95
HandleMessageStakeMethod · 0.95
HandleMessageSubsidyMethod · 0.95
TestAccountSubFunction · 0.80

Calls 3

GetAccountMethod · 0.95
SetAccountMethod · 0.95
ErrInsufficientFundsFunction · 0.70

Tested by 2

TestAccountSubFunction · 0.64