From df667872577529d1bfebcc754bbe2e624cd719f5 Mon Sep 17 00:00:00 2001 From: im-adithya Date: Thu, 19 Dec 2024 22:53:11 +0530 Subject: [PATCH 1/5] chore: improve logging --- internal/nostr/nostr.go | 98 ++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/internal/nostr/nostr.go b/internal/nostr/nostr.go index a7eed77..ac8b639 100644 --- a/internal/nostr/nostr.go +++ b/internal/nostr/nostr.go @@ -215,7 +215,7 @@ func (svc *Service) InfoHandler(c echo.Context) error { select { case <-ctx.Done(): - svc.Logger.WithFields(logrus.Fields{ + svc.Logger.WithError(ctx.Err()).WithFields(logrus.Fields{ "relay_url": requestData.RelayUrl, "wallet_pubkey": requestData.WalletPubkey, }).Error("Exiting info subscription without receiving event") @@ -227,7 +227,7 @@ func (svc *Service) InfoHandler(c echo.Context) error { svc.Logger.WithFields(logrus.Fields{ "relay_url": requestData.RelayUrl, "wallet_pubkey": requestData.WalletPubkey, - "event_id": event.ID, + "info_event_id": event.ID, }).Info("Received info event") sub.Unsub() return c.JSON(http.StatusOK, InfoResponse{ @@ -370,7 +370,7 @@ func (svc *Service) NIP47Handler(c echo.Context) error { select { case <-ctx.Done(): - svc.Logger.WithFields(logrus.Fields{ + svc.Logger.WithError(ctx.Err()).WithFields(logrus.Fields{ "request_event_id": requestData.SignedEvent.ID, "client_pubkey": requestData.SignedEvent.PubKey, "wallet_pubkey": requestData.WalletPubkey, @@ -472,14 +472,14 @@ func (svc *Service) NIP47WebhookHandler(c echo.Context) error { defer cancel() select { case <-ctx.Done(): - svc.Logger.WithFields(logrus.Fields{ + svc.Logger.WithError(ctx.Err()).WithFields(logrus.Fields{ "request_event_id": requestData.SignedEvent.ID, "client_pubkey": requestData.SignedEvent.PubKey, "wallet_pubkey": requestData.WalletPubkey, "relay_url": requestData.RelayUrl, }).Error("Stopped subscription without receiving event") case event := <-subscription.EventChan: - svc.postEventToWebhook(event, subscription.WebhookUrl) + svc.postEventToWebhook(event, &subscription) } }() @@ -490,17 +490,17 @@ func (svc *Service) NIP47WebhookHandler(c echo.Context) error { func (svc *Service) prepareNIP47Subscription(relayUrl, walletPubkey, webhookUrl string, requestEvent RequestEvent) (Subscription) { return Subscription{ - RelayUrl: relayUrl, - WebhookUrl: webhookUrl, - Open: true, - Authors: &[]string{walletPubkey}, - Kinds: &[]int{NIP_47_RESPONSE_KIND}, - Tags: &nostr.TagMap{"e": []string{requestEvent.NostrId}}, - Since: time.Now(), - Limit: 1, - RequestEvent: &requestEvent, - EventChan: make(chan *nostr.Event, 1), - Uuid: uuid.New().String(), + RelayUrl: relayUrl, + WebhookUrl: webhookUrl, + Open: true, + Authors: &[]string{walletPubkey}, + Kinds: &[]int{NIP_47_RESPONSE_KIND}, + Tags: &nostr.TagMap{"e": []string{requestEvent.NostrId}}, + Since: time.Now(), + Limit: 1, + RequestEvent: &requestEvent, + EventChan: make(chan *nostr.Event, 1), + Uuid: uuid.New().String(), } } @@ -655,13 +655,13 @@ func (svc *Service) StopSubscriptionHandler(c echo.Context) error { } svc.Logger.WithFields(logrus.Fields{ - "subscription_id": subscription.ID, + "subscription_id": subscription.Uuid, }).Debug("Stopping subscription") err := svc.stopSubscription(&subscription) if err != nil { svc.Logger.WithFields(logrus.Fields{ - "subscription_id": subscription.ID, + "subscription_id": subscription.Uuid, }).Debug("Subscription is stopped already") return c.JSON(http.StatusAlreadyReported, StopSubscriptionResponse{ @@ -675,7 +675,7 @@ func (svc *Service) StopSubscriptionHandler(c echo.Context) error { // delete svix app svc.Logger.WithFields(logrus.Fields{ - "subscription_id": subscription.ID, + "subscription_id": subscription.Uuid, }).Info("Stopped subscription") return c.JSON(http.StatusOK, StopSubscriptionResponse{ @@ -702,7 +702,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, + "subscription_id": subscription.Uuid, "relay_url": subscription.RelayUrl, }).Debug("Starting subscription") @@ -719,8 +719,8 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri relay.Close() } if ctx.Err() != nil { - svc.Logger.WithFields(logrus.Fields{ - "subscription_id": subscription.ID, + svc.Logger.WithError(ctx.Err()).WithFields(logrus.Fields{ + "subscription_id": subscription.Uuid, "relay_url": subscription.RelayUrl, }).Debug("Context canceled, stopping subscription") svc.stopSubscription(subscription) @@ -733,7 +733,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri waitToReconnectSeconds = max(waitToReconnectSeconds, 1) waitToReconnectSeconds = min(waitToReconnectSeconds * 2, 900) svc.Logger.WithError(err).WithFields(logrus.Fields{ - "subscription_id": subscription.ID, + "subscription_id": subscription.Uuid, "relay_url": subscription.RelayUrl, }).Errorf("Failed to connect to relay, retrying in %vs...", waitToReconnectSeconds) continue @@ -745,7 +745,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri waitToReconnectSeconds = max(waitToReconnectSeconds, 1) waitToReconnectSeconds = min(waitToReconnectSeconds * 2, 900) svc.Logger.WithError(err).WithFields(logrus.Fields{ - "subscription_id": subscription.ID, + "subscription_id": subscription.Uuid, "relay_url": subscription.RelayUrl, }).Errorf("Failed to subscribe to relay, retrying in %vs...", waitToReconnectSeconds) continue @@ -756,7 +756,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri svc.subscriptionsMutex.Unlock() svc.Logger.WithFields(logrus.Fields{ - "subscription_id": subscription.ID, + "subscription_id": subscription.Uuid, "relay_url": subscription.RelayUrl, }).Debug("Started subscription") @@ -767,7 +767,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri if err != nil { // TODO: notify user about subscription failure svc.Logger.WithError(err).WithFields(logrus.Fields{ - "subscription_id": subscription.ID, + "subscription_id": subscription.Uuid, "relay_url": subscription.RelayUrl, }).Error("Subscription stopped due to relay error, reconnecting...") continue @@ -778,7 +778,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri // stop the subscription if it's an NIP47 request if (subscription.RequestEvent != nil) { svc.Logger.WithFields(logrus.Fields{ - "subscription_id": subscription.ID, + "subscription_id": subscription.Uuid, "relay_url": subscription.RelayUrl, }).Debug("Stopping subscription") svc.stopSubscription(subscription) @@ -844,10 +844,10 @@ func (svc *Service) handleResponseEvent(event *nostr.Event, subscription *Subscr func (svc *Service) handleSubscribedEvent(event *nostr.Event, subscription *Subscription) { svc.Logger.WithFields(logrus.Fields{ - "event_id": event.ID, - "event_kind": event.Kind, - "subscription_id": subscription.ID, - "relay_url": subscription.RelayUrl, + "response_event_id": event.ID, + "response_event_kind": event.Kind, + "subscription_id": subscription.Uuid, + "relay_url": subscription.RelayUrl, }).Info("Received subscribed event") responseEvent := ResponseEvent{ NostrId: event.ID, @@ -856,7 +856,7 @@ func (svc *Service) handleSubscribedEvent(event *nostr.Event, subscription *Subs SubscriptionId: &subscription.ID, } svc.db.Save(&responseEvent) - svc.postEventToWebhook(event, subscription.WebhookUrl) + svc.postEventToWebhook(event, subscription) } func (svc *Service) processEvents(ctx context.Context, subscription *Subscription, onReceiveEOS OnReceiveEOSFunc, handleEvent HandleEventFunc) error { @@ -868,7 +868,7 @@ func (svc *Service) processEvents(ctx context.Context, subscription *Subscriptio // block till EOS is received <-sub.EndOfStoredEvents svc.Logger.WithFields(logrus.Fields{ - "subscription_id": subscription.ID, + "subscription_id": subscription.Uuid, "relay_url": subscription.RelayUrl, }).Debug("Received EOS") @@ -882,7 +882,7 @@ func (svc *Service) processEvents(ctx context.Context, subscription *Subscriptio } svc.Logger.WithFields(logrus.Fields{ - "subscription_id": subscription.ID, + "subscription_id": subscription.Uuid, "relay_url": subscription.RelayUrl, }).Debug("Relay subscription events channel ended") }() @@ -921,32 +921,40 @@ func (svc *Service) getRelayConnection(ctx context.Context, customRelayURL strin } } -func (svc *Service) postEventToWebhook(event *nostr.Event, webhookURL string) { +func (svc *Service) postEventToWebhook(event *nostr.Event, subscription *Subscription) { eventData, err := json.Marshal(event) + request_event_id := "" + if subscription.RequestEvent != nil { + request_event_id = subscription.RequestEvent.NostrId + } + if err != nil { svc.Logger.WithError(err).WithFields(logrus.Fields{ - "event_id": event.ID, - "event_kind": event.Kind, - "webhook_url": webhookURL, + "request_event_id": request_event_id, + "response_event_id": event.ID, + "response_event_kind": event.Kind, + "webhook_url": subscription.WebhookUrl, }).Error("Failed to marshal event for webhook") return } // TODO: add svix functionality - _, err = http.Post(webhookURL, "application/json", bytes.NewBuffer(eventData)) + _, err = http.Post(subscription.WebhookUrl, "application/json", bytes.NewBuffer(eventData)) if err != nil { svc.Logger.WithError(err).WithFields(logrus.Fields{ - "event_id": event.ID, - "event_kind": event.Kind, - "webhook_url": webhookURL, + "request_event_id": request_event_id, + "response_event_id": event.ID, + "response_event_kind": event.Kind, + "webhook_url": subscription.WebhookUrl, }).Error("Failed to post event to webhook") return } svc.Logger.WithFields(logrus.Fields{ - "event_id": event.ID, - "event_kind": event.Kind, - "webhook_url": webhookURL, + "request_event_id": request_event_id, + "response_event_id": event.ID, + "response_event_kind": event.Kind, + "webhook_url": subscription.WebhookUrl, }).Info("Posted event to webhook") } From de2d5c55821a11506b8209c28e0323ca14da0a37 Mon Sep 17 00:00:00 2001 From: im-adithya Date: Thu, 19 Dec 2024 23:40:36 +0530 Subject: [PATCH 2/5] chore: add subscription uuid to logs --- internal/nostr/nostr.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/nostr/nostr.go b/internal/nostr/nostr.go index ac8b639..944ff01 100644 --- a/internal/nostr/nostr.go +++ b/internal/nostr/nostr.go @@ -371,6 +371,7 @@ func (svc *Service) NIP47Handler(c echo.Context) error { select { case <-ctx.Done(): svc.Logger.WithError(ctx.Err()).WithFields(logrus.Fields{ + "subscription_id": subscription.Uuid, "request_event_id": requestData.SignedEvent.ID, "client_pubkey": requestData.SignedEvent.PubKey, "wallet_pubkey": requestData.WalletPubkey, @@ -473,6 +474,7 @@ func (svc *Service) NIP47WebhookHandler(c echo.Context) error { select { case <-ctx.Done(): svc.Logger.WithError(ctx.Err()).WithFields(logrus.Fields{ + "subscription_id": subscription.Uuid, "request_event_id": requestData.SignedEvent.ID, "client_pubkey": requestData.SignedEvent.PubKey, "wallet_pubkey": requestData.WalletPubkey, @@ -798,6 +800,7 @@ func (svc *Service) publishRequestEvent(ctx context.Context, subscription *Subsc if err != nil { // TODO: notify user about publish failure svc.Logger.WithError(err).WithFields(logrus.Fields{ + "subscription_id": subscription.Uuid, "request_event_id": subscription.RequestEvent.NostrId, "relay_url": subscription.RelayUrl, "wallet_pubkey": walletPubkey, @@ -807,6 +810,7 @@ func (svc *Service) publishRequestEvent(ctx context.Context, subscription *Subsc sub.Unsub() } else { svc.Logger.WithFields(logrus.Fields{ + "subscription_id": subscription.Uuid, "request_event_id": subscription.RequestEvent.NostrId, "relay_url": subscription.RelayUrl, "wallet_pubkey": walletPubkey, @@ -930,6 +934,7 @@ func (svc *Service) postEventToWebhook(event *nostr.Event, subscription *Subscri if err != nil { svc.Logger.WithError(err).WithFields(logrus.Fields{ + "subscription_id": subscription.Uuid, "request_event_id": request_event_id, "response_event_id": event.ID, "response_event_kind": event.Kind, @@ -942,6 +947,7 @@ func (svc *Service) postEventToWebhook(event *nostr.Event, subscription *Subscri _, err = http.Post(subscription.WebhookUrl, "application/json", bytes.NewBuffer(eventData)) if err != nil { svc.Logger.WithError(err).WithFields(logrus.Fields{ + "subscription_id": subscription.Uuid, "request_event_id": request_event_id, "response_event_id": event.ID, "response_event_kind": event.Kind, @@ -951,6 +957,7 @@ func (svc *Service) postEventToWebhook(event *nostr.Event, subscription *Subscri } svc.Logger.WithFields(logrus.Fields{ + "subscription_id": subscription.Uuid, "request_event_id": request_event_id, "response_event_id": event.ID, "response_event_kind": event.Kind, From 5930f6e8177e51eb2bda80da61e64f548a6e972f Mon Sep 17 00:00:00 2001 From: im-adithya Date: Fri, 20 Dec 2024 01:17:27 +0530 Subject: [PATCH 3/5] chore: log relay errors only once per app --- internal/nostr/nostr.go | 51 +++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/internal/nostr/nostr.go b/internal/nostr/nostr.go index 944ff01..e5957c9 100644 --- a/internal/nostr/nostr.go +++ b/internal/nostr/nostr.go @@ -713,7 +713,6 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri var relay *nostr.Relay var isCustomRelay bool var err error - waitToReconnectSeconds := 0 for { // context expiration has no effect on relays @@ -728,28 +727,13 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri svc.stopSubscription(subscription) return } - time.Sleep(time.Duration(waitToReconnectSeconds) * time.Second) relay, isCustomRelay, err = svc.getRelayConnection(ctx, subscription.RelayUrl) if err != nil { - // TODO: notify user about relay failure - waitToReconnectSeconds = max(waitToReconnectSeconds, 1) - waitToReconnectSeconds = min(waitToReconnectSeconds * 2, 900) - svc.Logger.WithError(err).WithFields(logrus.Fields{ - "subscription_id": subscription.Uuid, - "relay_url": subscription.RelayUrl, - }).Errorf("Failed to connect to relay, retrying in %vs...", waitToReconnectSeconds) continue } sub, err := relay.Subscribe(ctx, []nostr.Filter{*filter}) if err != nil { - // TODO: notify user about subscription failure - waitToReconnectSeconds = max(waitToReconnectSeconds, 1) - waitToReconnectSeconds = min(waitToReconnectSeconds * 2, 900) - svc.Logger.WithError(err).WithFields(logrus.Fields{ - "subscription_id": subscription.Uuid, - "relay_url": subscription.RelayUrl, - }).Errorf("Failed to subscribe to relay, retrying in %vs...", waitToReconnectSeconds) continue } @@ -762,8 +746,6 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri "relay_url": subscription.RelayUrl, }).Debug("Started subscription") - waitToReconnectSeconds = 0 - err = svc.processEvents(ctx, subscription, onReceiveEOS, handleEvent) if err != nil { @@ -906,7 +888,7 @@ func (svc *Service) getRelayConnection(ctx context.Context, customRelayURL strin svc.Logger.WithFields(logrus.Fields{ "custom_relay_url": customRelayURL, }).Info("Connecting to custom relay") - relay, err := nostr.RelayConnect(ctx, customRelayURL) + relay, err := svc.relayConnectWithBackoff(ctx, customRelayURL) return relay, true, err // true means custom and the relay should be closed } // use mutex otherwise the svc.Relay will be reconnected more than once @@ -917,7 +899,7 @@ func (svc *Service) getRelayConnection(ctx context.Context, customRelayURL strin return svc.Relay, false, nil } else { svc.Logger.Info("Lost connection to default relay, reconnecting...") - relay, err := nostr.RelayConnect(svc.Ctx, svc.Cfg.DefaultRelayURL) + relay, err := svc.relayConnectWithBackoff(svc.Ctx, svc.Cfg.DefaultRelayURL) if err == nil { svc.Relay = relay } @@ -925,6 +907,35 @@ func (svc *Service) getRelayConnection(ctx context.Context, customRelayURL strin } } +func (svc *Service) relayConnectWithBackoff(ctx context.Context, relayURL string) (relay *nostr.Relay, err error) { + waitToReconnectSeconds := 0 + for { + select { + case <-ctx.Done(): + svc.Logger.WithError(err).WithFields(logrus.Fields{ + "relay_url": relayURL, + }).Errorf("Context canceled, exiting attempt to connect to relay") + return nil, ctx.Err() + default: + time.Sleep(time.Duration(waitToReconnectSeconds) * time.Second) + relay, err = nostr.RelayConnect(ctx, relayURL) + if err != nil { + // TODO: notify user about relay failure + waitToReconnectSeconds = max(waitToReconnectSeconds, 1) + waitToReconnectSeconds = min(waitToReconnectSeconds * 2, 900) + svc.Logger.WithError(err).WithFields(logrus.Fields{ + "relay_url": relayURL, + }).Errorf("Failed to connect to relay, retrying in %vs...", waitToReconnectSeconds) + continue + } + svc.Logger.WithFields(logrus.Fields{ + "relay_url": relayURL, + }).Info("Relay connection successful.") + return relay, nil + } + } +} + func (svc *Service) postEventToWebhook(event *nostr.Event, subscription *Subscription) { eventData, err := json.Marshal(event) request_event_id := "" From 64fd5e358d21dfa031abb47bb1e150a2819782ea Mon Sep 17 00:00:00 2001 From: im-adithya Date: Fri, 20 Dec 2024 02:03:40 +0530 Subject: [PATCH 4/5] chore: log request event id --- internal/nostr/nostr.go | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/internal/nostr/nostr.go b/internal/nostr/nostr.go index 944ff01..5d41fc3 100644 --- a/internal/nostr/nostr.go +++ b/internal/nostr/nostr.go @@ -703,9 +703,14 @@ func (svc *Service) stopSubscription(subscription *Subscription) error { } func (svc *Service) startSubscription(ctx context.Context, subscription *Subscription, onReceiveEOS OnReceiveEOSFunc, handleEvent HandleEventFunc) { + requestEventId := "" + if subscription.RequestEvent != nil { + requestEventId = subscription.RequestEvent.NostrId + } svc.Logger.WithFields(logrus.Fields{ - "subscription_id": subscription.Uuid, - "relay_url": subscription.RelayUrl, + "request_event_id": requestEventId, + "subscription_id": subscription.Uuid, + "relay_url": subscription.RelayUrl, }).Debug("Starting subscription") filter := svc.subscriptionToFilter(subscription) @@ -722,8 +727,9 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri } if ctx.Err() != nil { svc.Logger.WithError(ctx.Err()).WithFields(logrus.Fields{ - "subscription_id": subscription.Uuid, - "relay_url": subscription.RelayUrl, + "request_event_id": requestEventId, + "subscription_id": subscription.Uuid, + "relay_url": subscription.RelayUrl, }).Debug("Context canceled, stopping subscription") svc.stopSubscription(subscription) return @@ -758,8 +764,9 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri svc.subscriptionsMutex.Unlock() svc.Logger.WithFields(logrus.Fields{ - "subscription_id": subscription.Uuid, - "relay_url": subscription.RelayUrl, + "request_event_id": requestEventId, + "subscription_id": subscription.Uuid, + "relay_url": subscription.RelayUrl, }).Debug("Started subscription") waitToReconnectSeconds = 0 @@ -769,8 +776,9 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri if err != nil { // TODO: notify user about subscription failure svc.Logger.WithError(err).WithFields(logrus.Fields{ - "subscription_id": subscription.Uuid, - "relay_url": subscription.RelayUrl, + "request_event_id": requestEventId, + "subscription_id": subscription.Uuid, + "relay_url": subscription.RelayUrl, }).Error("Subscription stopped due to relay error, reconnecting...") continue } else { @@ -780,8 +788,9 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri // stop the subscription if it's an NIP47 request if (subscription.RequestEvent != nil) { svc.Logger.WithFields(logrus.Fields{ - "subscription_id": subscription.Uuid, - "relay_url": subscription.RelayUrl, + "request_event_id": requestEventId, + "subscription_id": subscription.Uuid, + "relay_url": subscription.RelayUrl, }).Debug("Stopping subscription") svc.stopSubscription(subscription) } @@ -927,15 +936,15 @@ func (svc *Service) getRelayConnection(ctx context.Context, customRelayURL strin func (svc *Service) postEventToWebhook(event *nostr.Event, subscription *Subscription) { eventData, err := json.Marshal(event) - request_event_id := "" + requestEventId := "" if subscription.RequestEvent != nil { - request_event_id = subscription.RequestEvent.NostrId + requestEventId = subscription.RequestEvent.NostrId } if err != nil { svc.Logger.WithError(err).WithFields(logrus.Fields{ "subscription_id": subscription.Uuid, - "request_event_id": request_event_id, + "request_event_id": requestEventId, "response_event_id": event.ID, "response_event_kind": event.Kind, "webhook_url": subscription.WebhookUrl, @@ -948,7 +957,7 @@ func (svc *Service) postEventToWebhook(event *nostr.Event, subscription *Subscri if err != nil { svc.Logger.WithError(err).WithFields(logrus.Fields{ "subscription_id": subscription.Uuid, - "request_event_id": request_event_id, + "request_event_id": requestEventId, "response_event_id": event.ID, "response_event_kind": event.Kind, "webhook_url": subscription.WebhookUrl, @@ -958,7 +967,7 @@ func (svc *Service) postEventToWebhook(event *nostr.Event, subscription *Subscri svc.Logger.WithFields(logrus.Fields{ "subscription_id": subscription.Uuid, - "request_event_id": request_event_id, + "request_event_id": requestEventId, "response_event_id": event.ID, "response_event_kind": event.Kind, "webhook_url": subscription.WebhookUrl, From a415c01ab827d535984f6d2d1870f64b4dd6ac8f Mon Sep 17 00:00:00 2001 From: im-adithya Date: Fri, 20 Dec 2024 16:09:32 +0530 Subject: [PATCH 5/5] chore: use consistent naming and pass in pointer --- internal/nostr/nostr.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/nostr/nostr.go b/internal/nostr/nostr.go index c9dde8b..9661f75 100644 --- a/internal/nostr/nostr.go +++ b/internal/nostr/nostr.go @@ -227,7 +227,7 @@ func (svc *Service) InfoHandler(c echo.Context) error { svc.Logger.WithFields(logrus.Fields{ "relay_url": requestData.RelayUrl, "wallet_pubkey": requestData.WalletPubkey, - "info_event_id": event.ID, + "response_event_id": event.ID, }).Info("Received info event") sub.Unsub() return c.JSON(http.StatusOK, InfoResponse{ @@ -362,7 +362,7 @@ func (svc *Service) NIP47Handler(c echo.Context) error { }) } - subscription := svc.prepareNIP47Subscription(requestData.RelayUrl, requestData.WalletPubkey, "", requestEvent) + subscription := svc.prepareNIP47Subscription(requestData.RelayUrl, requestData.WalletPubkey, "", &requestEvent) ctx, cancel := context.WithTimeout(c.Request().Context(), 90*time.Second) defer cancel() @@ -463,7 +463,7 @@ func (svc *Service) NIP47WebhookHandler(c echo.Context) error { }) } - subscription := svc.prepareNIP47Subscription(requestData.RelayUrl, requestData.WalletPubkey, requestData.WebhookUrl, requestEvent) + subscription := svc.prepareNIP47Subscription(requestData.RelayUrl, requestData.WalletPubkey, requestData.WebhookUrl, &requestEvent) ctx, cancel := context.WithTimeout(svc.Ctx, 90*time.Second) @@ -490,7 +490,7 @@ func (svc *Service) NIP47WebhookHandler(c echo.Context) error { }) } -func (svc *Service) prepareNIP47Subscription(relayUrl, walletPubkey, webhookUrl string, requestEvent RequestEvent) (Subscription) { +func (svc *Service) prepareNIP47Subscription(relayUrl, walletPubkey, webhookUrl string, requestEvent *RequestEvent) (Subscription) { return Subscription{ RelayUrl: relayUrl, WebhookUrl: webhookUrl, @@ -500,7 +500,7 @@ func (svc *Service) prepareNIP47Subscription(relayUrl, walletPubkey, webhookUrl Tags: &nostr.TagMap{"e": []string{requestEvent.NostrId}}, Since: time.Now(), Limit: 1, - RequestEvent: &requestEvent, + RequestEvent: requestEvent, EventChan: make(chan *nostr.Event, 1), Uuid: uuid.New().String(), } @@ -664,7 +664,7 @@ func (svc *Service) StopSubscriptionHandler(c echo.Context) error { if err != nil { svc.Logger.WithFields(logrus.Fields{ "subscription_id": subscription.Uuid, - }).Debug("Subscription is stopped already") + }).Error("Subscription is stopped already") return c.JSON(http.StatusAlreadyReported, StopSubscriptionResponse{ Message: "Subscription is already closed", @@ -729,7 +729,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri "request_event_id": requestEventId, "subscription_id": subscription.Uuid, "relay_url": subscription.RelayUrl, - }).Debug("Context canceled, stopping subscription") + }).Error("Stopping subscription") svc.stopSubscription(subscription) return }