mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-23 23:55:02 +01:00
chore: add missing logs
This commit is contained in:
@@ -50,6 +50,7 @@ func AddInvoice(c echo.Context, svc *service.LndhubService, userID int64) error
|
|||||||
|
|
||||||
amount, err := svc.ParseInt(body.Amount)
|
amount, err := svc.ParseInt(body.Amount)
|
||||||
if err != nil || amount < 0 {
|
if err != nil || amount < 0 {
|
||||||
|
c.Logger().Errorf("Invalid amount %v for user_id:%v error: %v", amount, userID, err)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +64,8 @@ func AddInvoice(c echo.Context, svc *service.LndhubService, userID int64) error
|
|||||||
if svc.Config.MaxAccountBalance > 0 {
|
if svc.Config.MaxAccountBalance > 0 {
|
||||||
currentBalance, err := svc.CurrentUserBalance(c.Request().Context(), userID)
|
currentBalance, err := svc.CurrentUserBalance(c.Request().Context(), userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, responses.GeneralServerError)
|
c.Logger().Errorf("Error fetching balance for user_id:%v error: %v", userID, err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
if currentBalance+amount > svc.Config.MaxAccountBalance {
|
if currentBalance+amount > svc.Config.MaxAccountBalance {
|
||||||
c.Logger().Errorf("Max account balance exceeded for user_id:%v (balance:%v + amount:%v)", userID, currentBalance, amount)
|
c.Logger().Errorf("Max account balance exceeded for user_id:%v (balance:%v + amount:%v)", userID, currentBalance, amount)
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ func (controller *AuthController) Auth(c echo.Context) error {
|
|||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
if err := c.Validate(&body); err != nil {
|
if err := c.Validate(&body); err != nil {
|
||||||
|
c.Logger().Errorf("Failed to validate auth user request body: %v", err)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +57,8 @@ func (controller *AuthController) Auth(c echo.Context) error {
|
|||||||
// To support Swagger we also look in the Form data
|
// To support Swagger we also look in the Form data
|
||||||
params, err := c.FormParams()
|
params, err := c.FormParams()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to get form parameters: %v", err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
login := params.Get("login")
|
login := params.Get("login")
|
||||||
password := params.Get("password")
|
password := params.Get("password")
|
||||||
@@ -69,8 +71,10 @@ func (controller *AuthController) Auth(c echo.Context) error {
|
|||||||
accessToken, refreshToken, err := controller.svc.GenerateToken(c.Request().Context(), body.Login, body.Password, body.RefreshToken)
|
accessToken, refreshToken, err := controller.svc.GenerateToken(c.Request().Context(), body.Login, body.Password, body.RefreshToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == responses.AccountDeactivatedError.Message {
|
if err.Error() == responses.AccountDeactivatedError.Message {
|
||||||
|
c.Logger().Errorf("Account Deactivated for user: %s", body.Login)
|
||||||
return c.JSON(http.StatusUnauthorized, responses.AccountDeactivatedError)
|
return c.JSON(http.StatusUnauthorized, responses.AccountDeactivatedError)
|
||||||
}
|
}
|
||||||
|
c.Logger().Errorf("Authentication error for user: %s error: %v", body.Login, err)
|
||||||
return c.JSON(http.StatusUnauthorized, responses.BadAuthError)
|
return c.JSON(http.StatusUnauthorized, responses.BadAuthError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/getAlby/lndhub.go/lib/responses"
|
||||||
"github.com/getAlby/lndhub.go/lib/service"
|
"github.com/getAlby/lndhub.go/lib/service"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@@ -26,7 +27,8 @@ func (controller *BalanceController) Balance(c echo.Context) error {
|
|||||||
userId := c.Get("UserID").(int64)
|
userId := c.Get("UserID").(int64)
|
||||||
balance, err := controller.svc.CurrentUserBalance(c.Request().Context(), userId)
|
balance, err := controller.svc.CurrentUserBalance(c.Request().Context(), userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to retrieve user balance for user id: %v error: %v", userId, err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
return c.JSON(http.StatusOK, &BalanceResponse{
|
return c.JSON(http.StatusOK, &BalanceResponse{
|
||||||
BTC: struct{ AvailableBalance int64 }{
|
BTC: struct{ AvailableBalance int64 }{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/getAlby/lndhub.go/lib/responses"
|
||||||
"github.com/getAlby/lndhub.go/lib/service"
|
"github.com/getAlby/lndhub.go/lib/service"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@@ -77,7 +78,8 @@ func (controller *GetInfoController) GetInfo(c echo.Context) error {
|
|||||||
|
|
||||||
info, err := controller.svc.GetInfo(c.Request().Context())
|
info, err := controller.svc.GetInfo(c.Request().Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to retrieve info: %v", err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
if controller.svc.Config.CustomName != "" {
|
if controller.svc.Config.CustomName != "" {
|
||||||
info.Alias = controller.svc.Config.CustomName
|
info.Alias = controller.svc.Config.CustomName
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/getAlby/lndhub.go/common"
|
"github.com/getAlby/lndhub.go/common"
|
||||||
"github.com/getAlby/lndhub.go/lib"
|
"github.com/getAlby/lndhub.go/lib"
|
||||||
|
"github.com/getAlby/lndhub.go/lib/responses"
|
||||||
"github.com/getAlby/lndhub.go/lib/service"
|
"github.com/getAlby/lndhub.go/lib/service"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@@ -51,7 +52,8 @@ func (controller *GetTXSController) GetTXS(c echo.Context) error {
|
|||||||
|
|
||||||
invoices, err := controller.svc.InvoicesFor(c.Request().Context(), userId, common.InvoiceTypeOutgoing)
|
invoices, err := controller.svc.InvoicesFor(c.Request().Context(), userId, common.InvoiceTypeOutgoing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to retrieve transactions: %v", err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
response := make([]OutgoingInvoice, len(invoices))
|
response := make([]OutgoingInvoice, len(invoices))
|
||||||
@@ -78,7 +80,8 @@ func (controller *GetTXSController) GetUserInvoices(c echo.Context) error {
|
|||||||
|
|
||||||
invoices, err := controller.svc.InvoicesFor(c.Request().Context(), userId, common.InvoiceTypeIncoming)
|
invoices, err := controller.svc.InvoicesFor(c.Request().Context(), userId, common.InvoiceTypeIncoming)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to retrieve invoices for user_id: %v error: %v", userId, err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
response := make([]IncomingInvoice, len(invoices))
|
response := make([]IncomingInvoice, len(invoices))
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/getAlby/lndhub.go/lib/responses"
|
||||||
"github.com/getAlby/lndhub.go/lib/service"
|
"github.com/getAlby/lndhub.go/lib/service"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
@@ -66,7 +67,8 @@ func (controller *HomeController) QR(c echo.Context) error {
|
|||||||
url := fmt.Sprintf("bluewallet:setlndhuburl?url=%s", encoded)
|
url := fmt.Sprintf("bluewallet:setlndhuburl?url=%s", encoded)
|
||||||
png, err := qrcode.Encode(url, qrcode.Medium, 256)
|
png, err := qrcode.Encode(url, qrcode.Medium, 256)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Error encoding QR: %v", err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
return c.Blob(http.StatusOK, "image/png", png)
|
return c.Blob(http.StatusOK, "image/png", png)
|
||||||
}
|
}
|
||||||
@@ -74,16 +76,19 @@ func (controller *HomeController) QR(c echo.Context) error {
|
|||||||
func (controller *HomeController) Home(c echo.Context) error {
|
func (controller *HomeController) Home(c echo.Context) error {
|
||||||
info, err := controller.svc.GetInfo(c.Request().Context())
|
info, err := controller.svc.GetInfo(c.Request().Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to retrieve info: %v", err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
channels, err := controller.svc.LndClient.ListChannels(c.Request().Context(), &lnrpc.ListChannelsRequest{})
|
channels, err := controller.svc.LndClient.ListChannels(c.Request().Context(), &lnrpc.ListChannelsRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to list channels: %v", err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl, err := template.New("index").Parse(controller.html)
|
tmpl, err := template.New("index").Parse(controller.html)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to parse template: %v", err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
// See original code: https://github.com/BlueWallet/LndHub/blob/master/controllers/website.js#L32
|
// See original code: https://github.com/BlueWallet/LndHub/blob/master/controllers/website.js#L32
|
||||||
maxChanCapacity := -1
|
maxChanCapacity := -1
|
||||||
@@ -117,7 +122,8 @@ func (controller *HomeController) Home(c echo.Context) error {
|
|||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err = tmpl.Execute(&buf, content)
|
err = tmpl.Execute(&buf, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to parse template: %v", err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=300, stale-if-error=21600") // cache for 5 minutes or if error for 6 hours max
|
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=300, stale-if-error=21600") // cache for 5 minutes or if error for 6 hours max
|
||||||
return c.HTMLBlob(http.StatusOK, buf.Bytes())
|
return c.HTMLBlob(http.StatusOK, buf.Bytes())
|
||||||
|
|||||||
@@ -83,7 +83,8 @@ func (controller *KeySendController) KeySend(c echo.Context) error {
|
|||||||
|
|
||||||
ok, err := controller.svc.BalanceCheck(c.Request().Context(), lnPayReq, userID)
|
ok, err := controller.svc.BalanceCheck(c.Request().Context(), lnPayReq, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to check balance user_id: %v error: %v", userID, err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
c.Logger().Errorf("User does not have enough balance user_id:%v amount:%v", userID, lnPayReq.PayReq.NumSatoshis)
|
c.Logger().Errorf("User does not have enough balance user_id:%v amount:%v", userID, lnPayReq.PayReq.NumSatoshis)
|
||||||
@@ -91,7 +92,8 @@ func (controller *KeySendController) KeySend(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
invoice, err := controller.svc.AddOutgoingInvoice(c.Request().Context(), userID, "", lnPayReq)
|
invoice, err := controller.svc.AddOutgoingInvoice(c.Request().Context(), userID, "", lnPayReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Error saving invoice user_id: %v error: %v", userID, err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
if _, err := hex.DecodeString(invoice.DestinationPubkeyHex); err != nil || len(invoice.DestinationPubkeyHex) != common.DestinationPubkeyHexSize {
|
if _, err := hex.DecodeString(invoice.DestinationPubkeyHex); err != nil || len(invoice.DestinationPubkeyHex) != common.DestinationPubkeyHexSize {
|
||||||
c.Logger().Errorf("Invalid destination pubkey hex user_id:%v pubkey:%v", userID, len(invoice.DestinationPubkeyHex))
|
c.Logger().Errorf("Invalid destination pubkey hex user_id:%v pubkey:%v", userID, len(invoice.DestinationPubkeyHex))
|
||||||
@@ -101,6 +103,7 @@ func (controller *KeySendController) KeySend(c echo.Context) error {
|
|||||||
for key, value := range reqBody.CustomRecords {
|
for key, value := range reqBody.CustomRecords {
|
||||||
intKey, err := strconv.Atoi(key)
|
intKey, err := strconv.Atoi(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
c.Logger().Errorf("Invalid custom records user_id: %v error: %v", userID, err)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
invoice.DestinationCustomRecords[uint64(intKey)] = []byte(value)
|
invoice.DestinationCustomRecords[uint64(intKey)] = []byte(value)
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
|
|||||||
if decodedPaymentRequest.NumSatoshis == 0 {
|
if decodedPaymentRequest.NumSatoshis == 0 {
|
||||||
amt, err := controller.svc.ParseInt(reqBody.Amount)
|
amt, err := controller.svc.ParseInt(reqBody.Amount)
|
||||||
if err != nil || amt <= 0 {
|
if err != nil || amt <= 0 {
|
||||||
|
c.Logger().Errorf("Invalid amount in payment request user_id:%v error: %v", userID, err)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
lnPayReq.PayReq.NumSatoshis = amt
|
lnPayReq.PayReq.NumSatoshis = amt
|
||||||
@@ -91,7 +92,8 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
|
|||||||
|
|
||||||
ok, err := controller.svc.BalanceCheck(c.Request().Context(), lnPayReq, userID)
|
ok, err := controller.svc.BalanceCheck(c.Request().Context(), lnPayReq, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Error checking user balance user_id:%v error: %v", userID, err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.GeneralServerError)
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
c.Logger().Errorf("User does not have enough balance user_id:%v amount:%v", userID, lnPayReq.PayReq.NumSatoshis)
|
c.Logger().Errorf("User does not have enough balance user_id:%v amount:%v", userID, lnPayReq.PayReq.NumSatoshis)
|
||||||
@@ -100,7 +102,8 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
|
|||||||
|
|
||||||
invoice, err := controller.svc.AddOutgoingInvoice(c.Request().Context(), userID, paymentRequest, lnPayReq)
|
invoice, err := controller.svc.AddOutgoingInvoice(c.Request().Context(), userID, paymentRequest, lnPayReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Error saving invoice user_id:%v payment_request:%v", userID, paymentRequest)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.GeneralServerError)
|
||||||
}
|
}
|
||||||
sendPaymentResponse, err := controller.svc.PayInvoice(c.Request().Context(), invoice)
|
sendPaymentResponse, err := controller.svc.PayInvoice(c.Request().Context(), invoice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package v2controllers
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/getAlby/lndhub.go/lib/responses"
|
||||||
"github.com/getAlby/lndhub.go/lib/service"
|
"github.com/getAlby/lndhub.go/lib/service"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@@ -37,7 +38,8 @@ func (controller *BalanceController) Balance(c echo.Context) error {
|
|||||||
userId := c.Get("UserID").(int64)
|
userId := c.Get("UserID").(int64)
|
||||||
balance, err := controller.svc.CurrentUserBalance(c.Request().Context(), userId)
|
balance, err := controller.svc.CurrentUserBalance(c.Request().Context(), userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Error fetching balance for user_id:%v error: %v", userId, err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
return c.JSON(http.StatusOK, &BalanceResponse{
|
return c.JSON(http.StatusOK, &BalanceResponse{
|
||||||
Balance: balance,
|
Balance: balance,
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ func (controller *InvoiceController) GetOutgoingInvoices(c echo.Context) error {
|
|||||||
|
|
||||||
invoices, err := controller.svc.InvoicesFor(c.Request().Context(), userId, common.InvoiceTypeOutgoing)
|
invoices, err := controller.svc.InvoicesFor(c.Request().Context(), userId, common.InvoiceTypeOutgoing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to retrieve outgoing invoices for user_id: %v error: %v", userId, err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
response := make([]Invoice, len(invoices))
|
response := make([]Invoice, len(invoices))
|
||||||
@@ -98,7 +99,8 @@ func (controller *InvoiceController) GetIncomingInvoices(c echo.Context) error {
|
|||||||
|
|
||||||
invoices, err := controller.svc.InvoicesFor(c.Request().Context(), userId, common.InvoiceTypeIncoming)
|
invoices, err := controller.svc.InvoicesFor(c.Request().Context(), userId, common.InvoiceTypeIncoming)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
c.Logger().Errorf("Failed to retrieve incoming invoices for user_id: %v : %v", userId, err)
|
||||||
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
response := make([]Invoice, len(invoices))
|
response := make([]Invoice, len(invoices))
|
||||||
|
|||||||
@@ -193,6 +193,7 @@ func (controller *KeySendController) SingleKeySend(c echo.Context, reqBody *KeyS
|
|||||||
for key, value := range customRecords {
|
for key, value := range customRecords {
|
||||||
intKey, err := strconv.Atoi(key)
|
intKey, err := strconv.Atoi(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
c.Logger().Errorf("Failed to parse custom records: user_id:%v error: %v", userID, err)
|
||||||
return nil, &responses.BadArgumentsError
|
return nil, &responses.BadArgumentsError
|
||||||
}
|
}
|
||||||
invoice.DestinationCustomRecords[uint64(intKey)] = []byte(value)
|
invoice.DestinationCustomRecords[uint64(intKey)] = []byte(value)
|
||||||
|
|||||||
@@ -86,12 +86,14 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
|
|||||||
if decodedPaymentRequest.NumSatoshis == 0 {
|
if decodedPaymentRequest.NumSatoshis == 0 {
|
||||||
amt, err := controller.svc.ParseInt(reqBody.Amount)
|
amt, err := controller.svc.ParseInt(reqBody.Amount)
|
||||||
if err != nil || amt <= 0 {
|
if err != nil || amt <= 0 {
|
||||||
|
c.Logger().Errorf("Invalid amount in payment request user_id:%v error: %v", userID, err)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
lnPayReq.PayReq.NumSatoshis = amt
|
lnPayReq.PayReq.NumSatoshis = amt
|
||||||
}
|
}
|
||||||
ok, err := controller.svc.BalanceCheck(c.Request().Context(), lnPayReq, userID)
|
ok, err := controller.svc.BalanceCheck(c.Request().Context(), lnPayReq, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
c.Logger().Errorf("Error checking user balance user_id:%v error: %v", userID, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -100,6 +102,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
invoice, err := controller.svc.AddOutgoingInvoice(c.Request().Context(), userID, paymentRequest, lnPayReq)
|
invoice, err := controller.svc.AddOutgoingInvoice(c.Request().Context(), userID, paymentRequest, lnPayReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
c.Logger().Errorf("Error saving invoice user_id:%v payment_request:%v", userID, paymentRequest)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sendPaymentResponse, err := controller.svc.PayInvoice(c.Request().Context(), invoice)
|
sendPaymentResponse, err := controller.svc.PayInvoice(c.Request().Context(), invoice)
|
||||||
|
|||||||
Reference in New Issue
Block a user