GetOutboxByTransactionID retrieves an outbox entry by its transaction ID.
(ctx context.Context, transactionID string)
| 380 | |
| 381 | // GetOutboxByTransactionID retrieves an outbox entry by its transaction ID. |
| 382 | func (d Datasource) GetOutboxByTransactionID(ctx context.Context, transactionID string) (*model.LineageOutbox, error) { |
| 383 | row := d.Conn.QueryRowContext(ctx, ` |
| 384 | SELECT id, transaction_id, source_balance_id, destination_balance_id, provider, lineage_type, payload, status, attempts, max_attempts, last_error, created_at, processed_at, locked_until, inflight |
| 385 | FROM ledgerforge.lineage_outbox |
| 386 | WHERE transaction_id = $1 |
| 387 | `, transactionID) |
| 388 | |
| 389 | var entry model.LineageOutbox |
| 390 | var sourceBalanceID, destinationBalanceID, provider, lastError sql.NullString |
| 391 | var processedAt, lockedUntil sql.NullTime |
| 392 | |
| 393 | err := row.Scan( |
| 394 | &entry.ID, |
| 395 | &entry.TransactionID, |
| 396 | &sourceBalanceID, |
| 397 | &destinationBalanceID, |
| 398 | &provider, |
| 399 | &entry.LineageType, |
| 400 | &entry.Payload, |
| 401 | &entry.Status, |
| 402 | &entry.Attempts, |
| 403 | &entry.MaxAttempts, |
| 404 | &lastError, |
| 405 | &entry.CreatedAt, |
| 406 | &processedAt, |
| 407 | &lockedUntil, |
| 408 | &entry.Inflight, |
| 409 | ) |
| 410 | if err != nil { |
| 411 | if err == sql.ErrNoRows { |
| 412 | return nil, nil |
| 413 | } |
| 414 | return nil, apierror.NewAPIError(apierror.ErrInternalServer, "Failed to retrieve outbox entry", err) |
| 415 | } |
| 416 | |
| 417 | entry.SourceBalanceID = sourceBalanceID.String |
| 418 | entry.DestinationBalanceID = destinationBalanceID.String |
| 419 | entry.Provider = provider.String |
| 420 | entry.LastError = lastError.String |
| 421 | if processedAt.Valid { |
| 422 | entry.ProcessedAt = &processedAt.Time |
| 423 | } |
| 424 | if lockedUntil.Valid { |
| 425 | entry.LockedUntil = &lockedUntil.Time |
| 426 | } |
| 427 | |
| 428 | return &entry, nil |
| 429 | } |
| 430 | |
| 431 | // HasPendingCreditOutbox checks if there are pending credit outbox entries for a given balance. |
| 432 | // This is used to detect race conditions where a debit is being processed before credits are complete. |
nothing calls this directly
no test coverage detected