Merge pull request #22 from bumi/lnurl-logging

Better error logging for the LNURL endpoint
This commit is contained in:
bumi 2021-10-25 11:00:55 +02:00 committed by GitHub
commit 36d4dec5fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

11
lnme.go
View File

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