Skip to content

Commit

Permalink
subscribe to the event before publishing
Browse files Browse the repository at this point in the history
we had issues in the JS SDK for some methods because the reply came too fast
  • Loading branch information
bumi committed Jan 28, 2024
1 parent fa13864 commit 47e327a
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions internal/nostr/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ func NIP47Handler(w http.ResponseWriter, r *http.Request) {
return
}

// Start subscribing to the event for response
logrus.WithFields(logrus.Fields{"e": req.SignedEvent.ID, "author": req.WalletPubkey}).Info("Subscribing to events for response...")
filter := nostr.Filter{
Authors: []string{req.WalletPubkey},
Kinds: []int{NIP_47_RESPONSE_KIND},
Tags: nostr.TagMap{"e": []string{req.SignedEvent.ID}},
}
sub, err := relay.Subscribe(ctx, []nostr.Filter{filter})
if err != nil {
handleError(w, err, "error subscribing to events", http.StatusBadRequest)
return
}

// Publish the request event
logrus.Info("Publishing request event...")
status, err := relay.Publish(ctx, req.SignedEvent)
Expand Down Expand Up @@ -126,19 +139,6 @@ func NIP47Handler(w http.ResponseWriter, r *http.Request) {
}).Info("Request sent but no response from relay (timeout)")
}

// Start subscribing to the event for response
logrus.Info("Subscribing to events for response...")
filter := nostr.Filter{
Authors: []string{req.WalletPubkey},
Kinds: []int{NIP_47_RESPONSE_KIND},
Tags: nostr.TagMap{"e": []string{req.SignedEvent.ID}},
}
sub, err := relay.Subscribe(ctx, []nostr.Filter{filter})
if err != nil {
handleError(w, err, "error subscribing to events", http.StatusBadRequest)
return
}

select {
case <-ctx.Done():
logrus.Info("Exiting subscription.")
Expand Down

0 comments on commit 47e327a

Please sign in to comment.