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

Method TransactionExistsByRef

database/transaction.go:479–504  ·  view source on GitHub ↗

TransactionExistsByRef checks if a transaction with a given reference exists in the database. It uses OpenTelemetry to trace the operation and returns a boolean indicating whether the transaction exists. Parameters: - ctx: Context for managing the request and tracing. - reference: The reference of t

(ctx context.Context, reference string)

Source from the content-addressed store, hash-verified

477// Returns:
478// - A boolean indicating whether the transaction exists, or an error if the check fails.
479func (d Datasource) TransactionExistsByRef(ctx context.Context, reference string) (bool, error) {
480 // Start a new tracing span for the database operation
481 ctx, span := otel.Tracer("transaction.database").Start(ctx, "TransactionExistsByRef")
482 defer span.End()
483
484 // Variable to store whether the transaction exists
485 var exists bool
486
487 // Execute the SQL query to check if the transaction exists by reference
488 err := d.Conn.QueryRowContext(ctx, `
489 SELECT EXISTS(SELECT 1 FROM ledgerforge.transactions WHERE reference = $1)
490 `, reference).Scan(&exists)
491 // Handle errors from the query
492 if err != nil {
493 span.RecordError(err)
494 return false, apierror.NewAPIError(apierror.ErrInternalServer, "Failed to check if transaction exists", err)
495 }
496
497 // Log the transaction existence result in the tracing span
498 span.AddEvent("Transaction existence check", trace.WithAttributes(
499 attribute.String("transaction.reference", reference),
500 attribute.Bool("transaction.exists", exists),
501 ))
502
503 return exists, nil
504}
505
506// GetExistingTransactionReferences retrieves the subset of the provided references that already
507// exist in the database. It returns an empty set when the input is empty.

Calls 2

NewAPIErrorFunction · 0.92
StartMethod · 0.45