applyTransactionToBalances applies a transaction to the provided balances. It starts a tracing span, calculates new balances, and updates the balances based on the transaction status. Parameters: - ctx context.Context: The context for the operation. - balances []*model.Balance: A slice of Balance m
(ctx context.Context, balances []*model.Balance, transaction *model.Transaction)
| 410 | // Returns: |
| 411 | // - error: An error if the balances could not be updated. |
| 412 | func (l *LedgerForge) applyTransactionToBalances(ctx context.Context, balances []*model.Balance, transaction *model.Transaction) error { |
| 413 | _, span := tracer.Start(ctx, "Applying Transaction to Balances") |
| 414 | defer span.End() |
| 415 | |
| 416 | span.AddEvent("Calculating new balances") |
| 417 | |
| 418 | // Handle committed inflight transactions |
| 419 | if transaction.Status == StatusCommit { |
| 420 | balances[0].CommitInflightDebit(transaction) |
| 421 | balances[1].CommitInflightCredit(transaction) |
| 422 | span.AddEvent("Committed inflight balances") |
| 423 | return nil |
| 424 | } |
| 425 | |
| 426 | transactionAmount := transaction.PreciseAmount |
| 427 | |
| 428 | // Handle voided transactions |
| 429 | if transaction.Status == StatusVoid { |
| 430 | balances[0].RollbackInflightDebit(transactionAmount) |
| 431 | balances[1].RollbackInflightCredit(transactionAmount) |
| 432 | span.AddEvent("Rolled back inflight balances") |
| 433 | return nil |
| 434 | } |
| 435 | |
| 436 | // Update balances for other transaction statuses |
| 437 | err := model.UpdateBalances(transaction, balances[0], balances[1]) |
| 438 | if err != nil { |
| 439 | span.RecordError(err) |
| 440 | return err |
| 441 | } |
| 442 | |
| 443 | span.AddEvent("Balances updated") |
| 444 | return nil |
| 445 | } |
| 446 | |
| 447 | // GetRefundableTransactionsByParentID retrieves refundable transactions by their parent transaction ID. |
| 448 | // It starts a tracing span, fetches the transactions from the datasource, and records relevant events and errors. |
no test coverage detected