Skip to content

Commit

Permalink
chore: allow 0 limits for send/receive amount/volume
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Apr 3, 2024
1 parent 5abcb53 commit fcccdac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lib/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ type Config struct {
NoServiceFeeUpToAmount int `envconfig:"NO_SERVICE_FEE_UP_TO_AMOUNT" default:"0"`
AllowAccountCreation bool `envconfig:"ALLOW_ACCOUNT_CREATION" default:"true"`
MinPasswordEntropy int `envconfig:"MIN_PASSWORD_ENTROPY" default:"0"`
MaxReceiveAmount int64 `envconfig:"MAX_RECEIVE_AMOUNT" default:"0"`
MaxSendAmount int64 `envconfig:"MAX_SEND_AMOUNT" 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"`
MaxFeeAmount int64 `envconfig:"MAX_FEE_AMOUNT" default:"5000"`
MaxSendVolume int64 `envconfig:"MAX_SEND_VOLUME" default:"0"` //0 means the volume check is disabled by default
MaxReceiveVolume int64 `envconfig:"MAX_RECEIVE_VOLUME" default:"0"` //0 means the volume check is disabled by default
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
MaxVolumePeriod int64 `envconfig:"MAX_VOLUME_PERIOD" default:"2592000"` //in seconds, default 1 month
RabbitMQUri string `envconfig:"RABBITMQ_URI"`
RabbitMQLndhubInvoiceExchange string `envconfig:"RABBITMQ_INVOICE_EXCHANGE" default:"lndhub_invoice"`
Expand Down
18 changes: 9 additions & 9 deletions lib/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (svc *LndhubService) UpdateUser(ctx context.Context, userId int64, login *s
// if a user gets deleted we mark it as deactivated and deleted
// un-deleting it is not supported currently
if deleted != nil {
if *deleted == true {
if *deleted {
user.Deactivated = true
user.Deleted = true
}
Expand Down Expand Up @@ -136,14 +136,14 @@ func (svc *LndhubService) FindUserByLogin(ctx context.Context, login string) (*m

func (svc *LndhubService) CheckOutgoingPaymentAllowed(c echo.Context, lnpayReq *lnd.LNPayReq, userId int64) (result *responses.ErrorResponse, err error) {
limits := svc.GetLimits(c)
if limits.MaxSendAmount > 0 {
if limits.MaxSendAmount >= 0 {
if lnpayReq.PayReq.NumSatoshis > limits.MaxSendAmount {
svc.Logger.Errorf("Max send amount exceeded for user_id %v (amount:%v)", userId, lnpayReq.PayReq.NumSatoshis)
return &responses.SendExceededError, nil
}
}

if limits.MaxSendVolume > 0 {
if limits.MaxSendVolume >= 0 {
volume, err := svc.GetVolumeOverPeriod(c.Request().Context(), userId, common.InvoiceTypeOutgoing, time.Duration(svc.Config.MaxVolumePeriod*int64(time.Second)))
if err != nil {
svc.Logger.Errorj(
Expand Down Expand Up @@ -195,14 +195,14 @@ func (svc *LndhubService) CheckOutgoingPaymentAllowed(c echo.Context, lnpayReq *

func (svc *LndhubService) CheckIncomingPaymentAllowed(c echo.Context, amount, userId int64) (result *responses.ErrorResponse, err error) {
limits := svc.GetLimits(c)
if limits.MaxReceiveAmount > 0 {
if limits.MaxReceiveAmount >= 0 {
if amount > limits.MaxReceiveAmount {
svc.Logger.Errorf("Max receive amount exceeded for user_id %d", userId)
return &responses.ReceiveExceededError, nil
}
}

if limits.MaxReceiveVolume > 0 {
if limits.MaxReceiveVolume >= 0 {
volume, err := svc.GetVolumeOverPeriod(c.Request().Context(), userId, common.InvoiceTypeIncoming, time.Duration(svc.Config.MaxVolumePeriod*int64(time.Second)))
if err != nil {
svc.Logger.Errorj(
Expand Down Expand Up @@ -326,16 +326,16 @@ func (svc *LndhubService) GetLimits(c echo.Context) (limits *Limits) {
MaxReceiveAmount: svc.Config.MaxReceiveAmount,
MaxAccountBalance: svc.Config.MaxAccountBalance,
}
if val, ok := c.Get("MaxSendVolume").(int64); ok && val > 0 {
if val, ok := c.Get("MaxSendVolume").(int64); ok && val >= -1 {
limits.MaxSendVolume = val
}
if val, ok := c.Get("MaxSendAmount").(int64); ok && val > 0 {
if val, ok := c.Get("MaxSendAmount").(int64); ok && val >= -1 {
limits.MaxSendAmount = val
}
if val, ok := c.Get("MaxReceiveVolume").(int64); ok && val > 0 {
if val, ok := c.Get("MaxReceiveVolume").(int64); ok && val >= -1 {
limits.MaxReceiveVolume = val
}
if val, ok := c.Get("MaxReceiveAmount").(int64); ok && val > 0 {
if val, ok := c.Get("MaxReceiveAmount").(int64); ok && val >= -1 {
limits.MaxReceiveAmount = val
}
if val, ok := c.Get("MaxAccountBalance").(int64); ok && val > 0 {
Expand Down

0 comments on commit fcccdac

Please sign in to comment.