Compare commits

..

1 Commits

Author SHA1 Message Date
0bcd3aae15 Fix malformed callback 2024-12-27 01:06:33 +01:00
3 changed files with 7 additions and 13 deletions

View File

@ -3,7 +3,7 @@ package lightning
type Bolt11 string
type Lightning interface {
CreateInvoice(msats int64, description string) (Bolt11, error)
CreateInvoice(msats int64, comment string) (Bolt11, error)
}
type LightningImpl struct {

View File

@ -53,10 +53,10 @@ func WithPhoenixdWebhookUrl(webhookUrl string) func(*Phoenixd) *Phoenixd {
}
}
func (p *Phoenixd) CreateInvoice(msats int64, description string) (lightning.Bolt11, error) {
func (p *Phoenixd) CreateInvoice(msats int64, comment string) (lightning.Bolt11, error) {
values := url.Values{}
values.Add("amountSat", strconv.FormatInt(msats/1000, 10))
values.Add("description", description)
values.Add("description", comment)
if p.webhookUrl != "" {
values.Add("webhookUrl", p.webhookUrl)
}

View File

@ -27,7 +27,9 @@ func Router(e *echo.Echo, ln lightning.Lightning) {
}
func payRequest(c echo.Context) error {
callback, err := url.JoinPath(env.PublicUrl, "/.well-known/lnurlp/", c.Param("name"), "/pay")
name := c.Param("name")
callback, err := url.JoinPath(env.PublicUrl, "/.well-known/lnurlp/", name, "/pay")
if err != nil {
return err
}
@ -38,7 +40,7 @@ func payRequest(c echo.Context) error {
"callback": callback,
"minSendable": MIN_SENDABLE_AMOUNT,
"maxSendable": MAX_SENDABLE_AMOUNT,
"metadata": lnurlMetadata(c),
"metadata": fmt.Sprintf("[[\"text/plain\",\"paying %s\"]]", name),
"tag": "payRequest",
"commentAllowed": MAX_COMMENT_LENGTH,
},
@ -78,14 +80,6 @@ func pay(ln lightning.Lightning) echo.HandlerFunc {
}
}
func lnurlMetadata(c echo.Context) string {
s := "["
s += fmt.Sprintf("[\"text/plain\",\"Paying %s@%s\"]", c.Param("name"), c.Request().Host)
s += fmt.Sprintf("[\"text/identifier\",\"%s@%s\"]", c.Param("name"), c.Request().Host)
s += "]"
return s
}
func lnurlError(c echo.Context, code int, err error) error {
return c.JSON(code, map[string]any{"status": "ERROR", "error": err.Error()})
}