Compare commits
3 Commits
0bcd3aae15
...
43a2b4e9d5
Author | SHA1 | Date | |
---|---|---|---|
43a2b4e9d5 | |||
143aa67a5d | |||
40963f9a36 |
@ -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 {
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -27,14 +27,18 @@ func Router(e *echo.Echo, ln lightning.Lightning) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func payRequest(c echo.Context) error {
|
func payRequest(c echo.Context) error {
|
||||||
name := c.Param("name")
|
callback, err := url.JoinPath(env.PublicUrl, "/.well-known/lnurlp/", c.Param("name"), "/pay")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return c.JSON(
|
return c.JSON(
|
||||||
http.StatusOK,
|
http.StatusOK,
|
||||||
map[string]any{
|
map[string]any{
|
||||||
"callback": fmt.Sprintf("%s/.well-known/lnurlp/%s/pay", env.PublicUrl, name),
|
"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,
|
||||||
},
|
},
|
||||||
@ -74,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()})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user