MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / CommitInflightCredit

Method CommitInflightCredit

model/model.go:199–211  ·  view source on GitHub ↗

CommitInflightCredit commits a credit from the inflight balance and adds it to the credit balance.

(transaction *Transaction)

Source from the content-addressed store, hash-verified

197
198// CommitInflightCredit commits a credit from the inflight balance and adds it to the credit balance.
199func (balance *Balance) CommitInflightCredit(transaction *Transaction) {
200 balance.InitializeBalanceFields()
201 preciseAmount := ApplyPrecision(transaction)
202 transactionAmount := preciseAmount
203
204 if balance.InflightCreditBalance.Cmp(transactionAmount) >= 0 {
205 // Deduct from inflight and add to regular credit balance.
206 balance.InflightCreditBalance.Sub(balance.InflightCreditBalance, transactionAmount)
207 balance.CreditBalance.Add(balance.CreditBalance, transactionAmount)
208 balance.computeBalance(true) // Recompute inflight balance.
209 balance.computeBalance(false) // Recompute regular balance.
210 }
211}
212
213// RollbackInflightCredit rolls back (decreases) the inflight credit balance by the specified amount.
214func (balance *Balance) RollbackInflightCredit(amount *big.Int) {

Callers 2

Calls 3

computeBalanceMethod · 0.95
ApplyPrecisionFunction · 0.85

Tested by 1