Skip to content

Commit

Permalink
chore: check if svc lnclient is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jan 22, 2024
1 parent f76f903 commit e51f0ea
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions echo_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
echologrus "github.com/davrux/echo-logrus/v4"
"github.com/getAlby/nostr-wallet-connect/frontend"
"github.com/getAlby/nostr-wallet-connect/models/api"
"github.com/getAlby/nostr-wallet-connect/models/db"
"github.com/gorilla/sessions"
"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
Expand All @@ -20,31 +19,11 @@ import (

func (svc *Service) ValidateUserMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
dbConfig := db.Config{}
svc.db.First(&dbConfig)
errorMessage := "Configuration not initialized"

if dbConfig.LNBackendType == "" {
if svc.lnClient == nil {
return c.JSON(http.StatusMethodNotAllowed, ErrorResponse{
Message: errorMessage,
Message: "Lightning Client not initialized",
})
}

switch dbConfig.LNBackendType {
case LNDBackendType:
if dbConfig.LNDAddress == "" || svc.cfg.LNDCertFile == "" || dbConfig.LNDCertHex == "" || svc.cfg.LNDMacaroonFile == "" || dbConfig.LNDMacaroonHex == "" {
return c.JSON(http.StatusMethodNotAllowed, ErrorResponse{
Message: errorMessage,
})
}
case BreezBackendType:
if dbConfig.BreezMnemonic == "" || dbConfig.BreezAPIKey == "" || dbConfig.GreenlightInviteCode == "" || svc.cfg.BreezWorkdir == "" {
return c.JSON(http.StatusMethodNotAllowed, ErrorResponse{
Message: errorMessage,
})
}
}

return next(c)
}
}
Expand Down

0 comments on commit e51f0ea

Please sign in to comment.