resolveBalanceIDs resolves source and destination to actual balance IDs. If the source or destination starts with "@", it indicates a balance indicator (like @world) that needs to be resolved to an actual balance ID. This function creates the balance if needed. This should be called BEFORE acquiring
(ctx context.Context, transaction *model.Transaction)
| 222 | // - destinationBalanceID string: The resolved destination balance ID. |
| 223 | // - error: An error if the balance IDs could not be resolved. |
| 224 | func (l *LedgerForge) resolveBalanceIDs(ctx context.Context, transaction *model.Transaction) (string, string, error) { |
| 225 | ctx, span := tracer.Start(ctx, "ResolveBalanceIDs") |
| 226 | defer span.End() |
| 227 | |
| 228 | sourceID := transaction.Source |
| 229 | destID := transaction.Destination |
| 230 | |
| 231 | // Resolve source if it's an indicator (starts with "@") |
| 232 | if strings.HasPrefix(transaction.Source, "@") { |
| 233 | sourceBalance, err := l.getOrCreateBalanceByIndicator(ctx, transaction.Source, transaction.Currency) |
| 234 | if err != nil { |
| 235 | span.RecordError(err) |
| 236 | return "", "", fmt.Errorf("failed to resolve source balance indicator: %w", err) |
| 237 | } |
| 238 | sourceID = sourceBalance.BalanceID |
| 239 | span.SetAttributes(attribute.String("source.resolved_id", sourceID)) |
| 240 | } |
| 241 | |
| 242 | // Resolve destination if it's an indicator (starts with "@") |
| 243 | if strings.HasPrefix(transaction.Destination, "@") { |
| 244 | destBalance, err := l.getOrCreateBalanceByIndicator(ctx, transaction.Destination, transaction.Currency) |
| 245 | if err != nil { |
| 246 | span.RecordError(err) |
| 247 | return "", "", fmt.Errorf("failed to resolve destination balance indicator: %w", err) |
| 248 | } |
| 249 | destID = destBalance.BalanceID |
| 250 | span.SetAttributes(attribute.String("destination.resolved_id", destID)) |
| 251 | } |
| 252 | |
| 253 | span.AddEvent("Balance IDs resolved") |
| 254 | return sourceID, destID, nil |
| 255 | } |
| 256 | |
| 257 | // acquireLock acquires distributed locks for a transaction to ensure exclusive access to both |
| 258 | // source and destination balances. It uses a MultiLocker with deterministic ordering to prevent |
no test coverage detected