From 09ae1fbbe8f738d47623822836607126991c1e01 Mon Sep 17 00:00:00 2001 From: im-adithya Date: Thu, 18 Jan 2024 12:29:08 +0530 Subject: [PATCH] chore: refactoring --- handle_multi_pay_invoice_request.go | 18 +++++++++--------- models.go | 8 ++++---- service.go | 1 - 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/handle_multi_pay_invoice_request.go b/handle_multi_pay_invoice_request.go index b3a9c1c3..21c4ec2c 100644 --- a/handle_multi_pay_invoice_request.go +++ b/handle_multi_pay_invoice_request.go @@ -47,7 +47,7 @@ func (svc *Service) HandleMultiPayInvoiceEvent(ctx context.Context, sub *nostr.S var wg sync.WaitGroup for _, invoiceInfo := range multiPayParams.Invoices { wg.Add(1) - go func(invoiceInfo InvoiceInfo) { + go func(invoiceInfo Nip47MultiPayInvoiceElement) { defer wg.Done() bolt11 := invoiceInfo.Invoice // Convert invoice to lowercase string @@ -62,7 +62,7 @@ func (svc *Service) HandleMultiPayInvoiceEvent(ctx context.Context, sub *nostr.S }).Errorf("Failed to decode bolt11 invoice: %v", err) resp, err := svc.createResponse(event, Nip47Response{ - ResultType: NIP_47_PAY_INVOICE_METHOD, + ResultType: NIP_47_MULTI_PAY_INVOICE_METHOD, Error: &Nip47Error{ Code: NIP_47_ERROR_INTERNAL, Message: fmt.Sprintf("Failed to decode bolt11 invoice: %s", err.Error()), @@ -77,7 +77,7 @@ func (svc *Service) HandleMultiPayInvoiceEvent(ctx context.Context, sub *nostr.S }).Errorf("Failed to process event: %v", err) return } - dTag := []string{"a", fmt.Sprintf("%d:%s:%d", NIP_47_RESPONSE_KIND, event.PubKey, invoiceInfo.Id)} + dTag := []string{"a", fmt.Sprintf("%d:%s:%s", NIP_47_RESPONSE_KIND, event.PubKey, invoiceInfo.Id)} resp.Tags = append(resp.Tags, dTag) svc.PublishEvent(ctx, sub, event, resp) return @@ -93,7 +93,7 @@ func (svc *Service) HandleMultiPayInvoiceEvent(ctx context.Context, sub *nostr.S }).Errorf("App does not have permission: %s %s", code, message) resp, err := svc.createResponse(event, Nip47Response{ - ResultType: NIP_47_PAY_INVOICE_METHOD, + ResultType: NIP_47_MULTI_PAY_INVOICE_METHOD, Error: &Nip47Error{ Code: code, Message: message, @@ -108,7 +108,7 @@ func (svc *Service) HandleMultiPayInvoiceEvent(ctx context.Context, sub *nostr.S }).Errorf("Failed to process event: %v", err) return } - dTag := []string{"a", fmt.Sprintf("%d:%s:%d", NIP_47_RESPONSE_KIND, event.PubKey, invoiceInfo.Id)} + dTag := []string{"a", fmt.Sprintf("%d:%s:%s", NIP_47_RESPONSE_KIND, event.PubKey, invoiceInfo.Id)} resp.Tags = append(resp.Tags, dTag) svc.PublishEvent(ctx, sub, event, resp) return @@ -146,7 +146,7 @@ func (svc *Service) HandleMultiPayInvoiceEvent(ctx context.Context, sub *nostr.S svc.db.Save(&nostrEvent) resp, err := svc.createResponse(event, Nip47Response{ - ResultType: NIP_47_PAY_INVOICE_METHOD, + ResultType: NIP_47_MULTI_PAY_INVOICE_METHOD, Error: &Nip47Error{ Code: NIP_47_ERROR_INTERNAL, Message: fmt.Sprintf("Something went wrong while paying invoice: %s", err.Error()), @@ -161,7 +161,7 @@ func (svc *Service) HandleMultiPayInvoiceEvent(ctx context.Context, sub *nostr.S }).Errorf("Failed to process event: %v", err) return } - dTag := []string{"a", fmt.Sprintf("%d:%s:%d", NIP_47_RESPONSE_KIND, event.PubKey, invoiceInfo.Id)} + dTag := []string{"a", fmt.Sprintf("%d:%s:%s", NIP_47_RESPONSE_KIND, event.PubKey, invoiceInfo.Id)} resp.Tags = append(resp.Tags, dTag) svc.PublishEvent(ctx, sub, event, resp) return @@ -172,7 +172,7 @@ func (svc *Service) HandleMultiPayInvoiceEvent(ctx context.Context, sub *nostr.S svc.db.Save(&nostrEvent) svc.db.Save(&payment) resp, err := svc.createResponse(event, Nip47Response{ - ResultType: NIP_47_PAY_INVOICE_METHOD, + ResultType: NIP_47_MULTI_PAY_INVOICE_METHOD, Result: Nip47PayResponse{ Preimage: preimage, }, @@ -186,7 +186,7 @@ func (svc *Service) HandleMultiPayInvoiceEvent(ctx context.Context, sub *nostr.S }).Errorf("Failed to process event: %v", err) return } - dTag := []string{"a", fmt.Sprintf("%d:%s:%d", NIP_47_RESPONSE_KIND, event.PubKey, invoiceInfo.Id)} + dTag := []string{"a", fmt.Sprintf("%d:%s:%s", NIP_47_RESPONSE_KIND, event.PubKey, invoiceInfo.Id)} resp.Tags = append(resp.Tags, dTag) svc.PublishEvent(ctx, sub, event, resp) }(invoiceInfo) diff --git a/models.go b/models.go index 65d73600..12b014a4 100644 --- a/models.go +++ b/models.go @@ -253,12 +253,12 @@ type Nip47PayResponse struct { } type Nip47MultiPayParams struct { - Invoices []InvoiceInfo `json:"invoices"` + Invoices []Nip47MultiPayInvoiceElement `json:"invoices"` } -type InvoiceInfo struct { - Id uint64 `json:"id"` - Invoice string `json:"invoice"` +type Nip47MultiPayInvoiceElement struct { + Nip47PayParams + Id string `json:"id"` } type Nip47MultiPayResponse struct { diff --git a/service.go b/service.go index 2d9b96e7..7dc2ed89 100644 --- a/service.go +++ b/service.go @@ -232,7 +232,6 @@ func (svc *Service) handleAndPublishEvent(ctx context.Context, sub *nostr.Subscr resp, err = svc.HandleListTransactionsEvent(ctx, nip47Request, event, app, ss) case NIP_47_GET_INFO_METHOD: resp, err = svc.HandleGetInfoEvent(ctx, nip47Request, event, app, ss) - // multi methods default: resp, err = svc.createResponse(event, Nip47Response{ ResultType: nip47Request.Method,