Skip to content

Commit

Permalink
chore: add getPubkeys func
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jul 30, 2024
1 parent b673146 commit b36a24c
Showing 1 changed file with 17 additions and 35 deletions.
52 changes: 17 additions & 35 deletions internal/nostr/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,13 +676,7 @@ func (svc *Service) stopSubscription(subscription *Subscription) error {
}

func (svc *Service) startSubscription(ctx context.Context, subscription *Subscription, onReceiveEOS OnReceiveEOSFunc, handleEvent HandleEventFunc) {
walletPubkey := ""
clientPubkey := ""

if (subscription.RequestEvent != nil) {
walletPubkey = getWalletPubkey(&subscription.RequestEvent.Tags)
clientPubkey = subscription.RequestEvent.PubKey
}
walletPubkey, clientPubkey := getPubkeys(subscription)

svc.Logger.WithFields(logrus.Fields{
"subscription_id": subscription.ID,
Expand Down Expand Up @@ -779,13 +773,7 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri
}

func (svc *Service) publishRequestEvent(ctx context.Context, subscription *Subscription) {
walletPubkey := ""
clientPubkey := ""

if (subscription.RequestEvent != nil) {
walletPubkey = getWalletPubkey(&subscription.RequestEvent.Tags)
clientPubkey = subscription.RequestEvent.PubKey
}
walletPubkey, clientPubkey := getPubkeys(subscription)

svc.subscriptionsMutex.Lock()
sub := svc.subscriptions[subscription.Uuid]
Expand All @@ -812,13 +800,7 @@ func (svc *Service) publishRequestEvent(ctx context.Context, subscription *Subsc
}

func (svc *Service) handleResponseEvent(event *nostr.Event, subscription *Subscription) {
walletPubkey := ""
clientPubkey := ""

if (subscription.RequestEvent != nil) {
walletPubkey = getWalletPubkey(&subscription.RequestEvent.Tags)
clientPubkey = subscription.RequestEvent.PubKey
}
walletPubkey, clientPubkey := getPubkeys(subscription)

svc.Logger.WithFields(logrus.Fields{
"response_event_id": event.ID,
Expand All @@ -845,13 +827,7 @@ func (svc *Service) handleResponseEvent(event *nostr.Event, subscription *Subscr
}

func (svc *Service) handleSubscribedEvent(event *nostr.Event, subscription *Subscription) {
walletPubkey := ""
clientPubkey := ""

if (subscription.RequestEvent != nil) {
walletPubkey = getWalletPubkey(&subscription.RequestEvent.Tags)
clientPubkey = subscription.RequestEvent.PubKey
}
walletPubkey, clientPubkey := getPubkeys(subscription)

svc.Logger.WithFields(logrus.Fields{
"event_id": event.ID,
Expand All @@ -872,13 +848,7 @@ func (svc *Service) handleSubscribedEvent(event *nostr.Event, subscription *Subs
}

func (svc *Service) processEvents(ctx context.Context, subscription *Subscription, onReceiveEOS OnReceiveEOSFunc, handleEvent HandleEventFunc) error {
walletPubkey := ""
clientPubkey := ""

if (subscription.RequestEvent != nil) {
walletPubkey = getWalletPubkey(&subscription.RequestEvent.Tags)
clientPubkey = subscription.RequestEvent.PubKey
}
walletPubkey, clientPubkey := getPubkeys(subscription)

svc.subscriptionsMutex.Lock()
sub := svc.subscriptions[subscription.Uuid]
Expand Down Expand Up @@ -1001,6 +971,18 @@ func (svc *Service) subscriptionToFilter(subscription *Subscription) (*nostr.Fil
return &filter
}

func getPubkeys(subscription *Subscription) (string, string) {
walletPubkey := ""
clientPubkey := ""

if (subscription.RequestEvent != nil) {
walletPubkey = getWalletPubkey(&subscription.RequestEvent.Tags)
clientPubkey = subscription.RequestEvent.PubKey
}

return walletPubkey, clientPubkey
}

func getWalletPubkey(tags *nostr.Tags) string {
pTag := tags.GetFirst([]string{"p", ""})
if pTag != nil {
Expand Down

0 comments on commit b36a24c

Please sign in to comment.