cancel_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 cancelHoldInvoiceParams struct {
  13  	PaymentHash string `json:"payment_hash"`
  14  }
  15  type cancelHoldInvoiceResponse struct{}
  16  
  17  func (controller *nip47Controller) HandleCancelHoldInvoiceEvent(ctx context.Context, nip47Request *models.Request, requestEventId uint, appId uint, publishResponse func(*models.Response, nostr.Tags)) {
  18  	cancelHoldInvoiceParams := &cancelHoldInvoiceParams{}
  19  	decodeErrResp := decodeRequest(nip47Request, cancelHoldInvoiceParams)
  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  		"paymentHash":    cancelHoldInvoiceParams.PaymentHash,
  29  	}).Info("Canceling hold invoice")
  30  
  31  	err := controller.transactionsService.CancelHoldInvoice(ctx, cancelHoldInvoiceParams.PaymentHash, controller.lnClient)
  32  	if err != nil {
  33  		logger.Logger.WithFields(logrus.Fields{
  34  			"request_event_id": requestEventId,
  35  			"appId":            appId,
  36  			"paymentHash":      cancelHoldInvoiceParams.PaymentHash,
  37  		}).WithError(err).Error("Failed to cancel 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:     &cancelHoldInvoiceResponse{},
  49  	}, nostr.Tags{})
  50  }
  51