Skip to content

Commit

Permalink
chore: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jan 18, 2024
1 parent ddbe70d commit 09ae1fb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
18 changes: 9 additions & 9 deletions handle_multi_pay_invoice_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()),
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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()),
Expand All @@ -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
Expand All @@ -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,
},
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 09ae1fb

Please sign in to comment.