CreateBalance creates a new balance. It starts a tracing span, creates the balance, and performs post-creation actions. Parameters: - ctx context.Context: The context for the operation. - balance model.Balance: The Balance model to be created. Returns: - model.Balance: The created Balance model. -
(ctx context.Context, balance model.Balance)
| 229 | // - model.Balance: The created Balance model. |
| 230 | // - error: An error if the balance could not be created. |
| 231 | func (l *LedgerForge) CreateBalance(ctx context.Context, balance model.Balance) (model.Balance, error) { |
| 232 | ctx, span := balanceTracer.Start(ctx, "CreateBalance") |
| 233 | defer span.End() |
| 234 | |
| 235 | balance, err := l.datasource.CreateBalance(balance) |
| 236 | if err != nil { |
| 237 | span.RecordError(err) |
| 238 | return model.Balance{}, err |
| 239 | } |
| 240 | l.postBalanceActions(ctx, &balance) |
| 241 | metrics.BalanceCreatedTotal.Add(ctx, 1) |
| 242 | span.AddEvent("Balance created", trace.WithAttributes(attribute.String("balance.id", balance.BalanceID))) |
| 243 | return balance, nil |
| 244 | } |
| 245 | |
| 246 | // GetBalanceByID retrieves a balance by its ID. |
| 247 | // It starts a tracing span, fetches the balance, and records relevant events. |