diff --git a/cmd/server/main.go b/cmd/server/main.go index 9d6c9e3..059a346 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -153,17 +153,9 @@ func main() { logMw := transport.CreateLoggingMiddleware(logger) // strict rate limit for requests for sending payments strictRateLimitMiddleware := transport.CreateRateLimitMiddleware(c.StrictRateLimit, c.BurstRateLimit) - - limits := &lnd.Limits{ - MaxSendVolume: c.MaxSendVolume, - MaxSendAmount: c.MaxSendAmount, - MaxReceiveVolume: c.MaxReceiveVolume, - MaxReceiveAmount: c.MaxReceiveAmount, - MaxAccountBalance: c.MaxAccountBalance, - } - secured := e.Group("", tokens.Middleware(c.JWTSecret, limits), logMw) - securedWithStrictRateLimit := e.Group("", tokens.Middleware(c.JWTSecret, limits), strictRateLimitMiddleware, logMw) + secured := e.Group("", tokens.Middleware(c.JWTSecret), logMw) + securedWithStrictRateLimit := e.Group("", tokens.Middleware(c.JWTSecret), strictRateLimitMiddleware, logMw) transport.RegisterLegacyEndpoints(svc, e, secured, securedWithStrictRateLimit, strictRateLimitMiddleware, tokens.AdminTokenMiddleware(c.AdminToken), logMw) transport.RegisterV2Endpoints(svc, e, secured, securedWithStrictRateLimit, strictRateLimitMiddleware, tokens.AdminTokenMiddleware(c.AdminToken), logMw) diff --git a/controllers/addinvoice.ctrl.go b/controllers/addinvoice.ctrl.go index 6da8de6..00ba960 100644 --- a/controllers/addinvoice.ctrl.go +++ b/controllers/addinvoice.ctrl.go @@ -37,7 +37,7 @@ func (controller *AddInvoiceController) AddInvoice(c echo.Context) error { func AddInvoice(c echo.Context, svc *service.LndhubService, userID int64) error { var body AddInvoiceRequestBody - limits := svc.GetLimitsFromContext(c) + limits := svc.GetLimits(c) if err := c.Bind(&body); err != nil { c.Logger().Errorf("Failed to load addinvoice request body: %v", err) diff --git a/controllers/keysend.ctrl.go b/controllers/keysend.ctrl.go index dff2887..4ee3d70 100644 --- a/controllers/keysend.ctrl.go +++ b/controllers/keysend.ctrl.go @@ -46,7 +46,7 @@ type KeySendResponseBody struct { func (controller *KeySendController) KeySend(c echo.Context) error { userID := c.Get("UserID").(int64) - limits := controller.svc.GetLimitsFromContext(c) + limits := controller.svc.GetLimits(c) reqBody := KeySendRequestBody{} if err := c.Bind(&reqBody); err != nil { c.Logger().Errorf("Failed to load keysend request body: %v", err) diff --git a/controllers/payinvoice.ctrl.go b/controllers/payinvoice.ctrl.go index f6c2634..7f8e511 100644 --- a/controllers/payinvoice.ctrl.go +++ b/controllers/payinvoice.ctrl.go @@ -43,7 +43,7 @@ type PayInvoiceResponseBody struct { func (controller *PayInvoiceController) PayInvoice(c echo.Context) error { userID := c.Get("UserID").(int64) - limits := controller.svc.GetLimitsFromContext(c) + limits := controller.svc.GetLimits(c) reqBody := PayInvoiceRequestBody{} if err := c.Bind(&reqBody); err != nil { c.Logger().Errorf("Failed to load payinvoice request body: user_id:%v error: %v", userID, err) diff --git a/controllers_v2/invoice.ctrl.go b/controllers_v2/invoice.ctrl.go index 973a364..af20331 100644 --- a/controllers_v2/invoice.ctrl.go +++ b/controllers_v2/invoice.ctrl.go @@ -165,7 +165,7 @@ type AddInvoiceResponseBody struct { // @Security OAuth2Password func (controller *InvoiceController) AddInvoice(c echo.Context) error { userID := c.Get("UserID").(int64) - limits := controller.svc.GetLimitsFromContext(c) + limits := controller.svc.GetLimits(c) var body AddInvoiceRequestBody diff --git a/controllers_v2/keysend.ctrl.go b/controllers_v2/keysend.ctrl.go index 2db1ec0..9df4410 100644 --- a/controllers_v2/keysend.ctrl.go +++ b/controllers_v2/keysend.ctrl.go @@ -71,7 +71,7 @@ type KeySendResponseBody struct { // @Security OAuth2Password func (controller *KeySendController) KeySend(c echo.Context) error { userID := c.Get("UserID").(int64) - limits := controller.svc.GetLimitsFromContext(c) + limits := controller.svc.GetLimits(c) reqBody := KeySendRequestBody{} if err := c.Bind(&reqBody); err != nil { c.Logger().Errorf("Failed to load keysend request body: %v", err) @@ -109,7 +109,7 @@ func (controller *KeySendController) KeySend(c echo.Context) error { // @Security OAuth2Password func (controller *KeySendController) MultiKeySend(c echo.Context) error { userID := c.Get("UserID").(int64) - limits := controller.svc.GetLimitsFromContext(c) + limits := controller.svc.GetLimits(c) reqBody := MultiKeySendRequestBody{} if err := c.Bind(&reqBody); err != nil { c.Logger().Errorf("Failed to load keysend request body: %v", err) diff --git a/controllers_v2/payinvoice.ctrl.go b/controllers_v2/payinvoice.ctrl.go index 3bbc6bc..9d0647d 100644 --- a/controllers_v2/payinvoice.ctrl.go +++ b/controllers_v2/payinvoice.ctrl.go @@ -52,7 +52,7 @@ type PayInvoiceResponseBody struct { // @Security OAuth2Password func (controller *PayInvoiceController) PayInvoice(c echo.Context) error { userID := c.Get("UserID").(int64) - limits := controller.svc.GetLimitsFromContext(c) + limits := controller.svc.GetLimits(c) reqBody := PayInvoiceRequestBody{} if err := c.Bind(&reqBody); err != nil { c.Logger().Errorf("Failed to load payinvoice request body: user_id:%v error: %v", userID, err) diff --git a/go.mod b/go.mod index 9c20690..1f12b6f 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/lightningnetwork/lnd v0.16.4-beta.rc1 github.com/rabbitmq/amqp091-go v1.8.1 github.com/rs/zerolog v1.29.1 + github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.8.4 github.com/uptrace/bun v1.1.14 github.com/uptrace/bun/dialect/pgdialect v1.1.14 @@ -137,7 +138,6 @@ require ( github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rogpeppe/fastuuid v1.2.0 // indirect github.com/secure-systems-lab/go-securesystemslib v0.6.0 // indirect - github.com/sirupsen/logrus v1.9.3 // indirect github.com/soheilhy/cmux v0.1.5 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.0 // indirect diff --git a/integration_tests/checkpayment_test.go b/integration_tests/checkpayment_test.go index 67a379f..86b9da9 100644 --- a/integration_tests/checkpayment_test.go +++ b/integration_tests/checkpayment_test.go @@ -15,7 +15,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" @@ -57,7 +56,7 @@ func (suite *CheckPaymentTestSuite) SetupSuite() { assert.Equal(suite.T(), 1, len(userTokens)) suite.userLogin = users[0] suite.userToken = userTokens[0] - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) suite.echo.POST("/payinvoice", controllers.NewPayInvoiceController(suite.service).PayInvoice) suite.echo.GET("/checkpayment/:payment_hash", controllers.NewCheckPaymentController(suite.service).CheckPayment) diff --git a/integration_tests/getinfo_test.go b/integration_tests/getinfo_test.go index 2d57b0b..b6d0719 100644 --- a/integration_tests/getinfo_test.go +++ b/integration_tests/getinfo_test.go @@ -13,7 +13,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/lightningnetwork/lnd/lnrpc" @@ -48,7 +47,7 @@ func (suite *GetInfoTestSuite) SetupSuite() { assert.Equal(suite.T(), 1, len(userTokens)) suite.userLogin = users[0] suite.userToken = userTokens[0] - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.GET("/getinfo", controllers.NewGetInfoController(svc).GetInfo) } diff --git a/integration_tests/gettxs_test.go b/integration_tests/gettxs_test.go index 206158a..a1a6f05 100644 --- a/integration_tests/gettxs_test.go +++ b/integration_tests/gettxs_test.go @@ -15,7 +15,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" @@ -53,7 +52,7 @@ func (suite *GetTxTestSuite) SetupSuite() { e.HTTPErrorHandler = responses.HTTPErrorHandler e.Validator = &lib.CustomValidator{Validator: validator.New()} suite.echo = e - suite.echo.Use(tokens.Middleware([]byte(suite.Service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.Service.Config.JWTSecret))) suite.echo.GET("/gettxs", controllers.NewGetTXSController(suite.Service).GetTXS) suite.echo.GET("/getuserinvoices", controllers.NewGetTXSController(svc).GetUserInvoices) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.Service).AddInvoice) diff --git a/integration_tests/hodl_invoice_test.go b/integration_tests/hodl_invoice_test.go index 8a990c2..3e58e28 100644 --- a/integration_tests/hodl_invoice_test.go +++ b/integration_tests/hodl_invoice_test.go @@ -14,7 +14,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/lightningnetwork/lnd/lnrpc" @@ -73,7 +72,7 @@ func (suite *HodlInvoiceSuite) SetupSuite() { suite.userLogin = users[0] suite.userToken = userTokens[0] suite.userToken2 = userTokens[1] - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.GET("/balance", controllers.NewBalanceController(suite.service).Balance) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) suite.echo.POST("/payinvoice", controllers.NewPayInvoiceController(suite.service).PayInvoice) diff --git a/integration_tests/incoming_payment_test.go b/integration_tests/incoming_payment_test.go index fe6c17f..aabf5d1 100644 --- a/integration_tests/incoming_payment_test.go +++ b/integration_tests/incoming_payment_test.go @@ -17,7 +17,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/labstack/gommon/random" @@ -72,7 +71,7 @@ func (suite *IncomingPaymentTestSuite) TestIncomingPayment() { req := httptest.NewRequest(http.MethodGet, "/balance", &buf) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", suite.userToken)) rec := httptest.NewRecorder() - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.GET("/balance", controllers.NewBalanceController(suite.service).Balance) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) suite.echo.ServeHTTP(rec, req) @@ -103,7 +102,7 @@ func (suite *IncomingPaymentTestSuite) TestIncomingPaymentZeroAmt() { req := httptest.NewRequest(http.MethodGet, "/balance", &buf) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", suite.userToken)) rec := httptest.NewRecorder() - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.GET("/balance", controllers.NewBalanceController(suite.service).Balance) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) suite.echo.ServeHTTP(rec, req) @@ -145,7 +144,7 @@ func (suite *IncomingPaymentTestSuite) TestIncomingPaymentKeysend() { req := httptest.NewRequest(http.MethodGet, "/balance", &buf) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", suite.userToken)) rec := httptest.NewRecorder() - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.GET("/balance", controllers.NewBalanceController(suite.service).Balance) suite.echo.GET("/getuserinvoices", controllers.NewGetTXSController(suite.service).GetUserInvoices) suite.echo.ServeHTTP(rec, req) diff --git a/integration_tests/internal_payment_test.go b/integration_tests/internal_payment_test.go index 8a95158..950a1dc 100644 --- a/integration_tests/internal_payment_test.go +++ b/integration_tests/internal_payment_test.go @@ -17,7 +17,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/lightningnetwork/lnd/lnrpc" @@ -71,7 +70,7 @@ func (suite *PaymentTestSuite) SetupSuite() { suite.bobLogin = users[1] suite.bobToken = userTokens[1] - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.GET("/balance", controllers.NewBalanceController(suite.service).Balance) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) suite.echo.POST("/payinvoice", controllers.NewPayInvoiceController(suite.service).PayInvoice) diff --git a/integration_tests/invoice_test.go b/integration_tests/invoice_test.go index c93d6fa..083671c 100644 --- a/integration_tests/invoice_test.go +++ b/integration_tests/invoice_test.go @@ -18,7 +18,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" @@ -52,7 +51,7 @@ func (suite *InvoiceTestSuite) SetupSuite() { suite.aliceLogin = users[0] suite.aliceToken = userTokens[0] suite.echo.POST("/invoice/:user_login", controllers.NewInvoiceController(svc).Invoice) - suite.echo.POST("/v2/invoices", v2controllers.NewInvoiceController(svc).AddInvoice, tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.POST("/v2/invoices", v2controllers.NewInvoiceController(svc).AddInvoice, tokens.Middleware([]byte(suite.service.Config.JWTSecret))) } func (suite *InvoiceTestSuite) TearDownTest() { diff --git a/integration_tests/keysend_failure_test.go b/integration_tests/keysend_failure_test.go index 880db57..25659c7 100644 --- a/integration_tests/keysend_failure_test.go +++ b/integration_tests/keysend_failure_test.go @@ -13,7 +13,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" @@ -73,7 +72,7 @@ func (suite *KeySendFailureTestSuite) SetupSuite() { assert.Equal(suite.T(), 1, len(userTokens)) suite.aliceLogin = users[0] suite.aliceToken = userTokens[0] - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) suite.echo.POST("/keysend", controllers.NewKeySendController(suite.service).KeySend) } diff --git a/integration_tests/keysend_test.go b/integration_tests/keysend_test.go index 9409d64..7ce7955 100644 --- a/integration_tests/keysend_test.go +++ b/integration_tests/keysend_test.go @@ -17,7 +17,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" @@ -61,7 +60,7 @@ func (suite *KeySendTestSuite) SetupSuite() { assert.Equal(suite.T(), 1, len(userTokens)) suite.aliceLogin = users[0] suite.aliceToken = userTokens[0] - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.GET("/balance", controllers.NewBalanceController(suite.service).Balance) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) suite.echo.POST("/payinvoice", controllers.NewPayInvoiceController(suite.service).PayInvoice) diff --git a/integration_tests/payment_failure_async_test.go b/integration_tests/payment_failure_async_test.go index 818e6be..edc8a1f 100644 --- a/integration_tests/payment_failure_async_test.go +++ b/integration_tests/payment_failure_async_test.go @@ -13,7 +13,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/lightningnetwork/lnd/lnrpc" @@ -70,7 +69,7 @@ func (suite *PaymentTestAsyncErrorsSuite) SetupSuite() { assert.Equal(suite.T(), 1, len(userTokens)) suite.userLogin = users[0] suite.userToken = userTokens[0] - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.GET("/balance", controllers.NewBalanceController(suite.service).Balance) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) suite.echo.POST("/payinvoice", controllers.NewPayInvoiceController(suite.service).PayInvoice) diff --git a/integration_tests/payment_failure_test.go b/integration_tests/payment_failure_test.go index 6d38ec6..eff222a 100644 --- a/integration_tests/payment_failure_test.go +++ b/integration_tests/payment_failure_test.go @@ -17,7 +17,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/lightningnetwork/lnd/lnrpc" @@ -72,7 +71,7 @@ func (suite *PaymentTestErrorsSuite) SetupSuite() { assert.Equal(suite.T(), 1, len(userTokens)) suite.userLogin = users[0] suite.userToken = userTokens[0] - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.GET("/balance", controllers.NewBalanceController(suite.service).Balance) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) suite.echo.POST("/payinvoice", controllers.NewPayInvoiceController(suite.service).PayInvoice) diff --git a/integration_tests/rabbitmq_test.go b/integration_tests/rabbitmq_test.go index 85f6b73..3d4570e 100644 --- a/integration_tests/rabbitmq_test.go +++ b/integration_tests/rabbitmq_test.go @@ -16,7 +16,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/lightningnetwork/lnd/lnrpc" @@ -65,7 +64,7 @@ func (suite *RabbitMQTestSuite) SetupSuite() { e.Validator = &lib.CustomValidator{Validator: validator.New()} suite.echo = e - suite.echo.Use(tokens.Middleware([]byte(suite.svc.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.svc.Config.JWTSecret))) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.svc).AddInvoice) suite.echo.POST("/payinvoice", controllers.NewPayInvoiceController(suite.svc).PayInvoice) go func() { diff --git a/integration_tests/subscription_start_test.go b/integration_tests/subscription_start_test.go index 3f2c84c..aea1ee4 100644 --- a/integration_tests/subscription_start_test.go +++ b/integration_tests/subscription_start_test.go @@ -56,7 +56,7 @@ func (suite *SubscriptionStartTestSuite) SetupSuite() { suite.echo = e suite.userLogin = users[0] suite.userToken = userTokens[0] - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) } diff --git a/integration_tests/util.go b/integration_tests/util.go index 2fe3e7d..7e83a87 100644 --- a/integration_tests/util.go +++ b/integration_tests/util.go @@ -45,7 +45,7 @@ const ( ) func LndHubTestServiceInit(lndClientMock lnd.LightningClientWrapper) (svc *service.LndhubService, err error) { - dbUri := "postgresql://user:password@localhost/lndhub?sslmode=disable" + dbUri := "postgresql://im-adithya:password@localhost:5432/lndhub?sslmode=disable" c := &service.Config{ DatabaseUri: dbUri, DatabaseMaxConns: 1, diff --git a/integration_tests/webhook_test.go b/integration_tests/webhook_test.go index b18dfed..b8d7e21 100644 --- a/integration_tests/webhook_test.go +++ b/integration_tests/webhook_test.go @@ -15,7 +15,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/tokens" - "github.com/getAlby/lndhub.go/lnd" "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" @@ -74,7 +73,7 @@ func (suite *WebHookTestSuite) SetupSuite() { suite.echo = e suite.userLogin = users[0] suite.userToken = userTokens[0] - suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{})) + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) } func (suite *WebHookTestSuite) TestWebHook() { diff --git a/lib/service/user.go b/lib/service/user.go index b0739ab..4165fd8 100644 --- a/lib/service/user.go +++ b/lib/service/user.go @@ -275,8 +275,14 @@ func (svc *LndhubService) GetVolumeOverPeriod(ctx context.Context, userId int64, return result, nil } -func (svc *LndhubService) GetLimitsFromContext(c echo.Context) (limits *lnd.Limits) { - limits = &lnd.Limits{} +func (svc *LndhubService) GetLimits(c echo.Context) (limits *lnd.Limits) { + limits = &lnd.Limits{ + MaxSendVolume: svc.Config.MaxSendVolume, + MaxSendAmount: svc.Config.MaxSendAmount, + MaxReceiveVolume: svc.Config.MaxReceiveVolume, + MaxReceiveAmount: svc.Config.MaxReceiveAmount, + MaxAccountBalance: svc.Config.MaxAccountBalance, + } if val, ok := c.Get("MaxSendVolume").(int64); ok { limits.MaxSendVolume = val } diff --git a/lib/tokens/jwt.go b/lib/tokens/jwt.go index 144d1f3..20709f3 100644 --- a/lib/tokens/jwt.go +++ b/lib/tokens/jwt.go @@ -7,7 +7,6 @@ import ( "time" "github.com/getAlby/lndhub.go/db/models" - "github.com/getAlby/lndhub.go/lnd" "github.com/getsentry/sentry-go" sentryecho "github.com/getsentry/sentry-go/echo" "github.com/golang-jwt/jwt" @@ -26,7 +25,7 @@ type jwtCustomClaims struct { jwt.StandardClaims } -func Middleware(secret []byte, limits *lnd.Limits) echo.MiddlewareFunc { +func Middleware(secret []byte) echo.MiddlewareFunc { config := middleware.DefaultJWTConfig config.Claims = &jwtCustomClaims{} @@ -44,31 +43,11 @@ func Middleware(secret []byte, limits *lnd.Limits) echo.MiddlewareFunc { token := c.Get("UserJwt").(*jwt.Token) claims := token.Claims.(*jwtCustomClaims) c.Set("UserID", claims.ID) - if limits.MaxSendVolume == 0 { - c.Set("MaxSendVolume", claims.MaxSendAmount) - } else { - c.Set("MaxSendVolume", limits.MaxSendVolume) - } - if limits.MaxSendAmount == 0 { - c.Set("MaxSendAmount", claims.MaxSendAmount) - } else { - c.Set("MaxSendAmount", limits.MaxSendAmount) - } - if limits.MaxReceiveVolume == 0 { - c.Set("MaxReceiveVolume", claims.MaxReceiveVolume) - } else { - c.Set("MaxReceiveVolume", limits.MaxReceiveVolume) - } - if limits.MaxReceiveAmount == 0 { - c.Set("MaxReceiveAmount", claims.MaxReceiveAmount) - } else { - c.Set("MaxReceiveAmount", limits.MaxReceiveAmount) - } - if limits.MaxAccountBalance == 0 { - c.Set("MaxAccountBalance", claims.MaxAccountBalance) - } else { - c.Set("MaxAccountBalance", limits.MaxAccountBalance) - } + c.Set("MaxSendVolume", claims.MaxSendVolume) + c.Set("MaxSendAmount", claims.MaxSendAmount) + c.Set("MaxReceiveVolume", claims.MaxReceiveVolume) + c.Set("MaxReceiveAmount", claims.MaxReceiveAmount) + c.Set("MaxAccountBalance", claims.MaxAccountBalance) // pass UserID to sentry for exception notifications if hub := sentryecho.GetHubFromContext(c); hub != nil { hub.Scope().SetUser(sentry.User{ID: strconv.FormatInt(claims.ID, 10)})