mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-19 13:44:53 +01:00
chore: refactor
This commit is contained in:
@@ -154,16 +154,8 @@ func main() {
|
||||
// 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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
2
go.mod
2
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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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("MaxSendVolume", claims.MaxSendVolume)
|
||||
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)
|
||||
}
|
||||
// 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)})
|
||||
|
||||
Reference in New Issue
Block a user