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

fix: use getWalletPubkey func #89

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions internal/nostr/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,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,
"wallet_pubkey": (*subscription.Authors)[0],
"wallet_pubkey": svc.getWalletPubkey(subscription.Authors),
}).Info("Starting subscription")

filter := svc.subscriptionToFilter(subscription)
Expand All @@ -663,7 +663,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri
svc.Logger.WithError(err).WithFields(logrus.Fields{
"subscription_id": subscription.ID,
"relay_url": subscription.RelayUrl,
"wallet_pubkey": (*subscription.Authors)[0],
"wallet_pubkey": svc.getWalletPubkey(subscription.Authors),
}).Error("Failed get relay connection, retrying in 5s...")
time.Sleep(5 * time.Second) // sleep for 5 seconds
continue
Expand All @@ -675,7 +675,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri
svc.Logger.WithError(err).WithFields(logrus.Fields{
"subscription_id": subscription.ID,
"relay_url": subscription.RelayUrl,
"wallet_pubkey": (*subscription.Authors)[0],
"wallet_pubkey": svc.getWalletPubkey(subscription.Authors),
}).Error("Failed to subscribe to relay, retrying in 5s...")
time.Sleep(5 * time.Second) // sleep for 5 seconds
continue
Expand All @@ -687,7 +687,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri

svc.Logger.WithFields(logrus.Fields{
"subscription_id": subscription.ID,
"wallet_pubkey": (*subscription.Authors)[0],
"wallet_pubkey": svc.getWalletPubkey(subscription.Authors),
}).Info("Started subscription")

err = svc.processEvents(ctx, subscription, onReceiveEOS, handleEvent)
Expand All @@ -697,7 +697,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri
svc.Logger.WithError(err).WithFields(logrus.Fields{
"subscription_id": subscription.ID,
"relay_url": subscription.RelayUrl,
"wallet_pubkey": (*subscription.Authors)[0],
"wallet_pubkey": svc.getWalletPubkey(subscription.Authors),
}).Error("Subscription stopped due to relay error, reconnecting in 5s...")
time.Sleep(5 * time.Second) // sleep for 5 seconds
continue
Expand All @@ -718,7 +718,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": (*subscription.Authors)[0],
"wallet_pubkey": svc.getWalletPubkey(subscription.Authors),
}).Info("Stopping subscription")
break
}
Expand All @@ -735,14 +735,14 @@ func (svc *Service) publishEvent(ctx context.Context, subscription *Subscription
svc.Logger.WithError(err).WithFields(logrus.Fields{
"subscription_id": subscription.ID,
"relay_url": subscription.RelayUrl,
"wallet_pubkey": (*subscription.Authors)[0],
"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": (*subscription.Authors)[0],
"wallet_pubkey": svc.getWalletPubkey(subscription.Authors),
}).Info("Published request event successfully")
subscription.RequestEventDB.State = REQUEST_EVENT_PUBLISH_CONFIRMED
}
Expand All @@ -753,7 +753,7 @@ func (svc *Service) handleResponseEvent(event *nostr.Event, subscription *Subscr
"event_id": event.ID,
"event_kind": event.Kind,
"request_event_id": subscription.RequestEvent.ID,
"wallet_pubkey": (*subscription.Authors)[0],
"wallet_pubkey": svc.getWalletPubkey(subscription.Authors),
}).Info("Received response event")
responseEvent := ResponseEvent{
NostrId: event.ID,
Expand All @@ -777,7 +777,7 @@ func (svc *Service) handleSubscribedEvent(event *nostr.Event, subscription *Subs
"event_id": event.ID,
"event_kind": event.Kind,
"subscription_id": subscription.ID,
"wallet_pubkey": (*subscription.Authors)[0],
"wallet_pubkey": svc.getWalletPubkey(subscription.Authors),
}).Info("Received event")
responseEvent := ResponseEvent{
NostrId: event.ID,
Expand All @@ -799,7 +799,7 @@ func (svc *Service) processEvents(ctx context.Context, subscription *Subscriptio
<-sub.EndOfStoredEvents
svc.Logger.WithFields(logrus.Fields{
"subscription_id": subscription.ID,
"wallet_pubkey": (*subscription.Authors)[0],
"wallet_pubkey": svc.getWalletPubkey(subscription.Authors),
}).Info("Received EOS")

if (onReceiveEOS != nil) {
Expand All @@ -813,6 +813,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),
}).Info("Relay subscription events channel ended")
}()

Expand Down Expand Up @@ -906,3 +907,10 @@ func (svc *Service) subscriptionToFilter(subscription *Subscription) (*nostr.Fil
}
return &filter
}

func (svc *Service) getWalletPubkey(authors *[]string) string {
if authors != nil && len(*authors) > 0 {
return (*authors)[0]
}
return ""
}
Loading