Skip to content

Commit

Permalink
chore: return error if lnclient is not initialzied
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jan 25, 2024
1 parent 7cf88fd commit f3a195a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ func (svc *Service) HandleEvent(ctx context.Context, event *nostr.Event) (result
return nil, nil
}

if svc.lnClient == nil {
svc.Logger.WithFields(logrus.Fields{
"nostrPubkey": event.PubKey,
}).Errorf("Received an event before ln client is initialized")

ss, err := nip04.ComputeSharedSecret(event.PubKey, svc.cfg.NostrSecretKey)
if err != nil {
return nil, err
}
return svc.createResponse(event, Nip47Response{
Error: &Nip47Error{
Code: NIP_47_ERROR_INTERNAL,
Message: "The public key does not have a ln client initialized.",
},
}, ss)
}

app := App{}
err = svc.db.First(&app, &App{
NostrPubkey: event.PubKey,
Expand All @@ -287,13 +304,12 @@ func (svc *Service) HandleEvent(ctx context.Context, event *nostr.Event) (result
if err != nil {
return nil, err
}
resp, _ := svc.createResponse(event, Nip47Response{
return svc.createResponse(event, Nip47Response{
Error: &Nip47Error{
Code: NIP_47_ERROR_UNAUTHORIZED,
Message: "The public key does not have a wallet connected.",
},
}, ss)
return resp, err
}

svc.Logger.WithFields(logrus.Fields{
Expand Down

0 comments on commit f3a195a

Please sign in to comment.