wip: phoenixd webhook

This commit is contained in:
ekzyis 2024-12-27 01:52:47 +01:00
parent 0a10fcc109
commit c5554cb9ca
2 changed files with 28 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
"strings"
"github.com/ekzyis/zaply/lightning"
"github.com/labstack/echo/v4"
)
type Phoenixd struct {
@ -96,3 +97,18 @@ func (p *Phoenixd) CreateInvoice(msats int64, description string) (lightning.Bol
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
import (
"log"
"net/url"
"github.com/ekzyis/zaply/env"
"github.com/ekzyis/zaply/lightning/phoenixd"
"github.com/ekzyis/zaply/lnurl"
@ -22,11 +25,20 @@ func NewServer() *Server {
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)
return s