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

Method getOriginalTransactionForRefund

transaction.go:2254–2283  ·  view source on GitHub ↗

getOriginalTransactionForRefund retrieves the original transaction to be refunded, checking both the database and the queue if necessary.

(ctx context.Context, transactionID string)

Source from the content-addressed store, hash-verified

2252// getOriginalTransactionForRefund retrieves the original transaction to be refunded,
2253// checking both the database and the queue if necessary.
2254func (l *LedgerForge) getOriginalTransactionForRefund(ctx context.Context, transactionID string) (*model.Transaction, error) {
2255 ctx, span := tracer.Start(ctx, "getOriginalTransactionForRefund")
2256 defer span.End()
2257
2258 originalTxn, err := l.datasource.GetTransaction(ctx, transactionID)
2259 if err != nil {
2260 // Check if the error is due to no row found
2261 if errors.Is(err, sql.ErrNoRows) || strings.Contains(err.Error(), fmt.Sprintf("Transaction with ID '%s' not found", transactionID)) {
2262 // Check the queue for the transaction
2263 queuedTxn, queueErr := l.queue.GetTransactionFromQueue(transactionID)
2264 if queueErr != nil {
2265 span.RecordError(queueErr)
2266 // Return the original DB error if queue retrieval also fails
2267 return nil, fmt.Errorf("transaction %s not found in DB or queue: %w", transactionID, err)
2268 }
2269 if queuedTxn == nil {
2270 err := fmt.Errorf("transaction %s not found in DB or queue", transactionID)
2271 span.RecordError(err)
2272 return nil, err
2273 }
2274 span.AddEvent("Transaction found in queue", trace.WithAttributes(attribute.String("transaction.id", transactionID)))
2275 return queuedTxn, nil // Return the transaction found in the queue
2276 }
2277 // Return other database errors directly
2278 span.RecordError(err)
2279 return nil, fmt.Errorf("failed to get transaction %s from DB: %w", transactionID, err)
2280 }
2281 span.AddEvent("Transaction found in DB", trace.WithAttributes(attribute.String("transaction.id", transactionID)))
2282 return originalTxn, nil
2283}
2284
2285// validateTransactionForRefund checks if the given transaction is eligible for a refund.
2286func (l *LedgerForge) validateTransactionForRefund(ctx context.Context, originalTxn *model.Transaction) error {

Callers 1

RefundTransactionMethod · 0.95

Calls 4

GetTransactionMethod · 0.65
StartMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected