diff --git a/lnme.go b/lnme.go index 8608d13..31f6584 100644 --- a/lnme.go +++ b/lnme.go @@ -144,7 +144,7 @@ func main() { }) if !cfg.Bool("disable-ln-address") { - e.GET("/.well-known/lnurlp/:name", func(c echo.Context) error { + lnurlHandler := func(c echo.Context) error { name := c.Param("name") lightningAddress := name + "@" + c.Request().Host lnurlMetadata := "[[\"text/identifier\", \"" + lightningAddress + "\"], [\"text/plain\", \"Sats for " + lightningAddress + "\"]]" @@ -164,11 +164,16 @@ func main() { stdOutLogger.Printf("New LightningAddress request amount: %s", amount) msats, err := strconv.ParseInt(amount, 10, 64) if err != nil || msats < 1000 { + stdOutLogger.Printf("Invalid amount: %s", amount) return c.JSON(http.StatusOK, lnurl.LNURLErrorResponse{Status: "ERROR", Reason: "Invalid Amount"}) } sats := msats / 1000 // we need sats metadataHash := sha256.Sum256([]byte(lnurlMetadata)) invoice, err := lnClient.AddInvoice(sats, lightningAddress, metadataHash[:]) + if err != nil { + stdOutLogger.Printf("Error creating invoice: %s", err) + return c.JSON(http.StatusOK, lnurl.LNURLErrorResponse{Status: "ERROR", Reason: "Server Error"}) + } lnurlPayResponse2 := lnurl.LNURLPayResponse2{ LNURLResponse: lnurl.LNURLResponse{Status: "OK"}, PR: invoice.PaymentRequest, @@ -178,7 +183,9 @@ func main() { } return c.JSON(http.StatusOK, lnurlPayResponse2) } - }) + } + e.GET("/.well-known/lnurlp/:name", lnurlHandler) + e.GET("/lnurlp/:name", lnurlHandler) } // Debug test endpoint