Compare commits

..

3 Commits

Author SHA1 Message Date
43a2b4e9d5 Rename param to description 2024-12-27 01:22:51 +01:00
143aa67a5d Add LNURL metadata 2024-12-27 01:22:51 +01:00
40963f9a36 Fix malformed callback 2024-12-27 01:13:52 +01:00
3 changed files with 13 additions and 7 deletions

View File

@ -3,7 +3,7 @@ package lightning
type Bolt11 string
type Lightning interface {
CreateInvoice(msats int64, comment string) (Bolt11, error)
CreateInvoice(msats int64, description 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, comment string) (lightning.Bolt11, error) {
func (p *Phoenixd) CreateInvoice(msats int64, description string) (lightning.Bolt11, error) {
values := url.Values{}
values.Add("amountSat", strconv.FormatInt(msats/1000, 10))
values.Add("description", comment)
values.Add("description", description)
if p.webhookUrl != "" {
values.Add("webhookUrl", p.webhookUrl)
}

View File

@ -27,9 +27,7 @@ func Router(e *echo.Echo, ln lightning.Lightning) {
}
func payRequest(c echo.Context) error {
name := c.Param("name")
callback, err := url.JoinPath(env.PublicUrl, "/.well-known/lnurlp/", name, "/pay")
callback, err := url.JoinPath(env.PublicUrl, "/.well-known/lnurlp/", c.Param("name"), "/pay")
if err != nil {
return err
}
@ -40,7 +38,7 @@ func payRequest(c echo.Context) error {
"callback": callback,
"minSendable": MIN_SENDABLE_AMOUNT,
"maxSendable": MAX_SENDABLE_AMOUNT,
"metadata": fmt.Sprintf("[[\"text/plain\",\"paying %s\"]]", name),
"metadata": lnurlMetadata(c),
"tag": "payRequest",
"commentAllowed": MAX_COMMENT_LENGTH,
},
@ -80,6 +78,14 @@ 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()})
}