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

Method CreateBalance

balance.go:231–244  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

229// - model.Balance: The created Balance model.
230// - error: An error if the balance could not be created.
231func (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.

Callers 3

TestCreateBalanceFunction · 0.95

Calls 3

postBalanceActionsMethod · 0.95
CreateBalanceMethod · 0.65
StartMethod · 0.45

Tested by 2

TestCreateBalanceFunction · 0.76