Skip to content

Commit

Permalink
fix: writes the pay address index to the db
Browse files Browse the repository at this point in the history
  • Loading branch information
anarkrypto committed Oct 22, 2024
1 parent 7e48f31 commit 83f4bfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/invoice/invoice-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class InvoiceSupabaseRepository implements InvoiceRepository {
redirect_url,
expires_at,
pay_address,
index,
}: z.infer<typeof invoiceCreateSchema>) {
invoiceCreateSchema.parse({
title,
Expand All @@ -76,6 +77,7 @@ export class InvoiceSupabaseRepository implements InvoiceRepository {
redirect_url,
expires_at,
pay_address,
index,
});

const id = generateInvoiceId();
Expand All @@ -94,6 +96,7 @@ export class InvoiceSupabaseRepository implements InvoiceRepository {
service_id,
redirect_url,
pay_address,
index,
})
.select(
`
Expand Down
3 changes: 2 additions & 1 deletion src/invoice/invoice-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,6 +56,7 @@ export class InvoiceService {
service_id,
redirect_url,
pay_address,
index: randomIndex,
});

logger.info(`New Invoice Created: ${invoice.id}`, {
Expand Down
4 changes: 4 additions & 0 deletions src/invoice/invoices-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 83f4bfb

Please sign in to comment.