Compare commits

...

2 Commits

Author SHA1 Message Date
99c48cb684 Rename param to description 2024-12-27 01:29:18 +01:00
6e39698f18 Add LNURL metadata 2024-12-27 01:29:18 +01:00
3 changed files with 12 additions and 4 deletions

View File

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

View File

@ -38,7 +38,7 @@ func payRequest(c echo.Context) error {
"callback": callback, "callback": callback,
"minSendable": MIN_SENDABLE_AMOUNT, "minSendable": MIN_SENDABLE_AMOUNT,
"maxSendable": MAX_SENDABLE_AMOUNT, "maxSendable": MAX_SENDABLE_AMOUNT,
"metadata": fmt.Sprintf("[[\"text/plain\",\"paying %s\"]]", name), "metadata": lnurlMetadata(c),
"tag": "payRequest", "tag": "payRequest",
"commentAllowed": MAX_COMMENT_LENGTH, "commentAllowed": MAX_COMMENT_LENGTH,
}, },
@ -78,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 { func lnurlError(c echo.Context, code int, err error) error {
return c.JSON(code, map[string]any{"status": "ERROR", "error": err.Error()}) return c.JSON(code, map[string]any{"status": "ERROR", "error": err.Error()})
} }