mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-23 15:44:51 +01:00
json logging
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/getAlby/lndhub.go/lib/service"
|
"github.com/getAlby/lndhub.go/lib/service"
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/labstack/gommon/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddInvoiceController : Add invoice controller struct
|
// AddInvoiceController : Add invoice controller struct
|
||||||
@@ -50,7 +51,14 @@ 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)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"error": err,
|
||||||
|
"message": "invalid amount",
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
"amount": amount,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +72,13 @@ 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 {
|
||||||
c.Logger().Errorf("Error fetching balance for user_id:%v error: %v", userID, err)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "error fetching balance",
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
"error": err,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
if currentBalance+amount > svc.Config.MaxAccountBalance {
|
if currentBalance+amount > svc.Config.MaxAccountBalance {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/getAlby/lndhub.go/lib/responses"
|
"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/labstack/gommon/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AuthController : AuthController struct
|
// AuthController : AuthController struct
|
||||||
@@ -49,7 +50,12 @@ 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)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"error": err,
|
||||||
|
"message": "invalid request body",
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +63,12 @@ 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 {
|
||||||
c.Logger().Errorf("Failed to get form parameters: %v", err)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "invalid form parameters",
|
||||||
|
"error": err,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
login := params.Get("login")
|
login := params.Get("login")
|
||||||
@@ -71,10 +82,21 @@ 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)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "account deactivated",
|
||||||
|
"user_login": 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)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "authentication error",
|
||||||
|
"user_login": body.Login,
|
||||||
|
"error": err,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusUnauthorized, responses.BadAuthError)
|
return c.JSON(http.StatusUnauthorized, responses.BadAuthError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/getAlby/lndhub.go/lib/responses"
|
"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/labstack/gommon/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BalanceController : BalanceController struct
|
// BalanceController : BalanceController struct
|
||||||
@@ -27,7 +28,13 @@ 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 {
|
||||||
c.Logger().Errorf("Failed to retrieve user balance for user id: %v error: %v", userId, err)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "failed to retrieve user balance",
|
||||||
|
"lndhub_user_id": userId,
|
||||||
|
"error": err,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
return c.JSON(http.StatusOK, &BalanceResponse{
|
return c.JSON(http.StatusOK, &BalanceResponse{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Copy over struct for swagger purposes
|
// Copy over struct for swagger purposes
|
||||||
type GetInfoResponse struct {
|
type GetInfoResponse struct {
|
||||||
// The version of the LND software that the node is running.
|
// The version of the LND software that the node is running.
|
||||||
Version string `protobuf:"bytes,14,opt,name=version,proto3" json:"version,omitempty"`
|
Version string `protobuf:"bytes,14,opt,name=version,proto3" json:"version,omitempty"`
|
||||||
@@ -78,7 +78,7 @@ 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 {
|
||||||
c.Logger().Errorf("Failed to retrieve info: %v", err)
|
c.Logger().Errorf("failed to retrieve info: %v", err)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
if controller.svc.Config.CustomName != "" {
|
if controller.svc.Config.CustomName != "" {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/getAlby/lndhub.go/lib/responses"
|
"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/labstack/gommon/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetTXSController : GetTXSController struct
|
// GetTXSController : GetTXSController struct
|
||||||
@@ -52,7 +53,13 @@ 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 {
|
||||||
c.Logger().Errorf("Failed to retrieve transactions: %v", err)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "failed to get transactions",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userId,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +87,13 @@ 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 {
|
||||||
c.Logger().Errorf("Failed to retrieve invoices for user_id: %v error: %v", userId, err)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "failed to get invoices",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userId,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/getAlby/lndhub.go/lnd"
|
"github.com/getAlby/lndhub.go/lnd"
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/labstack/gommon/log"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -83,7 +84,13 @@ 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 {
|
||||||
c.Logger().Errorf("Failed to check balance user_id: %v error: %v", userID, err)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "failed to check balance",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -92,7 +99,13 @@ 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 {
|
||||||
c.Logger().Errorf("Error saving invoice user_id: %v error: %v", userID, err)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "failed to add invoice",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
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 {
|
||||||
@@ -103,7 +116,13 @@ 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)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "invalid custom records",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
},
|
||||||
|
)
|
||||||
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)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
sentryecho "github.com/getsentry/sentry-go/echo"
|
sentryecho "github.com/getsentry/sentry-go/echo"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/labstack/gommon/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PayInvoiceController : Pay invoice controller struct
|
// PayInvoiceController : Pay invoice controller struct
|
||||||
@@ -57,7 +58,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
|
|||||||
paymentRequest = strings.ToLower(paymentRequest)
|
paymentRequest = strings.ToLower(paymentRequest)
|
||||||
decodedPaymentRequest, err := controller.svc.DecodePaymentRequest(c.Request().Context(), paymentRequest)
|
decodedPaymentRequest, err := controller.svc.DecodePaymentRequest(c.Request().Context(), paymentRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(),"invoice not for current active network") {
|
if strings.Contains(err.Error(), "invoice not for current active network") {
|
||||||
c.Logger().Errorf("Incorrect network user_id:%v error: %v", userID, err)
|
c.Logger().Errorf("Incorrect network user_id:%v error: %v", userID, err)
|
||||||
return c.JSON(http.StatusBadRequest, responses.IncorrectNetworkError)
|
return c.JSON(http.StatusBadRequest, responses.IncorrectNetworkError)
|
||||||
}
|
}
|
||||||
@@ -77,7 +78,13 @@ 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)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "invalid amount",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
lnPayReq.PayReq.NumSatoshis = amt
|
lnPayReq.PayReq.NumSatoshis = amt
|
||||||
@@ -92,7 +99,13 @@ 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 {
|
||||||
c.Logger().Errorf("Error checking user balance user_id:%v error: %v", userID, err)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "error checking balance",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.GeneralServerError)
|
return c.JSON(http.StatusBadRequest, responses.GeneralServerError)
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -102,7 +115,13 @@ 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)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "error adding invoice",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.GeneralServerError)
|
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)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/getAlby/lndhub.go/lib/responses"
|
"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/labstack/gommon/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BalanceController : BalanceController struct
|
// BalanceController : BalanceController struct
|
||||||
@@ -38,7 +39,13 @@ 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 {
|
||||||
c.Logger().Errorf("Error fetching balance for user_id:%v error: %v", userId, err)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "failed to retrieve user balance",
|
||||||
|
"lndhub_user_id": userId,
|
||||||
|
"error": err,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
return c.JSON(http.StatusOK, &BalanceResponse{
|
return c.JSON(http.StatusOK, &BalanceResponse{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/getAlby/lndhub.go/lib/service"
|
"github.com/getAlby/lndhub.go/lib/service"
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/labstack/gommon/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InvoiceController : Add invoice controller struct
|
// InvoiceController : Add invoice controller struct
|
||||||
@@ -55,7 +56,13 @@ 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 {
|
||||||
c.Logger().Errorf("Failed to retrieve outgoing invoices for user_id: %v error: %v", userId, err)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "failed to get invoices",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userId,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +106,13 @@ 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 {
|
||||||
c.Logger().Errorf("Failed to retrieve incoming invoices for user_id: %v : %v", userId, err)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "failed to get invoices",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userId,
|
||||||
|
},
|
||||||
|
)
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/getAlby/lndhub.go/lnd"
|
"github.com/getAlby/lndhub.go/lnd"
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/labstack/gommon/log"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -193,7 +194,13 @@ 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)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "invalid custom records",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
},
|
||||||
|
)
|
||||||
return nil, &responses.BadArgumentsError
|
return nil, &responses.BadArgumentsError
|
||||||
}
|
}
|
||||||
invoice.DestinationCustomRecords[uint64(intKey)] = []byte(value)
|
invoice.DestinationCustomRecords[uint64(intKey)] = []byte(value)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
sentryecho "github.com/getsentry/sentry-go/echo"
|
sentryecho "github.com/getsentry/sentry-go/echo"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/labstack/gommon/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PayInvoiceController : Pay invoice controller struct
|
// PayInvoiceController : Pay invoice controller struct
|
||||||
@@ -66,7 +67,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
|
|||||||
paymentRequest = strings.ToLower(paymentRequest)
|
paymentRequest = strings.ToLower(paymentRequest)
|
||||||
decodedPaymentRequest, err := controller.svc.DecodePaymentRequest(c.Request().Context(), paymentRequest)
|
decodedPaymentRequest, err := controller.svc.DecodePaymentRequest(c.Request().Context(), paymentRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(),"invoice not for current active network") {
|
if strings.Contains(err.Error(), "invoice not for current active network") {
|
||||||
c.Logger().Errorf("Incorrect network user_id:%v error: %v", userID, err)
|
c.Logger().Errorf("Incorrect network user_id:%v error: %v", userID, err)
|
||||||
return c.JSON(http.StatusBadRequest, responses.IncorrectNetworkError)
|
return c.JSON(http.StatusBadRequest, responses.IncorrectNetworkError)
|
||||||
}
|
}
|
||||||
@@ -86,14 +87,26 @@ 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)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "invalid amount",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
},
|
||||||
|
)
|
||||||
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)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "error checking balance",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
},
|
||||||
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -102,7 +115,13 @@ 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)
|
c.Logger().Errorj(
|
||||||
|
log.JSON{
|
||||||
|
"message": "error adding invoice",
|
||||||
|
"error": err,
|
||||||
|
"lndhub_user_id": userID,
|
||||||
|
},
|
||||||
|
)
|
||||||
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