From b1a43fe38b01da7664d311c115e99aeced35b0ca Mon Sep 17 00:00:00 2001 From: im-adithya Date: Thu, 18 Jan 2024 15:40:01 +0530 Subject: [PATCH] chore: DRY up dtag usage --- handle_multi_pay_invoice_request.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/handle_multi_pay_invoice_request.go b/handle_multi_pay_invoice_request.go index 21c4ec2c..4a865415 100644 --- a/handle_multi_pay_invoice_request.go +++ b/handle_multi_pay_invoice_request.go @@ -77,12 +77,19 @@ func (svc *Service) HandleMultiPayInvoiceEvent(ctx context.Context, sub *nostr.S }).Errorf("Failed to process event: %v", err) return } + // TODO: Decide what to do if id is empty 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 } + id := invoiceInfo.Id + if id == "" { + id = paymentRequest.PaymentHash + } + dTag := []string{"a", fmt.Sprintf("%d:%s:%s", NIP_47_RESPONSE_KIND, event.PubKey, id)} + hasPermission, code, message := svc.hasPermission(&app, event, request.Method, paymentRequest.MSatoshi) if !hasPermission { @@ -108,7 +115,6 @@ 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:%s", NIP_47_RESPONSE_KIND, event.PubKey, invoiceInfo.Id)} resp.Tags = append(resp.Tags, dTag) svc.PublishEvent(ctx, sub, event, resp) return @@ -161,7 +167,6 @@ 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:%s", NIP_47_RESPONSE_KIND, event.PubKey, invoiceInfo.Id)} resp.Tags = append(resp.Tags, dTag) svc.PublishEvent(ctx, sub, event, resp) return @@ -186,7 +191,6 @@ 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:%s", NIP_47_RESPONSE_KIND, event.PubKey, invoiceInfo.Id)} resp.Tags = append(resp.Tags, dTag) svc.PublishEvent(ctx, sub, event, resp) }(invoiceInfo)