Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multi pay invoice method #218

Closed
wants to merge 13 commits into from
19 changes: 13 additions & 6 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ func (svc *Service) handleAndPublishEvent(ctx context.Context, sub *nostr.Subscr
}).Errorf("Failed to process event: %v", err)
return
}

// TODO: consider move event publishing to individual methods - multi_* methods are
// inconsistent with single methods because they publish multiple responses
switch nip47Request.Method {
case NIP_47_MULTI_PAY_INVOICE_METHOD:
svc.HandleMultiPayInvoiceEvent(ctx, sub, nip47Request, event, app, ss)
Expand All @@ -233,12 +236,7 @@ func (svc *Service) handleAndPublishEvent(ctx context.Context, sub *nostr.Subscr
case NIP_47_GET_INFO_METHOD:
resp, err = svc.HandleGetInfoEvent(ctx, nip47Request, event, app, ss)
default:
resp, err = svc.createResponse(event, Nip47Response{
ResultType: nip47Request.Method,
Error: &Nip47Error{
Code: NIP_47_ERROR_NOT_IMPLEMENTED,
Message: fmt.Sprintf("Unknown method: %s", nip47Request.Method),
}}, nostr.Tags{}, ss)
resp, err = svc.handleUnknownMethod(ctx, nip47Request, event, app, ss)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

}

if err != nil {
Expand All @@ -252,6 +250,15 @@ func (svc *Service) handleAndPublishEvent(ctx context.Context, sub *nostr.Subscr
}
}

func (svc *Service) handleUnknownMethod(ctx context.Context, request *Nip47Request, event *nostr.Event, app App, ss []byte) (result *nostr.Event, err error) {
return svc.createResponse(event, Nip47Response{
ResultType: request.Method,
Error: &Nip47Error{
Code: NIP_47_ERROR_NOT_IMPLEMENTED,
Message: fmt.Sprintf("Unknown method: %s", request.Method),
}}, nostr.Tags{}, ss)
}

func (svc *Service) createResponse(initialEvent *nostr.Event, content interface{}, tags nostr.Tags, ss []byte) (result *nostr.Event, err error) {
payloadBytes, err := json.Marshal(content)
if err != nil {
Expand Down
Loading