Skip to content

Commit

Permalink
chore: also default max account balance to -1
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Apr 3, 2024
1 parent e1687f2 commit 6f0de7d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion integration_tests/internal_payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (suite *PaymentTestSuite) TestIncomingExceededChecks() {
assert.Equal(suite.T(), responses.BalanceExceededError.Message, resp.Message)

//change the config back and add sats, it should work now
suite.service.Config.MaxAccountBalance = 0
suite.service.Config.MaxAccountBalance = -1
invoiceResponse = suite.createAddInvoiceReq(aliceFundingSats, "integration test internal payment alice", suite.aliceToken)
err = suite.mlnd.mockPaidInvoice(invoiceResponse, 0, false, nil)
assert.NoError(suite.T(), err)
Expand Down
6 changes: 5 additions & 1 deletion integration_tests/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ const (
func LndHubTestServiceInit(lndClientMock lnd.LightningClientWrapper) (svc *service.LndhubService, err error) {
dbUri, ok := os.LookupEnv("DATABASE_URI")
if !ok {
dbUri = "postgresql://user:password@localhost/lndhub?sslmode=disable"
dbUri = "postgresql://im-adithya:password@localhost:5432/lndhub?sslmode=disable"
}
dc := &service.Config{}
fmt.Println("dc.MaxSendAmount")
fmt.Println(dc.MaxSendAmount)
c := &service.Config{
DatabaseUri: dbUri,
DatabaseMaxConns: 1,
Expand All @@ -64,6 +67,7 @@ func LndHubTestServiceInit(lndClientMock lnd.LightningClientWrapper) (svc *servi
MaxSendVolume: -1,
MaxReceiveAmount: -1,
MaxReceiveVolume: -1,
MaxAccountBalance: -1,
}

rabbitmqUri, ok := os.LookupEnv("RABBITMQ_URI")
Expand Down
2 changes: 1 addition & 1 deletion lib/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Config struct {
MinPasswordEntropy int `envconfig:"MIN_PASSWORD_ENTROPY" default:"0"`
MaxReceiveAmount int64 `envconfig:"MAX_RECEIVE_AMOUNT" default:"-1"`
MaxSendAmount int64 `envconfig:"MAX_SEND_AMOUNT" default:"-1"`
MaxAccountBalance int64 `envconfig:"MAX_ACCOUNT_BALANCE" default:"0"`
MaxAccountBalance int64 `envconfig:"MAX_ACCOUNT_BALANCE" default:"-1"`
MaxFeeAmount int64 `envconfig:"MAX_FEE_AMOUNT" default:"5000"`
MaxSendVolume int64 `envconfig:"MAX_SEND_VOLUME" default:"-1"` //-1 means the volume check is disabled by default
MaxReceiveVolume int64 `envconfig:"MAX_RECEIVE_VOLUME" default:"-1"` //-1 means the volume check is disabled by default
Expand Down
6 changes: 3 additions & 3 deletions lib/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (svc *LndhubService) CheckIncomingPaymentAllowed(c echo.Context, amount, us
}
}

if limits.MaxAccountBalance > 0 {
if limits.MaxAccountBalance >= 0 {
currentBalance, err := svc.CurrentUserBalance(c.Request().Context(), userId)
if err != nil {
svc.Logger.Errorj(
Expand Down Expand Up @@ -338,8 +338,8 @@ func (svc *LndhubService) GetLimits(c echo.Context) (limits *Limits) {
if val, ok := c.Get("MaxReceiveAmount").(*int64); ok && val != nil {
limits.MaxReceiveAmount = *val
}
if val, ok := c.Get("MaxAccountBalance").(int64); ok && val > 0 {
limits.MaxAccountBalance = val
if val, ok := c.Get("MaxAccountBalance").(*int64); ok && val != nil {
limits.MaxAccountBalance = *val
}

return limits
Expand Down
2 changes: 1 addition & 1 deletion lib/tokens/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type jwtCustomClaims struct {
MaxSendAmount *int64 `json:"maxSendAmount,omitempty"`
MaxReceiveVolume *int64 `json:"maxReceiveVolume,omitempty"`
MaxReceiveAmount *int64 `json:"maxReceiveAmount,omitempty"`
MaxAccountBalance int64 `json:"maxAccountBalance"`
MaxAccountBalance *int64 `json:"maxAccountBalance,omitempty"`
jwt.StandardClaims
}

Expand Down

0 comments on commit 6f0de7d

Please sign in to comment.