mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-20 22:24:52 +01:00
Use request context in handlers
This commit is contained in:
@@ -45,7 +45,7 @@ func (controller *AddInvoiceController) AddInvoice(c echo.Context) error {
|
||||
}
|
||||
c.Logger().Infof("Adding invoice: user_id=%v memo=%s value=%v description_hash=%s", userID, body.Memo, amount, body.DescriptionHash)
|
||||
|
||||
invoice, err := controller.svc.AddIncomingInvoice(userID, amount, body.Memo, body.DescriptionHash)
|
||||
invoice, err := controller.svc.AddIncomingInvoice(c.Request().Context(), userID, amount, body.Memo, body.DescriptionHash)
|
||||
if err != nil {
|
||||
c.Logger().Errorf("Error creating invoice: %v", err)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
@@ -41,7 +41,7 @@ func (controller *AuthController) Auth(c echo.Context) error {
|
||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||
}
|
||||
|
||||
accessToken, refreshToken, err := controller.svc.GenerateToken(body.Login, body.Password, body.RefreshToken)
|
||||
accessToken, refreshToken, err := controller.svc.GenerateToken(c.Request().Context(), body.Login, body.Password, body.RefreshToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/getAlby/lndhub.go/lib/service"
|
||||
@@ -20,7 +19,7 @@ func NewBalanceController(svc *service.LndhubService) *BalanceController {
|
||||
// Balance : Balance Controller
|
||||
func (controller *BalanceController) Balance(c echo.Context) error {
|
||||
userId := c.Get("UserID").(int64)
|
||||
balance, err := controller.svc.CurrentUserBalance(context.TODO(), userId)
|
||||
balance, err := controller.svc.CurrentUserBalance(c.Request().Context(), userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func (controller *CheckPaymentController) CheckPayment(c echo.Context) error {
|
||||
userId := c.Get("UserID").(int64)
|
||||
rHash := c.Param("payment_hash")
|
||||
|
||||
invoice, err := controller.svc.FindInvoiceByPaymentHash(userId, rHash)
|
||||
invoice, err := controller.svc.FindInvoiceByPaymentHash(c.Request().Context(), userId, rHash)
|
||||
|
||||
// Probably we did not find the invoice
|
||||
if err != nil {
|
||||
|
||||
@@ -33,7 +33,7 @@ func (controller *CreateUserController) CreateUser(c echo.Context) error {
|
||||
if err := c.Bind(&body); err != nil {
|
||||
return err
|
||||
}
|
||||
user, err := controller.svc.CreateUser()
|
||||
user, err := controller.svc.CreateUser(c.Request().Context())
|
||||
//todo json response
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/getAlby/lndhub.go/lib/service"
|
||||
@@ -21,7 +20,7 @@ func NewGetInfoController(svc *service.LndhubService) *GetInfoController {
|
||||
func (controller *GetInfoController) GetInfo(c echo.Context) error {
|
||||
|
||||
// TODO: add some caching for this GetInfo call. No need to always hit the node
|
||||
info, err := controller.svc.GetInfo(context.TODO())
|
||||
info, err := controller.svc.GetInfo(c.Request().Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/getAlby/lndhub.go/lib"
|
||||
@@ -22,7 +21,7 @@ func NewGetTXSController(svc *service.LndhubService) *GetTXSController {
|
||||
func (controller *GetTXSController) GetTXS(c echo.Context) error {
|
||||
userId := c.Get("UserID").(int64)
|
||||
|
||||
invoices, err := controller.svc.InvoicesFor(context.TODO(), userId, "outgoing")
|
||||
invoices, err := controller.svc.InvoicesFor(c.Request().Context(), userId, "outgoing")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -47,7 +46,7 @@ func (controller *GetTXSController) GetTXS(c echo.Context) error {
|
||||
func (controller *GetTXSController) GetUserInvoices(c echo.Context) error {
|
||||
userId := c.Get("UserID").(int64)
|
||||
|
||||
invoices, err := controller.svc.InvoicesFor(context.TODO(), userId, "incoming")
|
||||
invoices, err := controller.svc.InvoicesFor(c.Request().Context(), userId, "incoming")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package controllers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
@@ -72,11 +71,11 @@ func (controller *HomeController) QR(c echo.Context) error {
|
||||
}
|
||||
|
||||
func (controller *HomeController) Home(c echo.Context) error {
|
||||
info, err := controller.svc.GetInfo(context.TODO())
|
||||
info, err := controller.svc.GetInfo(c.Request().Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
channels, err := controller.svc.LndClient.ListChannels(context.TODO(), &lnrpc.ListChannelsRequest{})
|
||||
channels, err := controller.svc.LndClient.ListChannels(c.Request().Context(), &lnrpc.ListChannelsRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -58,12 +57,12 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
|
||||
}
|
||||
*/
|
||||
|
||||
invoice, err := controller.svc.AddOutgoingInvoice(userID, paymentRequest, decodedPaymentRequest)
|
||||
invoice, err := controller.svc.AddOutgoingInvoice(c.Request().Context(), userID, paymentRequest, decodedPaymentRequest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
currentBalance, err := controller.svc.CurrentUserBalance(context.TODO(), userID)
|
||||
currentBalance, err := controller.svc.CurrentUserBalance(c.Request().Context(), userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -74,7 +73,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
|
||||
return c.JSON(http.StatusBadRequest, responses.NotEnoughBalanceError)
|
||||
}
|
||||
|
||||
sendPaymentResponse, err := controller.svc.PayInvoice(invoice)
|
||||
sendPaymentResponse, err := controller.svc.PayInvoice(c.Request().Context(), invoice)
|
||||
if err != nil {
|
||||
c.Logger().Errorf("Payment failed: %v", err)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
Reference in New Issue
Block a user