forked from mito-systems/sol-mem-gen
Check if signature exists before writing to DB
This commit is contained in:
parent
77f38148f1
commit
3514c04c25
@ -56,7 +56,7 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
)
|
||||
}
|
||||
|
||||
await markSignatureAsUsed(transactionSignature)
|
||||
await markSignatureAsUsed(transactionSignature);
|
||||
|
||||
console.log('Generating with Flux model:', modelId)
|
||||
console.log('Prompt:', prompt)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
import { Payment } from './entity/Payment';
|
||||
|
||||
export const AppDataSource = new DataSource({
|
||||
|
@ -3,6 +3,7 @@ import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
||||
|
||||
import { AppDataSource } from '../data-source';
|
||||
import { Payment } from '../entity/Payment';
|
||||
import { getManager } from 'typeorm';
|
||||
|
||||
const SOLANA_RPC_URL = process.env.NEXT_PUBLIC_SOLANA_RPC_URL;
|
||||
const SOLANA_WEBSOCKET_URL = process.env.NEXT_PUBLIC_SOLANA_WEBSOCKET_URL;
|
||||
@ -26,10 +27,18 @@ export async function isSignatureUsed(transactionSignature: string): Promise<boo
|
||||
}
|
||||
|
||||
export async function markSignatureAsUsed(transactionSignature: string): Promise<void> {
|
||||
const paymentRepository = AppDataSource.getRepository(Payment);
|
||||
const payment = new Payment();
|
||||
payment.transactionSignature = transactionSignature;
|
||||
await paymentRepository.save(payment);
|
||||
await AppDataSource.transaction(async (transactionalEntityManager) => {
|
||||
const paymentRepository = transactionalEntityManager.getRepository(Payment);
|
||||
|
||||
// Check if the payment with the given signature already exists
|
||||
const exists = await paymentRepository.exists({ where: { transactionSignature } });
|
||||
|
||||
// If not, create a new payment entry
|
||||
if (!exists) {
|
||||
const newPayment = paymentRepository.create({ transactionSignature });
|
||||
await paymentRepository.save(newPayment);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function verifyPayment(
|
||||
|
Loading…
Reference in New Issue
Block a user