From 83f4bfb110ce0d9f03b113507e040a9725cc3fe7 Mon Sep 17 00:00:00 2001 From: anarkrypto Date: Tue, 22 Oct 2024 06:50:16 -0300 Subject: [PATCH] fix: writes the pay address index to the db --- src/invoice/invoice-repository.ts | 3 +++ src/invoice/invoice-service.ts | 3 ++- src/invoice/invoices-schema.ts | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/invoice/invoice-repository.ts b/src/invoice/invoice-repository.ts index 100678a..c3a03c5 100644 --- a/src/invoice/invoice-repository.ts +++ b/src/invoice/invoice-repository.ts @@ -65,6 +65,7 @@ export class InvoiceSupabaseRepository implements InvoiceRepository { redirect_url, expires_at, pay_address, + index, }: z.infer) { invoiceCreateSchema.parse({ title, @@ -76,6 +77,7 @@ export class InvoiceSupabaseRepository implements InvoiceRepository { redirect_url, expires_at, pay_address, + index, }); const id = generateInvoiceId(); @@ -94,6 +96,7 @@ export class InvoiceSupabaseRepository implements InvoiceRepository { service_id, redirect_url, pay_address, + index, }) .select( ` diff --git a/src/invoice/invoice-service.ts b/src/invoice/invoice-service.ts index 117b3c2..87e734d 100644 --- a/src/invoice/invoice-service.ts +++ b/src/invoice/invoice-service.ts @@ -32,7 +32,7 @@ export class InvoiceService { const expires_at = new Date(Date.now() + INVOICE_EXPIRATION).toISOString(); invoiceCreateSchema - .omit({ pay_address: true }) + .omit({ pay_address: true, index: true }) .parse({ title, description, metadata, price, recipient_address, service_id, redirect_url, expires_at }); const minIndex = 1000; // Initially we used a sequential index in the first 1000 invoices, feel free to change this value @@ -56,6 +56,7 @@ export class InvoiceService { service_id, redirect_url, pay_address, + index: randomIndex, }); logger.info(`New Invoice Created: ${invoice.id}`, { diff --git a/src/invoice/invoices-schema.ts b/src/invoice/invoices-schema.ts index cc969d8..3bc15a3 100644 --- a/src/invoice/invoices-schema.ts +++ b/src/invoice/invoices-schema.ts @@ -12,5 +12,9 @@ export const invoiceCreateSchema = z service_id: z.string(), expires_at: z.string(), pay_address: z.string().regex(/^nano_[13456789abcdefghijkmnopqrstuwxyz]{60}$/), + index: z + .number() + .min(0) + .max(Math.pow(2, 32) - 1), }) .strict();