diff --git a/notifications/notification_service.go b/notifications/notification_service.go index 8dd50cc..7151e3c 100644 --- a/notifications/notification_service.go +++ b/notifications/notification_service.go @@ -70,6 +70,8 @@ func (s *NotificationService) Notify( return false, err } + log.Printf("Notifying %d registrations for %s", len(registrations), pubkey) + req := &PaymentReceivedPayload{ Template: "payment_received", Data: struct { @@ -100,6 +102,7 @@ func (s *NotificationService) Notify( wg.Wait() cancel() + log.Printf("finished notifying %s with result: %v", pubkey, notified) if notified { s.mtx.Lock() s.recentNotifications[paymentIdentifier(pubkey, paymenthash)] = time.Now() @@ -123,11 +126,11 @@ func (s *NotificationService) notifyOnce(ctx context.Context, req *PaymentReceiv return false } - if resp.StatusCode != 200 { + if resp.StatusCode/100 != 2 { buf := make([]byte, 1000) bytesRead, _ := io.ReadFull(resp.Body, buf) respBody := buf[:bytesRead] - log.Printf("Got non 200 status code (%s) for payment notification for %s to %s: %s", resp.Status, pubkey, url, respBody) + log.Printf("Got non successfull status code (%s) for payment notification for %s to %s: %s", resp.Status, pubkey, url, respBody) // TODO: Remove subscription? return false } diff --git a/notifications/server.go b/notifications/server.go index 7c3766b..59e40d3 100644 --- a/notifications/server.go +++ b/notifications/server.go @@ -36,18 +36,34 @@ func (s *server) SubscribeNotifications( data, err := ecies.Decrypt(node.EciesPrivateKey, in.Blob) if err != nil { + log.Printf( + "failed to register for notifications: ecies.Decrypt error: %v", + err, + ) return nil, fmt.Errorf("ecies.Decrypt(%x) error: %w", in.Blob, err) } var request SubscribeNotificationsRequest err = proto.Unmarshal(data, &request) if err != nil { - log.Printf("proto.Unmarshal(%x) error: %v", data, err) + log.Printf( + "failed to register for notifications on url %v: proto.Unmarshal(%x) error: %v", + request.Url, + data, + err, + ) return nil, fmt.Errorf("proto.Unmarshal(%x) error: %w", data, err) } pubkey, err := lightning.VerifyMessage([]byte(request.Url), request.Signature) if err != nil { + log.Printf( + "failed to register %x for notifications on url %s: lightning.VerifyMessage error: %v", + pubkey.SerializeCompressed(), + request.Url, + err, + ) + return nil, err } @@ -63,5 +79,6 @@ func (s *server) SubscribeNotifications( return nil, ErrInternal } + log.Printf("%v was successfully registered for notifications on url %s", pubkey, request.Url) return &SubscribeNotificationsReply{}, nil }