processBalances processes the source and destination balances by applying the transaction in-memory. It starts a tracing span, applies the transaction to the balances, and records relevant events and errors. Note: The actual database update of balances is done atomically with the transaction persist
(ctx context.Context, transaction *model.Transaction, sourceBalance, destinationBalance *model.Balance)
| 1241 | // Returns: |
| 1242 | // - error: An error if the transaction could not be applied to the balances. |
| 1243 | func (l *LedgerForge) processBalances(ctx context.Context, transaction *model.Transaction, sourceBalance, destinationBalance *model.Balance) error { |
| 1244 | ctx, span := tracer.Start(ctx, "ProcessBalances") |
| 1245 | defer span.End() |
| 1246 | |
| 1247 | // Apply the transaction to the source and destination balances (in-memory only) |
| 1248 | if err := l.applyTransactionToBalances(ctx, []*model.Balance{sourceBalance, destinationBalance}, transaction); err != nil { |
| 1249 | span.RecordError(err) |
| 1250 | return l.logAndRecordError(span, "failed to apply transaction to balances", err) |
| 1251 | } |
| 1252 | |
| 1253 | span.AddEvent("Balances calculated") |
| 1254 | return nil |
| 1255 | } |
| 1256 | |
| 1257 | // buildTransactionExecutionWork converts an in-memory-applied transaction into the shared |
| 1258 | // persistence and post-commit work shape used by both single and batched execution paths. |
no test coverage detected