Compare commits

..

5 Commits

Author SHA1 Message Date
c5554cb9ca wip: phoenixd webhook 2024-12-27 01:52:47 +01:00
0a10fcc109 Add LNURL metadata 2024-12-27 01:45:36 +01:00
79d473b0f5 Fix malformed callback 2024-12-27 01:45:36 +01:00
9c13048fb6 Print LNURL 2024-12-27 01:45:36 +01:00
0eb37e8e9d LNURL + phoenixd 2024-12-27 01:45:36 +01:00
2 changed files with 33 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import (
"strings" "strings"
"github.com/ekzyis/zaply/lightning" "github.com/ekzyis/zaply/lightning"
"github.com/labstack/echo/v4"
) )
type Phoenixd struct { type Phoenixd struct {
@ -96,3 +97,18 @@ func (p *Phoenixd) CreateInvoice(msats int64, description string) (lightning.Bol
return lightning.Bolt11(response.Serialized), nil return lightning.Bolt11(response.Serialized), nil
} }
func WebhookHandler(c echo.Context) error {
var webhook struct {
Type string `json:"type"`
AmountSat int64 `json:"amountSat"`
PaymentHash string `json:"paymentHash"`
}
if err := c.Bind(&webhook); err != nil {
return err
}
log.Printf("webhook: %+v", webhook)
return c.NoContent(http.StatusOK)
}

View File

@ -1,6 +1,9 @@
package server package server
import ( import (
"log"
"net/url"
"github.com/ekzyis/zaply/env" "github.com/ekzyis/zaply/env"
"github.com/ekzyis/zaply/lightning/phoenixd" "github.com/ekzyis/zaply/lightning/phoenixd"
"github.com/ekzyis/zaply/lnurl" "github.com/ekzyis/zaply/lnurl"
@ -17,16 +20,25 @@ func NewServer() *Server {
Echo: echo.New(), Echo: echo.New(),
} }
p := phoenixd.NewPhoenixd(
phoenixd.WithPhoenixdURL(env.PhoenixdURL),
phoenixd.WithPhoenixdLimitedAccessToken(env.PhoenixdLimitedAccessToken),
)
s.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ s.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_custom} ${method} ${uri} ${status}\n", Format: "${time_custom} ${method} ${uri} ${status}\n",
CustomTimeFormat: "2006-01-02 15:04:05.00000-0700", CustomTimeFormat: "2006-01-02 15:04:05.00000-0700",
})) }))
webhookPath := "/overlay/webhook"
webhookUrl, err := url.JoinPath(env.PublicUrl, webhookPath)
if err != nil {
log.Fatal(err)
}
p := phoenixd.NewPhoenixd(
phoenixd.WithPhoenixdURL(env.PhoenixdURL),
phoenixd.WithPhoenixdLimitedAccessToken(env.PhoenixdLimitedAccessToken),
phoenixd.WithPhoenixdWebhookUrl(webhookUrl),
)
s.POST(webhookPath, phoenixd.WebhookHandler)
lnurl.Router(s.Echo, p) lnurl.Router(s.Echo, p)
return s return s