diff --git a/cmd/server/main.go b/cmd/server/main.go index fbc05a2..a91aba6 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -57,7 +57,7 @@ func main() { }() //handle graceful shutdown <-svc.Ctx.Done() - svc.Logger.Infof("Shutting down echo server...") + svc.Logger.Info("Shutting down echo server...") ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() e.Shutdown(ctx) diff --git a/internal/nostr/nostr.go b/internal/nostr/nostr.go index f823774..f1e1f93 100644 --- a/internal/nostr/nostr.go +++ b/internal/nostr/nostr.go @@ -181,7 +181,7 @@ func (svc *Service) InfoHandler(c echo.Context) error { svc.Logger.WithFields(logrus.Fields{ "relay_url": requestData.RelayUrl, "wallet_pubkey": requestData.WalletPubkey, - }).Info("Subscribing to info event") + }).Debug("Subscribing to info event") filter := nostr.Filter{ Authors: []string{requestData.WalletPubkey}, @@ -205,7 +205,7 @@ func (svc *Service) InfoHandler(c echo.Context) error { svc.Logger.WithFields(logrus.Fields{ "relay_url": requestData.RelayUrl, "wallet_pubkey": requestData.WalletPubkey, - }).Info("Exiting info subscription without receiving") + }).Error("Exiting info subscription without receiving event") return c.JSON(http.StatusRequestTimeout, ErrorResponse{ Message: "Request canceled or timed out", Error: ctx.Err().Error(), @@ -261,7 +261,7 @@ func (svc *Service) PublishHandler(c echo.Context) error { svc.Logger.WithFields(logrus.Fields{ "event_id": requestData.SignedEvent.ID, "relay_url": requestData.RelayUrl, - }).Info("Publishing event") + }).Debug("Publishing event") err = relay.Publish(ctx, *requestData.SignedEvent) if err != nil { @@ -277,7 +277,7 @@ func (svc *Service) PublishHandler(c echo.Context) error { } svc.Logger.WithFields(logrus.Fields{ - "request_event_id": requestData.SignedEvent.ID, + "event_id": requestData.SignedEvent.ID, "relay_url": requestData.RelayUrl, }).Info("Published event") @@ -353,7 +353,7 @@ func (svc *Service) NIP47Handler(c echo.Context) error { ctx, cancel := context.WithTimeout(c.Request().Context(), 90*time.Second) defer cancel() - go svc.startSubscription(ctx, &subscription, svc.publishEvent, svc.handleResponseEvent) + go svc.startSubscription(ctx, &subscription, svc.publishRequestEvent, svc.handleResponseEvent) select { case <-ctx.Done(): @@ -452,7 +452,7 @@ func (svc *Service) NIP47WebhookHandler(c echo.Context) error { ctx, cancel := context.WithTimeout(svc.Ctx, 90*time.Second) defer cancel() - go svc.startSubscription(ctx, &subscription, svc.publishEvent, svc.handleResponseEvent) + go svc.startSubscription(ctx, &subscription, svc.publishRequestEvent, svc.handleResponseEvent) return c.JSON(http.StatusOK, NIP47Response{ State: WEBHOOK_RECEIVED, }) @@ -510,7 +510,7 @@ func (svc *Service) NIP47NotificationHandler(c echo.Context) error { "wallet_pubkey": requestData.WalletPubkey, "relay_url": requestData.RelayUrl, "webhook_url": requestData.WebhookUrl, - }).Info("Subscribing to notifications") + }).Debug("Subscribing to notifications") subscription := Subscription{ RelayUrl: requestData.RelayUrl, @@ -647,7 +647,7 @@ func (svc *Service) StopSubscriptionHandler(c echo.Context) error { svc.Logger.WithFields(logrus.Fields{ "subscription_id": subscription.ID, - }).Debug("Stopped subscription") + }).Info("Stopped subscription") return c.JSON(http.StatusOK, StopSubscriptionResponse{ Message: "Subscription stopped successfully", @@ -674,6 +674,7 @@ func (svc *Service) stopSubscription(subscription *Subscription) error { func (svc *Service) startSubscription(ctx context.Context, subscription *Subscription, onReceiveEOS OnReceiveEOSFunc, handleEvent HandleEventFunc) { svc.Logger.WithFields(logrus.Fields{ "subscription_id": subscription.ID, + "relay_url": subscription.RelayUrl, "wallet_pubkey": svc.getWalletPubkey(subscription.Authors), }).Debug("Starting subscription") @@ -720,6 +721,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri svc.Logger.WithFields(logrus.Fields{ "subscription_id": subscription.ID, + "relay_url": subscription.RelayUrl, "wallet_pubkey": svc.getWalletPubkey(subscription.Authors), }).Debug("Started subscription") @@ -758,7 +760,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri } } -func (svc *Service) publishEvent(ctx context.Context, subscription *Subscription) { +func (svc *Service) publishRequestEvent(ctx context.Context, subscription *Subscription) { svc.subscriptionsMutex.Lock() sub := svc.subscriptions[subscription.Uuid] svc.subscriptionsMutex.Unlock() @@ -766,16 +768,16 @@ func (svc *Service) publishEvent(ctx context.Context, subscription *Subscription if err != nil { // TODO: notify user about publish failure svc.Logger.WithError(err).WithFields(logrus.Fields{ - "subscription_id": subscription.ID, - "relay_url": subscription.RelayUrl, - "wallet_pubkey": svc.getWalletPubkey(subscription.Authors), + "request_event_id": subscription.RequestEvent.ID, + "relay_url": subscription.RelayUrl, + "wallet_pubkey": svc.getWalletPubkey(subscription.Authors), }).Error("Failed to publish to relay") sub.Unsub() } else { svc.Logger.WithFields(logrus.Fields{ - "publish_status": REQUEST_EVENT_PUBLISH_CONFIRMED, - "event_id": subscription.RequestEvent.ID, - "wallet_pubkey": svc.getWalletPubkey(subscription.Authors), + "request_event_id": subscription.RequestEvent.ID, + "relay_url": subscription.RelayUrl, + "wallet_pubkey": svc.getWalletPubkey(subscription.Authors), }).Info("Published request event successfully") subscription.RequestEventDB.State = REQUEST_EVENT_PUBLISH_CONFIRMED } @@ -811,7 +813,8 @@ func (svc *Service) handleSubscribedEvent(event *nostr.Event, subscription *Subs "event_kind": event.Kind, "subscription_id": subscription.ID, "wallet_pubkey": svc.getWalletPubkey(subscription.Authors), - }).Info("Received event") + "relay_url": subscription.RelayUrl, + }).Info("Received subscribed event") responseEvent := ResponseEvent{ NostrId: event.ID, Content: event.Content, @@ -833,6 +836,7 @@ func (svc *Service) processEvents(ctx context.Context, subscription *Subscriptio svc.Logger.WithFields(logrus.Fields{ "subscription_id": subscription.ID, "wallet_pubkey": svc.getWalletPubkey(subscription.Authors), + "relay_url": subscription.RelayUrl, }).Debug("Received EOS") if (onReceiveEOS != nil) { @@ -847,6 +851,7 @@ func (svc *Service) processEvents(ctx context.Context, subscription *Subscriptio svc.Logger.WithFields(logrus.Fields{ "subscription_id": subscription.ID, "wallet_pubkey": svc.getWalletPubkey(subscription.Authors), + "relay_url": subscription.RelayUrl, }).Debug("Relay subscription events channel ended") }() @@ -864,7 +869,7 @@ func (svc *Service) getRelayConnection(ctx context.Context, customRelayURL strin if customRelayURL != "" && customRelayURL != svc.Cfg.DefaultRelayURL { svc.Logger.WithFields(logrus.Fields{ "custom_relay_url": customRelayURL, - }).Infof("Connecting to custom relay") + }).Info("Connecting to custom relay") relay, err := nostr.RelayConnect(ctx, customRelayURL) return relay, true, err // true means custom and the relay should be closed } @@ -909,7 +914,7 @@ func (svc *Service) postEventToWebhook(event *nostr.Event, webhookURL string) { "event_id": event.ID, "event_kind": event.Kind, "webhook_url": webhookURL, - }).Infof("Successfully posted event to webhook") + }).Info("Successfully posted event to webhook") } func (svc *Service) subscriptionToFilter(subscription *Subscription) (*nostr.Filter){