MCPcopy Index your code
hub / github.com/devaccuracy/ledgerforge / processBalances

Method processBalances

transaction.go:1243–1255  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1241// Returns:
1242// - error: An error if the transaction could not be applied to the balances.
1243func (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.

Callers 2

Calls 3

logAndRecordErrorMethod · 0.95
StartMethod · 0.45

Tested by

no test coverage detected