| 1520 | } |
| 1521 | |
| 1522 | func (l *LedgerForge) validateQueuedBatchTransactionReference(ctx context.Context, transaction *model.Transaction, prefetchedReferences, existingReferences, batchReferences map[string]struct{}) error { |
| 1523 | if transaction == nil { |
| 1524 | return fmt.Errorf("nil transaction") |
| 1525 | } |
| 1526 | |
| 1527 | if transaction.Reference == "" { |
| 1528 | return fmt.Errorf("reference is required") |
| 1529 | } |
| 1530 | |
| 1531 | if _, ok := batchReferences[transaction.Reference]; ok { |
| 1532 | return fmt.Errorf("reference %s has already been used", transaction.Reference) |
| 1533 | } |
| 1534 | |
| 1535 | if _, ok := existingReferences[transaction.Reference]; ok { |
| 1536 | return fmt.Errorf("reference %s has already been used", transaction.Reference) |
| 1537 | } |
| 1538 | |
| 1539 | if len(prefetchedReferences) == 0 { |
| 1540 | if err := l.validateTxn(ctx, transaction); err != nil { |
| 1541 | return err |
| 1542 | } |
| 1543 | batchReferences[transaction.Reference] = struct{}{} |
| 1544 | return nil |
| 1545 | } |
| 1546 | |
| 1547 | // Fall back to the single-reference validation path only if the transaction's |
| 1548 | // current reference was not part of the prefetched batch reference set. |
| 1549 | if _, ok := prefetchedReferences[transaction.Reference]; !ok { |
| 1550 | if err := l.validateTxn(ctx, transaction); err != nil { |
| 1551 | return err |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | batchReferences[transaction.Reference] = struct{}{} |
| 1556 | return nil |
| 1557 | } |
| 1558 | |
| 1559 | func (l *LedgerForge) batchReferenceCheckEnabled() bool { |
| 1560 | return !l.Config().Transaction.DisableBatchReferenceCheck |