From 3b7ac31615b9901e0c020e3ca639e2d31795f902 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Sun, 24 Oct 2021 11:32:00 +0200 Subject: [PATCH 1/2] Better error logging for the LNURL endpoint This checks for errors when creating the invoice and logs the error and returns an LNURL error response. Before it would return a blank pr. --- lnme.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lnme.go b/lnme.go index 8608d13..5056753 100644 --- a/lnme.go +++ b/lnme.go @@ -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, From 9ae6153d4750fb9243a2d8de5420daecb4682b74 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Sun, 24 Oct 2021 11:44:05 +0200 Subject: [PATCH 2/2] Nicer LNURLp URLs this also registers a shorter lnurlp that can be used additionally to the lightning address --- lnme.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lnme.go b/lnme.go index 5056753..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 + "\"]]" @@ -183,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