Skip to content

Commit 36d4dec

Browse files
authored
Merge pull request #22 from bumi/lnurl-logging
Better error logging for the LNURL endpoint
2 parents 22bc75d + 0fd121d commit 36d4dec

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lnme.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func main() {
144144
})
145145

146146
if !cfg.Bool("disable-ln-address") {
147-
e.GET("/.well-known/lnurlp/:name", func(c echo.Context) error {
147+
lnurlHandler := func(c echo.Context) error {
148148
name := c.Param("name")
149149
lightningAddress := name + "@" + c.Request().Host
150150
lnurlMetadata := "[[\"text/identifier\", \"" + lightningAddress + "\"], [\"text/plain\", \"Sats for " + lightningAddress + "\"]]"
@@ -164,11 +164,16 @@ func main() {
164164
stdOutLogger.Printf("New LightningAddress request amount: %s", amount)
165165
msats, err := strconv.ParseInt(amount, 10, 64)
166166
if err != nil || msats < 1000 {
167+
stdOutLogger.Printf("Invalid amount: %s", amount)
167168
return c.JSON(http.StatusOK, lnurl.LNURLErrorResponse{Status: "ERROR", Reason: "Invalid Amount"})
168169
}
169170
sats := msats / 1000 // we need sats
170171
metadataHash := sha256.Sum256([]byte(lnurlMetadata))
171172
invoice, err := lnClient.AddInvoice(sats, lightningAddress, metadataHash[:])
173+
if err != nil {
174+
stdOutLogger.Printf("Error creating invoice: %s", err)
175+
return c.JSON(http.StatusOK, lnurl.LNURLErrorResponse{Status: "ERROR", Reason: "Server Error"})
176+
}
172177
lnurlPayResponse2 := lnurl.LNURLPayResponse2{
173178
LNURLResponse: lnurl.LNURLResponse{Status: "OK"},
174179
PR: invoice.PaymentRequest,
@@ -178,7 +183,9 @@ func main() {
178183
}
179184
return c.JSON(http.StatusOK, lnurlPayResponse2)
180185
}
181-
})
186+
}
187+
e.GET("/.well-known/lnurlp/:name", lnurlHandler)
188+
e.GET("/lnurlp/:name", lnurlHandler)
182189
}
183190

184191
// Debug test endpoint

0 commit comments

Comments
 (0)