settle_hold_invoice_controller.go raw
1 package controllers
2
3 import (
4 "context"
5
6 "github.com/getAlby/go-nostr"
7 "github.com/getAlby/hub/logger"
8 "github.com/getAlby/hub/nip47/models"
9 "github.com/sirupsen/logrus"
10 )
11
12 type settleHoldInvoiceParams struct {
13 Preimage string `json:"preimage"`
14 }
15 type settleHoldInvoiceResponse struct{}
16
17 func (controller *nip47Controller) HandleSettleHoldInvoiceEvent(ctx context.Context, nip47Request *models.Request, requestEventId uint, appId uint, publishResponse func(*models.Response, nostr.Tags)) {
18 settleHoldInvoiceParams := &settleHoldInvoiceParams{}
19 decodeErrResp := decodeRequest(nip47Request, settleHoldInvoiceParams)
20 if decodeErrResp != nil {
21 publishResponse(decodeErrResp, nostr.Tags{})
22 return
23 }
24
25 logger.Logger.WithFields(logrus.Fields{
26 "requestEventId": requestEventId,
27 "appId": appId,
28 "preimage": settleHoldInvoiceParams.Preimage,
29 }).Info("Settling hold invoice")
30
31 _, err := controller.transactionsService.SettleHoldInvoice(ctx, settleHoldInvoiceParams.Preimage, controller.lnClient)
32 if err != nil {
33 logger.Logger.WithFields(logrus.Fields{
34 "request_event_id": requestEventId,
35 "appId": appId,
36 "preimage": settleHoldInvoiceParams.Preimage,
37 }).WithError(err).Error("Failed to settle hold invoice")
38
39 publishResponse(&models.Response{
40 ResultType: nip47Request.Method,
41 Error: mapNip47Error(err),
42 }, nostr.Tags{})
43 return
44 }
45
46 publishResponse(&models.Response{
47 ResultType: nip47Request.Method,
48 Result: &settleHoldInvoiceResponse{},
49 }, nostr.Tags{})
50 }
51